From e3739acac9f4133a120aafdf134e9ab75bb7915d Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Sun, 17 Sep 2017 11:01:29 +0700 Subject: [PATCH] Use the UTXO set to get balance --- cli_getbalance.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli_getbalance.go b/cli_getbalance.go index c67c536..814569d 100644 --- a/cli_getbalance.go +++ b/cli_getbalance.go @@ -10,12 +10,13 @@ func (cli *CLI) getBalance(address string) { log.Panic("ERROR: Address is not valid") } bc := NewBlockchain() + UTXOSet := UTXOSet{bc} defer bc.db.Close() balance := 0 pubKeyHash := Base58Decode([]byte(address)) pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4] - UTXOs := bc.FindUTXO(pubKeyHash) + UTXOs := UTXOSet.FindUTXO(pubKeyHash) for _, out := range UTXOs { balance += out.Value