Skip to content

Commit

Permalink
Added more error catching
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Masley committed Jun 21, 2017
1 parent 23c7ce3 commit a60bcc1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wallet/transactions.go
Expand Up @@ -456,12 +456,18 @@ func (wal *WalletDB) ConstructTransaction(toAddresses []string, amounts []uint64
return trans, nil, fmt.Errorf("Not enough factoids to cover the transaction")
}
if list[i].Balance > totalLeft {
wal.Wallet.AddInput(trans, list[i].Address, totalLeft)
err := wal.Wallet.AddInput(trans, list[i].Address, totalLeft)
if err != nil {
return trans, nil, err
}
list[i].Balance -= totalLeft
totalLeft = 0
} else {
if list[i].Balance > 0 {
wal.Wallet.AddInput(trans, list[i].Address, list[i].Balance)
err := wal.Wallet.AddInput(trans, list[i].Address, list[i].Balance)
if err != nil {
return trans, nil, err
}
totalLeft -= list[i].Balance
list[i].Balance = 0
}
Expand All @@ -485,7 +491,10 @@ func (wal *WalletDB) ConstructTransaction(toAddresses []string, amounts []uint64
if i == -1 || err != nil { // We don't have an address that can pay for the fee.
return trans, nil, fmt.Errorf("Not enough factoids to cover the transaction")
} else {
wal.Wallet.AddInput(trans, list[i].Address, 0)
err := wal.Wallet.AddInput(trans, list[i].Address, 0)
if err != nil {
return trans, nil, err
}
}
}

Expand Down

0 comments on commit a60bcc1

Please sign in to comment.