52 lines
1.6 KiB
Rust
Raw Normal View History

2025-07-18 16:42:55 -03:00
use crate::mocked_components::sequencer::MockedSequencer;
2025-07-18 08:56:12 -03:00
use core::{
account::Account,
2025-07-18 18:10:33 -03:00
types::{Address, Key},
visibility::AccountVisibility,
2025-07-18 08:56:12 -03:00
};
pub mod transfer_deshielded;
pub mod transfer_private;
pub mod transfer_public;
pub mod transfer_shielded;
2025-07-18 16:42:55 -03:00
/// A client that creates and submits transfer transactions
pub struct MockedClient {
user_private_key: Key,
}
2025-07-18 08:56:12 -03:00
impl MockedClient {
pub const fn new(user_private_key: Key) -> Self {
2025-07-18 20:34:07 -03:00
Self { user_private_key }
}
pub fn user_address(&self) -> Address {
2025-07-18 15:56:41 -03:00
Account::address_for_key(&self.user_private_key)
}
2025-07-18 16:42:55 -03:00
/// Runs the outer program and submits the proof to the sequencer.
/// Returns the output private accounts of the execution.
2025-07-18 15:56:41 -03:00
pub fn prove_and_send_to_sequencer<P: nssa::Program>(
2025-07-18 09:55:23 -03:00
input_accounts: &[Account],
instruction_data: P::InstructionData,
visibilities: &[AccountVisibility],
2025-07-18 09:55:23 -03:00
commitment_tree_root: [u32; 8],
sequencer: &mut MockedSequencer,
2025-07-19 22:05:03 -03:00
) -> Result<Vec<Account>, nssa::Error> {
2025-07-18 16:42:55 -03:00
// Execute and generate proof of the outer program
let (receipt, private_outputs) =
2025-07-19 22:05:03 -03:00
nssa::execute_offchain::<P>(input_accounts, instruction_data, visibilities, commitment_tree_root)?;
2025-07-18 16:42:55 -03:00
// Send proof to the sequencer
2025-07-18 11:19:08 -03:00
sequencer.process_privacy_execution(receipt)?;
2025-07-18 09:55:23 -03:00
2025-07-18 16:42:55 -03:00
// Return private outputs
2025-07-18 11:19:08 -03:00
Ok(private_outputs)
2025-07-18 09:55:23 -03:00
}
2025-07-18 10:09:12 -03:00
2025-07-18 16:42:55 -03:00
/// Returns a new account used in privacy executions that mint private accounts
2025-07-18 10:09:12 -03:00
pub fn fresh_account_for_mint(address: Address) -> Account {
2025-07-18 15:56:41 -03:00
Account::new(address, 0)
2025-07-18 10:09:12 -03:00
}
2025-07-18 08:56:12 -03:00
}