27 lines
492 B
Go
27 lines
492 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
func (cli *CLI) getBalance(address string) {
|
|
if !ValidateAddress(address) {
|
|
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 := UTXOSet.FindUTXO(pubKeyHash)
|
|
|
|
for _, out := range UTXOs {
|
|
balance += out.Value
|
|
}
|
|
|
|
fmt.Printf("Balance of '%s': %d\n", address, balance)
|
|
}
|