46 lines
1.7 KiB
Rust
Raw Normal View History

2025-07-19 22:31:25 -03:00
use super::{MockedClient, MockedSequencer};
use crate::mocked_components::sequencer::error::Error;
2025-07-18 08:56:12 -03:00
use core::account::Account;
2025-07-18 18:10:33 -03:00
use core::types::Address;
use core::visibility::AccountVisibility;
2025-07-18 08:56:12 -03:00
use nssa::program::TransferProgram;
impl MockedClient {
2025-07-18 15:56:41 -03:00
/// A shielded execution of the Transfer program
2025-07-18 16:42:55 -03:00
// All of this is executed locally by the sender
2025-07-18 15:56:41 -03:00
pub fn transfer_shielded(
&self,
2025-07-18 08:56:12 -03:00
to_address: &Address,
balance_to_move: u128,
sequencer: &mut MockedSequencer,
2025-07-19 22:31:25 -03:00
) -> Result<Account, Error> {
2025-07-18 16:42:55 -03:00
// Fetch commitment tree root from the sequencer
2025-07-18 08:56:12 -03:00
let commitment_tree_root = sequencer.get_commitment_tree_root();
2025-07-18 16:42:55 -03:00
// Fetch sender account from the sequencer
let from_account = sequencer.get_account(&self.user_address());
2025-07-18 16:42:55 -03:00
// Create a new default private account for the receiver
2025-07-18 18:10:33 -03:00
let to_account = Self::fresh_account_for_mint(*to_address);
2025-07-18 16:42:55 -03:00
// Set account visibilities
2025-07-18 16:42:55 -03:00
// First is the public account of the sender. Second is the private account minted in this
// execution
let visibilities = [AccountVisibility::Public, AccountVisibility::Private(None)];
2025-07-18 15:56:41 -03:00
2025-07-18 16:42:55 -03:00
// Execute privately (off-chain) and submit it to the sequencer
2025-07-18 09:55:23 -03:00
let private_outputs = Self::prove_and_send_to_sequencer::<TransferProgram>(
2025-07-18 16:42:55 -03:00
&[from_account, to_account],
2025-07-18 08:56:12 -03:00
balance_to_move,
&visibilities,
commitment_tree_root,
2025-07-18 09:55:23 -03:00
sequencer,
2025-07-18 11:19:08 -03:00
)?;
2025-07-18 16:42:55 -03:00
// There is only one private account as the output of this execution. It corresponds to the
// receiver.
2025-07-18 15:56:41 -03:00
let [receiver_private_account] = private_outputs.try_into().unwrap();
Ok(receiver_private_account)
2025-07-18 08:56:12 -03:00
}
}