pub fn spent_outputs_for_block<C>(
chain: Option<C>,
db: &ZebraDb,
hash_or_height: HashOrHeight,
) -> Option<HashMap<OutPoint, Utxo>>Expand description
Returns the transparent outputs spent by the non-coinbase inputs of the block with
hash_or_height, keyed by the OutPoint that spends them, if the
block exists in the non-finalized chain or finalized db.
Used by the getblock RPC at verbosity 3 to fill in each input’s prevout and the
transaction fee.
§Correctness
The block and all of its spent outputs are read from the same chain/db snapshot, so the
prevouts are consistent with the block.
A spent output that cannot be found (for example, an input of a side-chain block that spends an output not in the best chain) is omitted from the map. Callers must treat a missing outpoint as “prevout unknown”, not as an error.
Coinbase transactions spend no outputs, so they contribute nothing to the map.
§Performance
Spent outputs are deleted from the finalized UTXO set, so an output already spent in the
finalized chain is recovered by reading its whole parent transaction. Each distinct parent
transaction is read at most once, so this is O(distinct spent parent transactions) reads —
the same cost as resolving the prevouts individually, but in a single state request under one
snapshot.
UTXO lookups only help for a non-finalized block: its spent outputs are still in the non-finalized chain’s created UTXOs or the finalized UTXO set. A finalized block skips them and reads the parent transactions directly.