pub fn transparent_spend(
    prepared: &PreparedBlock,
    non_finalized_chain_unspent_utxos: &HashMap<transparent::OutPoint, transparent::Utxo>,
    non_finalized_chain_spent_utxos: &HashSet<transparent::OutPoint>,
    finalized_state: &FinalizedState,
) -> Result<HashMap<transparent::OutPoint, transparent::Utxo>, ValidateContextError> {
    let mut block_spends = HashMap::new();

    for (spend_tx_index_in_block, transaction) in prepared.block.transactions.iter().enumerate() {
        let spends = transaction.inputs().iter().filter_map(|input| match input {
            transparent::Input::PrevOut { outpoint, .. } => Some(outpoint),
            // Coinbase inputs represent new coins,
            // so there are no UTXOs to mark as spent.
            transparent::Input::Coinbase { .. } => None,
        });

        for spend in spends {
            let utxo = transparent_spend_chain_order(
                *spend,
                spend_tx_index_in_block,
                &prepared.new_outputs,
                non_finalized_chain_unspent_utxos,
                non_finalized_chain_spent_utxos,
                finalized_state,
            )?;

            // The state service returns UTXOs from pending blocks,
            // which can be rejected by later contextual checks.
            // This is a particular issue for v5 transactions,
            // because their authorizing data is only bound to the block data
            // during contextual validation (#2336).
            //
            // We don't want to use UTXOs from invalid pending blocks,
            // so we check transparent coinbase maturity and shielding
            // using known valid UTXOs during non-finalized chain validation.
            let spend_restriction = transaction.coinbase_spend_restriction(prepared.height);
            let utxo = transparent_coinbase_spend(*spend, spend_restriction, utxo)?;

            // We don't delete the UTXOs until the block is committed,
            // so we  need to check for duplicate spends within the same block.
            //
            // See `transparent_spend_chain_order` for the relevant consensus rule.
            if block_spends.insert(*spend, utxo).is_some() {
                return Err(DuplicateTransparentSpend {
                    outpoint: *spend,
                    location: "the same block",
                });
            }
        }
    }

    remaining_transaction_value(prepared, &block_spends)?;

    Ok(block_spends)
}
/// Lookup all the [`transparent::Utxo`]s spent by a [`PreparedBlock`].
/// If any of the spends are invalid, return an error.
/// Otherwise, return the looked up UTXOs.
///
/// Checks for the following kinds of invalid spends:
///
/// Double-spends:
/// - duplicate spends that are both in this block,
/// - spends of an output that was spent by a previous block,
///
/// Missing spends:
/// - spends of an output that hasn't been created yet,
///   (in linear chain and transaction order),
/// - spends of UTXOs that were never created in this chain,
///
/// Invalid spends:
/// - spends of an immature transparent coinbase output,
/// - unshielded spends of a transparent coinbase output.
Lookup all the [`transparent::Utxo`]s spent by a [`PreparedBlock`].
If any of the spends are invalid, return an error.
Otherwise, return the looked up UTXOs.

Checks for the following kinds of invalid spends.

Double-spends:
duplicate spends that are both in this block,
spends of an output that was spent by a previous block.

Missing spends:
spends of an output that hasn't been created yet,
(in linear chain and transaction order),
spends of UTXOs that were never created in this chain.

