2017-09-10 00:53:06 -05:00
|
|
|
package main
|
|
|
|
|
2017-09-10 01:53:14 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
)
|
2017-09-10 00:53:06 -05:00
|
|
|
|
|
|
|
func (cli *CLI) getBalance(address string) {
|
2017-09-10 01:53:14 -05:00
|
|
|
if !ValidateAddress(address) {
|
|
|
|
log.Panic("ERROR: Address is not valid")
|
|
|
|
}
|
2017-09-16 22:43:23 -05:00
|
|
|
bc := NewBlockchain()
|
2017-09-16 23:01:29 -05:00
|
|
|
UTXOSet := UTXOSet{bc}
|
2017-09-10 00:53:06 -05:00
|
|
|
defer bc.db.Close()
|
|
|
|
|
|
|
|
balance := 0
|
|
|
|
pubKeyHash := Base58Decode([]byte(address))
|
|
|
|
pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
|
2017-09-16 23:01:29 -05:00
|
|
|
UTXOs := UTXOSet.FindUTXO(pubKeyHash)
|
2017-09-10 00:53:06 -05:00
|
|
|
|
|
|
|
for _, out := range UTXOs {
|
|
|
|
balance += out.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Balance of '%s': %d\n", address, balance)
|
|
|
|
}
|