January 2019
Beginner to intermediate
372 pages
11h 17m
English
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, ...