Skip to main content

apply_transaction

Function apply_transaction 

Source
pub fn apply_transaction(
    tx: &Transaction,
    utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
    height: u64,
) -> Result<(HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, Vec<UndoEntry>), ConsensusError>
Expand description

ApplyTransaction (Orange Paper 5.3.2)

For transaction tx and UTXO set us:

  1. If tx is coinbase: us’ = us ∪ {(tx.id, i) ↦ tx.outputs[i] : i ∈ [0, |tx.outputs|)}
  2. Otherwise: us’ = (us \ {i.prevout : i ∈ tx.inputs}) ∪ {(tx.id, i) ↦ tx.outputs[i] : i ∈ [0, |tx.outputs|)}
  3. Return us’

This function computes the transaction ID internally. For batch operations, use apply_transaction_with_id instead.

Returns both the new UTXO set and undo entries for all UTXO changes.