fn mock_transparent_transfer(
    previous_utxo_height: block::Height,
    script_should_succeed: bool,
    outpoint_index: u32,
) -> (
    transparent::Input,
    transparent::Output,
    HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
) {
    // A script with a single opcode that accepts the transaction (pushes true on the stack)
    let accepting_script = transparent::Script::new(&[1, 1]);
    // A script with a single opcode that rejects the transaction (OP_FALSE)
    let rejecting_script = transparent::Script::new(&[0]);

    // Mock an unspent transaction output
    let previous_outpoint = transparent::OutPoint {
        hash: Hash([1u8; 32]),
        index: outpoint_index,
    };

    let lock_script = if script_should_succeed {
        accepting_script.clone()
    } else {
        rejecting_script.clone()
    };

    let previous_output = transparent::Output {
        value: Amount::try_from(1).expect("1 is an invalid amount"),
        lock_script,
    };

    let previous_utxo =
        transparent::OrderedUtxo::new(previous_output, previous_utxo_height, false, 1);

    // Use the `previous_outpoint` as input
    let input = transparent::Input::PrevOut {
        outpoint: previous_outpoint,
        unlock_script: accepting_script,
        sequence: 0,
    };

    // The output resulting from the transfer
    // Using the rejecting script pretends the amount is burned because it can't be spent again
    let output = transparent::Output {
        value: Amount::try_from(1).expect("1 is an invalid amount"),
        lock_script: rejecting_script,
    };

    // Cache the source of the fund so that it can be used during verification
    let mut known_utxos = HashMap::new();
    known_utxos.insert(previous_outpoint, previous_utxo);

    (input, output, known_utxos)
}
/// Create a mock transparent transfer to be included in a transaction.
///
/// First, this creates a fake unspent transaction output from a fake transaction included in the
/// specified `previous_utxo_height` block height. This fake [`Utxo`] also contains a simple script
/// that can either accept or reject any spend attempt, depending on if `script_should_succeed` is
/// `true` or `false`. Since the `tx_index_in_block` is irrelevant for blocks that have already
/// been verified, it is set to `1`.
///
/// Then, a [`transparent::Input::PrevOut`] is created that attempts to spend the previously created fake
/// UTXO to a new [`transparent::Output`].
///
/// Finally, the initial fake UTXO is placed in a `known_utxos` [`HashMap`] so that it can be
/// retrieved during verification.
///
/// The function then returns the generated transparent input and output, as well as the
/// `known_utxos` map.
///
/// Note: `known_utxos` is only intended to be used for UTXOs within the same block,
/// so future verification changes might break this mocking function.
Create a mock transparent transfer to be included in a transaction.
First, this creates a fake unspent transaction output from a fake transaction included in the
specified `previous_utxo_height` block height.



Finally, the initial fake UTXO is placed in a `known_utxos` [`HashMap`] so that it can be
retrieved during verification.

The function then returns the generated transparent input and output, as well as the
`known_utxos` map.

`known_utxos` is only intended to be used for UTXOs within the same block,
so future verification changes might break this mocking function.
Create a mock transparent transfer to be included in a transaction . First this creates a fake unspent transaction output from a fake transaction included in the specified ` previous_utxo_height ` block height . Finally the initial fake UTXO is placed in a ` known_utxos ` [ ` HashMap ` ] so that it can be retrieved during verification . The function then returns the generated transparent input and output as well as the ` known_utxos ` map . ` known_utxos ` is only intended to be used for UTXOs within the same block so future verification changes might break this mocking function .
fn mock_transparent_transfer(
    previous_utxo_height: block::Height,
    script_should_succeed: bool,
    outpoint_index: u32,
) -> (
    transparent::Input,
    transparent::Output,
    HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
) {
    // A script with a single opcode that accepts the transaction (pushes true on the stack)
    let accepting_script = transparent::Script::new(&[1, 1]);
    // A script with a single opcode that rejects the transaction (OP_FALSE)
    let rejecting_script = transparent::Script::new(&[0]);
    // Mock an unspent transaction output
    let previous_outpoint = transparent::OutPoint {
        hash: Hash([1u8; 32]),
        index: outpoint_index,
    };
    let lock_script = if script_should_succeed {
        accepting_script.clone()
    } else {
        rejecting_script.clone()
    };
    let previous_output = transparent::Output {
        value: Amount::try_from(1).expect("1 is an invalid amount"),
        lock_script,
    };
    let previous_utxo =
        transparent::OrderedUtxo::new(previous_output, previous_utxo_height, false, 1);
    // Use the `previous_outpoint` as input
    let input = transparent::Input::PrevOut {
        outpoint: previous_outpoint,
        unlock_script: accepting_script,
        sequence: 0,
    };
    // The output resulting from the transfer
    // Using the rejecting script pretends the amount is burned because it can't be spent again
    let output = transparent::Output {
        value: Amount::try_from(1).expect("1 is an invalid amount"),
        lock_script: rejecting_script,
    };
    // Cache the source of the fund so that it can be used during verification
    let mut known_utxos = HashMap::new();
    known_utxos.insert(previous_outpoint, previous_utxo);
    (input, output, known_utxos)
}
fn mock_transparent_transfer ( previous_utxo_height : block :: Height , script_should_succeed : bool , outpoint_index : u32 , ) -> ( transparent :: Input , transparent :: Output , HashMap < transparent :: OutPoint , transparent :: OrderedUtxo > , ) { // A script with a single opcode that accepts the transaction (pushes true on the stack) let accepting_script = transparent :: Script :: new ( & [ 1 , 1 ] ) ; // A script with a single opcode that rejects the transaction (OP_FALSE) let rejecting_script = transparent :: Script :: new ( & [ 0 ] ) ; // Mock an unspent transaction output let previous_outpoint = transparent :: OutPoint { hash : Hash ( [ 1u8 ; 32 ] ) , index : outpoint_index , } ; let lock_script = if script_should_succeed { accepting_script . clone ( ) } else { rejecting_script . clone ( ) } ; let previous_output = transparent :: Output { value : Amount :: try_from ( 1 ) . expect ( " " ) , lock_script , } ; let previous_utxo = transparent :: OrderedUtxo :: new ( previous_output , previous_utxo_height , false , 1 ) ; // Use the `previous_outpoint` as input let input = transparent :: Input :: PrevOut { outpoint : previous_outpoint , unlock_script : accepting_script , sequence : 0 , } ; // The output resulting from the transfer // Using the rejecting script pretends the amount is burned because it can't be spent again let output = transparent :: Output { value : Amount :: try_from ( 1 ) . expect ( " " ) , lock_script : rejecting_script , } ; // Cache the source of the fund so that it can be used during verification let mut known_utxos = HashMap :: new ( ) ; known_utxos . insert ( previous_outpoint , previous_utxo ) ; ( input , output , known_utxos ) }
Create a mock transparent transfer to be included in a transaction.
Create a mock transparent transfer to be included in a transaction .
previous_utxo_height
block::Height
script_should_succeed
bool
outpoint_index
u32