add GetBalance to chain
This commit is contained in:
parent
9b2f73b11b
commit
56c9e3faa6
|
@ -376,3 +376,16 @@ func (bc *Blockchain) PrintHTML() string {
|
|||
return strings.Join(lines, "\n")
|
||||
|
||||
}
|
||||
|
||||
func (bc *Blockchain) GetBalance(address string) int {
|
||||
UTXOSet := UTXOSet{bc}
|
||||
balance := 0
|
||||
pubKeyHash := Base58Decode([]byte(address))
|
||||
pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
|
||||
UTXOs := UTXOSet.FindUTXO(pubKeyHash)
|
||||
|
||||
for _, out := range UTXOs {
|
||||
balance += out.Value
|
||||
}
|
||||
return balance
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue