UtxoManager
Manages UTXO state from transaction updates.
Handles:
Processing transaction updates (created/spent UTXOs)
Three-state UTXO lifecycle (AVAILABLE → PENDING → SPENT)
Transaction failure handling (unlock UTXOs)
Calculating balances from available UTXOs only
Transaction Status Handling:
SUCCESS/PARTIAL_SUCCESS: Create UTXOs (AVAILABLE), mark spent as SPENT
FAILURE: Don't create UTXOs, unlock spent UTXOs (PENDING → AVAILABLE)
Thread-safe: All operations are suspend functions using Room's built-in thread safety.
Functions
Calculate balance for an address.
Delete all UTXOs for an address.
Debug: Dump all UTXOs for an address to logs.
Get detailed UTXO list for an address.
Check if database has ANY UTXOs for this address (any state).
Check if database has AVAILABLE UTXOs for this address.
Mark UTXOs as spent by their database IDs.
Observe balance changes for an address (available UTXOs only).
Observe pending balance for an address (locked in pending transactions).
Observe UTXO counts per token type (available UTXOs only).
Process transaction update from subscription.
Reset ALL SPENT UTXOs to AVAILABLE for self-healing.
Select and lock UTXOs for transaction (atomic operation).
Select and lock UTXOs for multiple token types (atomic operation).
Unlock UTXOs (mark as AVAILABLE).