From 1261b61fffa1e75b56968a268009413e07e02e1e Mon Sep 17 00:00:00 2001 From: mingrammer Date: Sat, 26 May 2018 00:31:06 +0900 Subject: [PATCH] Early exits while finding spendable outputs --- utxo_set.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utxo_set.go b/utxo_set.go index 180ce04..a73cb5a 100644 --- a/utxo_set.go +++ b/utxo_set.go @@ -28,6 +28,10 @@ func (u UTXOSet) FindSpendableOutputs(pubkeyHash []byte, amount int) (int, map[s txID := hex.EncodeToString(k) outs := DeserializeOutputs(v) + if accumulated >= amount { + break + } + for outIdx, out := range outs.Outputs { if out.IsLockedWithKey(pubkeyHash) && accumulated < amount { accumulated += out.Value