Skip to content

Commit

Permalink
add GetBalance to chain
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWeiYang committed Oct 22, 2017
1 parent 9b2f73b commit 56c9e3f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 56c9e3f

Please sign in to comment.