balance

open override fun balance(): Map<GroupId, Balance>

Gets the contract-encumbered balance of this contract, calculated by iterating through contract UTXOs. The returned map always has at least one entry: nativeGroupId(Chainselector) tracking the native coin (i.e. Nexa), even if the balance is 0.

Contract-encumbered means that this contract is "claiming" the UTXO, typically for isolation reasons or because the contract required additional signing steps. If a UTXO adheres to this contract, but can be immediately spent without any additional interaction, the contract may place the UTXO in the general pool (and it won't show up here).

The concept of "balance" is actually hard in UTXO based chains, when confirmed/unconfirmed transactions are considered. Unconfirmed transactions that are created by this wallet should be considered confirmed because we trust our own operations. Similarly, If a transaction spends X with Y change, we should not see Y incoming coins. It is change so never left the wallet. This function attempts to return the balance as humans would like it imagine it (with the above caveats).

Return

This function conceptually returns: groupId -> (current balance, confirmed balance, unconfirmed balance). But it actually included unconfirmed "domestic" (created by this wallet) operations into the "confirmed" slot, since the expectation is that the wallet owner will not try to trick themselves. So a pedantically accurate description of its return is (Total balance, Confirmed domestic balance, Foreign unconfirmed balance)