Skip to content

Commit

Permalink
Handle negative/positive subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Dec 24, 2020
1 parent b34772a commit a3c754d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func CreateTxWithChange(utxos []*Utxo, payToAddresses []*PayToAddress, opReturns
// Accumulate the total satoshis from all utxo(s)
var totalSatoshis uint64
var totalPayToSatoshis uint64
var remainder uint64
var hasChange bool

// Loop utxos and get total usable satoshis
Expand Down Expand Up @@ -109,7 +110,12 @@ func CreateTxWithChange(utxos []*Utxo, payToAddresses []*PayToAddress, opReturns
}

// Get the remainder missing
remainder := (totalPayToSatoshis + fee) - totalSatoshis
totalToPay := totalPayToSatoshis + fee
if totalToPay >= totalSatoshis {
remainder = totalToPay - totalSatoshis
} else {
remainder = totalSatoshis - totalToPay
}

// Remove remainder from last used payToAddress (or continue until found)
feeAdjusted := false
Expand Down

0 comments on commit a3c754d

Please sign in to comment.