Skip to Content
Foundations of Blockchain
book

Foundations of Blockchain

by Koshik Raj
January 2019
Beginner to intermediate
372 pages
11h 17m
English
Packt Publishing
Content preview from Foundations of Blockchain

Wallet balance

Owning funds in cryptocurrency boils down to claiming the transaction outputs that are addressed to the user. The wallet's balance is calculated by collecting all the UTXOs whose addresses match the public key counterpart of the user's private key.

Since our application maintains a single private key per wallet, all the UTXOs of the user will be referenced to a single public address, which isn't the case in implementations where user-owned UTXOs will be addressed to multiple addresses. The following method finds the sum of all the funds amounts specified in the UTXOs whose addresses match the user's public key:

def get_balance(address, unspent_tx_outs): return sum(map(lambda utxo : utxo.amount, find_unspent_tx_outs(address, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Blockchain Basics

Blockchain Basics

Daniel Drescher
What Is Blockchain?

What Is Blockchain?

Sir John Hargrave, Evan Karnoupakis
Mastering Blockchain

Mastering Blockchain

Lorne Lantz, Daniel Cawrey

Publisher Resources

ISBN: 9781789139396Supplemental Content