You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The second judgment condition accumulated < amount is not necessary. It only works when amount <= 0, In this case, we should check the value of amount at the beginning of the function.
func (bc *Blockchain) FindSpendableOutputs(pubKeyHash []byte, amount int) (int, map[string][]int) {
unspentOutputs := make(map[string][]int)
accumulated := 0
// Maybe we should check “amount” at the beginning of the function.
if (amount <= 0){
return accumulated,unspentOutputs
}
unspentTXs := bc.FindUnspentTransactions(pubKeyHash)
Work:
for _, tx := range unspentTXs {
txID := hex.EncodeToString(tx.ID)
for outIdx, out := range tx.Vout {
if out.IsLockedWithKey(pubKeyHash) { // Delete “&& accumulated < amount”
accumulated += out.Value
unspentOutputs[txID] = append(unspentOutputs[txID], outIdx)
if accumulated >= amount {
break Work
}
}
}
}
return accumulated, unspentOutputs
}
The text was updated successfully, but these errors were encountered:
In branch part_5, blockchain.go#L109:
blockchain_go/blockchain.go
Line 109 in 201e7a1
The second judgment condition
accumulated < amount
is not necessary. It only works whenamount <= 0
, In this case, we should check the value ofamount
at the beginning of the function.The text was updated successfully, but these errors were encountered: