pub fn create_transaction_with_amount<L: Ledger, R: RngCore + CryptoRng>(
    ledger: &mut L,
    tx_out: &TxOut,
    sender: &AccountKey,
    recipient: &PublicAddress,
    amount: u64,
    fee: u64,
    tombstone_block: BlockIndex,
    rng: &mut R,
) -> Tx {
    let mut transaction_builder = TransactionBuilder::new();

    // The first transaction in the origin block should contain enough outputs to use as mixins.
    let origin_tx = &ledger.get_transactions_by_block(0).unwrap()[0];
    let origin_outputs = &origin_tx.outputs;

    // Populate a ring with mixins.
    let mut ring: Vec<TxOut> = origin_outputs.iter().take(RING_SIZE).cloned().collect();
    if !ring.contains(tx_out) {
        ring[0] = tx_out.clone();
    }
    let real_index = ring.iter().position(|element| element == tx_out).unwrap();

    // Membership proofs for the full ring.
    let indexes = ring
        .iter()
        .map(|tx_out| ledger.get_tx_out_index_by_hash(&tx_out.hash()).unwrap())
        .collect::<Vec<u64>>();
    let membership_proofs = ledger.get_tx_out_proof_of_memberships(&indexes).unwrap();

    let spend_private_key = sender.subaddress_spend_key(DEFAULT_SUBADDRESS_INDEX);
    let tx_out_public_key = RistrettoPublic::try_from(&tx_out.public_key).unwrap();
    let onetime_private_key = recover_onetime_private_key(
        &tx_out_public_key,
        sender.view_private_key(),
        &spend_private_key,
    );

    let input_credentials = InputCredentials::new(
        ring,
        membership_proofs,
        real_index,
        onetime_private_key,
        *sender.view_private_key(),
        rng,
    )
    .unwrap();
    transaction_builder.add_input(input_credentials);

    // Output
    transaction_builder
        .add_output(amount, recipient, None, rng)
        .unwrap();

    // Tombstone block
    transaction_builder.set_tombstone_block(tombstone_block);

    // Fee
    transaction_builder.set_fee(fee);

    // Build and return the transaction
    transaction_builder.build(rng).unwrap()
}
/// Creates a transaction that sends an arbitrary amount to a single recipient.
///
/// # Arguments:
/// * `ledger` - A ledger containing `tx_out`.
/// * `tx_out` - The TxOut that will be spent.
/// * `sender` - The owner of `tx_out`.
/// * `recipient` - The recipient of the new transaction.
/// * `amount` - Amount to send.
/// * `tombstone_block` - The tombstone block for the new transaction.
/// * `rng` - The randomness used by this function
Creates a transaction that sends an arbitrary amount to a single recipient.
Creates a transaction that sends an arbitrary amount to a single recipient .
pub fn create_transaction_with_amount<L: Ledger, R: RngCore + CryptoRng>(
    ledger: &mut L,
    tx_out: &TxOut,
    sender: &AccountKey,
    recipient: &PublicAddress,
    amount: u64,
    fee: u64,
    tombstone_block: BlockIndex,
    rng: &mut R,
) -> Tx {
    let mut transaction_builder = TransactionBuilder::new();
    // The first transaction in the origin block should contain enough outputs to use as mixins.
    let origin_tx = &ledger.get_transactions_by_block(0).unwrap()[0];
    let origin_outputs = &origin_tx.outputs;
    // Populate a ring with mixins.
    let mut ring: Vec<TxOut> = origin_outputs.iter().take(RING_SIZE).cloned().collect();
    if !ring.contains(tx_out) {
        ring[0] = tx_out.clone();
    }
    let real_index = ring.iter().position(|element| element == tx_out).unwrap();
    // Membership proofs for the full ring.
    let indexes = ring
        .iter()
        .map(|tx_out| ledger.get_tx_out_index_by_hash(&tx_out.hash()).unwrap())
        .collect::<Vec<u64>>();
    let membership_proofs = ledger.get_tx_out_proof_of_memberships(&indexes).unwrap();
    let spend_private_key = sender.subaddress_spend_key(DEFAULT_SUBADDRESS_INDEX);
    let tx_out_public_key = RistrettoPublic::try_from(&tx_out.public_key).unwrap();
    let onetime_private_key = recover_onetime_private_key(
        &tx_out_public_key,
        sender.view_private_key(),
        &spend_private_key,
    );
    let input_credentials = InputCredentials::new(
        ring,
        membership_proofs,
        real_index,
        onetime_private_key,
        *sender.view_private_key(),
        rng,
    )
    .unwrap();
    transaction_builder.add_input(input_credentials);
    // Output
    transaction_builder
        .add_output(amount, recipient, None, rng)
        .unwrap();
    // Tombstone block
    transaction_builder.set_tombstone_block(tombstone_block);
    // Fee
    transaction_builder.set_fee(fee);
    // Build and return the transaction
    transaction_builder.build(rng).unwrap()
}
pub fn create_transaction_with_amount < L : Ledger , R : RngCore + CryptoRng > ( ledger : & mut L , tx_out : & TxOut , sender : & AccountKey , recipient : & PublicAddress , amount : u64 , fee : u64 , tombstone_block : BlockIndex , rng : & mut R , ) -> Tx { let mut transaction_builder = TransactionBuilder :: new ( ) ; // The first transaction in the origin block should contain enough outputs to use as mixins. let origin_tx = & ledger . get_transactions_by_block ( 0 ) . unwrap ( ) [ 0 ] ; let origin_outputs = & origin_tx . outputs ; // Populate a ring with mixins. let mut ring : Vec < TxOut > = origin_outputs . iter ( ) . take ( RING_SIZE ) . cloned ( ) . collect ( ) ; if ! ring . contains ( tx_out ) { ring [ 0 ] = tx_out . clone ( ) ; } let real_index = ring . iter ( ) . position ( | element | element == tx_out ) . unwrap ( ) ; // Membership proofs for the full ring. let indexes = ring . iter ( ) . map ( | tx_out | ledger . get_tx_out_index_by_hash ( & tx_out . hash ( ) ) . unwrap ( ) ) . collect :: < Vec < u64 > > ( ) ; let membership_proofs = ledger . get_tx_out_proof_of_memberships ( & indexes ) . unwrap ( ) ; let spend_private_key = sender . subaddress_spend_key ( DEFAULT_SUBADDRESS_INDEX ) ; let tx_out_public_key = RistrettoPublic :: try_from ( & tx_out . public_key ) . unwrap ( ) ; let onetime_private_key = recover_onetime_private_key ( & tx_out_public_key , sender . view_private_key ( ) , & spend_private_key , ) ; let input_credentials = InputCredentials :: new ( ring , membership_proofs , real_index , onetime_private_key , * sender . view_private_key ( ) , rng , ) . unwrap ( ) ; transaction_builder . add_input ( input_credentials ) ; // Output transaction_builder . add_output ( amount , recipient , None , rng ) . unwrap ( ) ; // Tombstone block transaction_builder . set_tombstone_block ( tombstone_block ) ; // Fee transaction_builder . set_fee ( fee ) ; // Build and return the transaction transaction_builder . build ( rng ) . unwrap ( ) }
Creates a transaction that sends an arbitrary amount to a single recipient.
Creates a transaction that sends an arbitrary amount to a single recipient .
ledger
&mut L
tx_out
&TxOut
sender
&AccountKey
recipient
&PublicAddress
amount
u64
fee
u64
tombstone_block
BlockIndex
rng
&mut R
ledger
&mut L
tx_out
&TxOut
sender
&AccountKey
recipient
&PublicAddress
amount
u64
fee
u64
tombstone_block
BlockIndex
rng
&mut R
arguments:
`ledger` - A ledger containing `tx_out`.
`tx_out` - The TxOut that will be spent.
`sender` - The owner of `tx_out`.
`recipient` - The recipient of the new transaction.
`amount` - Amount to send.
`tombstone_block` - The tombstone block for the new transaction.
`rng` - The randomness used by this function
` ledger ` - A ledger containing ` tx_out ` . ` tx_out ` - The TxOut that will be spent . ` sender ` - The owner of ` tx_out ` . ` recipient ` - The recipient of the new transaction . ` amount ` - Amount to send . ` tombstone_block ` - The tombstone block for the new transaction . ` rng ` - The randomness used by this function