Use the UTXO set to get balance
This commit is contained in:
parent
c3aa678291
commit
e3739acac9
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue