Early exits while finding spendable outputs

This commit is contained in:
mingrammer 2018-05-26 00:31:06 +09:00
parent fee9bfd3af
commit 1261b61fff
1 changed files with 4 additions and 0 deletions

View File

@ -28,6 +28,10 @@ func (u UTXOSet) FindSpendableOutputs(pubkeyHash []byte, amount int) (int, map[s
txID := hex.EncodeToString(k) txID := hex.EncodeToString(k)
outs := DeserializeOutputs(v) outs := DeserializeOutputs(v)
if accumulated >= amount {
break
}
for outIdx, out := range outs.Outputs { for outIdx, out := range outs.Outputs {
if out.IsLockedWithKey(pubkeyHash) && accumulated < amount { if out.IsLockedWithKey(pubkeyHash) && accumulated < amount {
accumulated += out.Value accumulated += out.Value