Invalid spends:
spends of an immature transparent coinbase output,
unshielded spends of a transparent coinbase output.
Lookup all the [ ` transparent :: Utxo ` ] s spent by a [ ` PreparedBlock ` ] . If any of the spends are invalid return an error . Otherwise return the looked up UTXOs . Checks for the following kinds of invalid spends . Double - spends : duplicate spends that are both in this block spends of an output that was spent by a previous block . Missing spends : spends of an output that hasn ' t been created yet ( in linear chain and transaction order ) spends of UTXOs that were never created in this chain . Invalid spends : spends of an immature transparent coinbase output unshielded spends of a transparent coinbase output .
pub fn transparent_spend(
    prepared: &PreparedBlock,
    non_finalized_chain_unspent_utxos: &HashMap<transparent::OutPoint, transparent::Utxo>,
    non_finalized_chain_spent_utxos: &HashSet<transparent::OutPoint>,
    finalized_state: &FinalizedState,
) -> Result<HashMap<transparent::OutPoint, transparent::Utxo>, ValidateContextError> {
    let mut block_spends = HashMap::new();
    for (spend_tx_index_in_block, transaction) in prepared.block.transactions.iter().enumerate() {
        let spends = transaction.inputs().iter().filter_map(|input| match input {
            transparent::Input::PrevOut { outpoint, .. } => Some(outpoint),
            // Coinbase inputs represent new coins,
            // so there are no UTXOs to mark as spent.
            transparent::Input::Coinbase { .. } => None,
        });
        for spend in spends {
            let utxo = transparent_spend_chain_order(
                *spend,
                spend_tx_index_in_block,
                &prepared.new_outputs,
                non_finalized_chain_unspent_utxos,
                non_finalized_chain_spent_utxos,
                finalized_state,
            )?;
            // The state service returns UTXOs from pending blocks,
            // which can be rejected by later contextual checks.
            // This is a particular issue for v5 transactions,
            // because their authorizing data is only bound to the block data
            // during contextual validation (#2336).
            //
            // We don't want to use UTXOs from invalid pending blocks,
            // so we check transparent coinbase maturity and shielding
            // using known valid UTXOs during non-finalized chain validation.
            let spend_restriction = transaction.coinbase_spend_restriction(prepared.height);
            let utxo = transparent_coinbase_spend(*spend, spend_restriction, utxo)?;
            // We don't delete the UTXOs until the block is committed,
            // so we  need to check for duplicate spends within the same block.
            //
            // See `transparent_spend_chain_order` for the relevant consensus rule.
            if block_spends.insert(*spend, utxo).is_some() {
                return Err(DuplicateTransparentSpend {
                    outpoint: *spend,
                    location: "the same block",
                });
            }
        }
    }
    remaining_transaction_value(prepared, &block_spends)?;
    Ok(block_spends)
}
pub fn transparent_spend ( prepared : & PreparedBlock , non_finalized_chain_unspent_utxos : & HashMap < transparent :: OutPoint , transparent :: Utxo > , non_finalized_chain_spent_utxos : & HashSet < transparent :: OutPoint > , finalized_state : & FinalizedState , ) -> Result < HashMap < transparent :: OutPoint , transparent :: Utxo > , ValidateContextError > { let mut block_spends = HashMap :: new ( ) ; for ( spend_tx_index_in_block , transaction ) in prepared . block . transactions . iter ( ) . enumerate ( ) { let spends = transaction . inputs ( ) . iter ( ) . filter_map ( | input | match input { transparent :: Input :: PrevOut { outpoint , .. } => Some ( outpoint ) , // Coinbase inputs represent new coins, // so there are no UTXOs to mark as spent. transparent :: Input :: Coinbase { .. } => None , } ) ; for spend in spends { let utxo = transparent_spend_chain_order ( * spend , spend_tx_index_in_block , & prepared . new_outputs , non_finalized_chain_unspent_utxos , non_finalized_chain_spent_utxos , finalized_state , ) ? ; // The state service returns UTXOs from pending blocks, // which can be rejected by later contextual checks. // This is a particular issue for v5 transactions, // because their authorizing data is only bound to the block data // during contextual validation (#2336). // // We don't want to use UTXOs from invalid pending blocks, // so we check transparent coinbase maturity and shielding // using known valid UTXOs during non-finalized chain validation. let spend_restriction = transaction . coinbase_spend_restriction ( prepared . height ) ; let utxo = transparent_coinbase_spend ( * spend , spend_restriction , utxo ) ? ; // We don't delete the UTXOs until the block is committed, // so we  need to check for duplicate spends within the same block. // // See `transparent_spend_chain_order` for the relevant consensus rule. if block_spends . insert ( * spend , utxo ) . is_some ( ) { return Err ( DuplicateTransparentSpend { outpoint : * spend , location : " " , } ) ; } } } remaining_transaction_value ( prepared , & block_spends ) ? ; Ok ( block_spends ) }
Lookup all the [`transparent::Utxo`]s spent by a [`PreparedBlock`].
Lookup all the [ ` transparent :: Utxo ` ] s spent by a [ ` PreparedBlock ` ] .
prepared
&PreparedBlock
non_finalized_chain_unspent_utxos
&HashMap<transparent::OutPoint, transparent::Utxo>
non_finalized_chain_spent_utxos
&HashSet<transparent::OutPoint>
finalized_state
&FinalizedState