Use the UTXO set to get balance

This commit is contained in:
Ivan Kuznetsov 2017-09-17 11:01:29 +07:00
parent c3aa678291
commit e3739acac9
1 changed files with 2 additions and 1 deletions

View File

@ -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