A balance is the value associated with a wallet after its ledger transactions are accounted for. Computing it means ignoring the genesis block, examining each transaction, and combining incoming and outgoing funds. section 4.7
Two implementations expose different design tradeoffs:
- An imperative algorithm loops through blocks and transactions, branches on sender identity, and repeatedly reassigns a running balance. section 4.7
- A functional implementation makes the address and ledger explicit, filters genesis blocks, flattens transactions, maps each transaction to a balance contribution, and reduces with immutable summation. section 4.7
Delegating from Wallet
A Wallet can keep its public API small while delegating calculation to a side-effect-free function: balance(ledger) returns computeBalance(this.address, ledger).
