2025-07-18 08:56:12 -03:00
|
|
|
use core::account::Account;
|
2025-07-18 18:10:33 -03:00
|
|
|
use core::types::Address;
|
2025-07-18 16:42:55 -03:00
|
|
|
use core::visibility::InputVisibiility;
|
2025-07-18 08:56:12 -03:00
|
|
|
|
|
|
|
|
use nssa::program::TransferProgram;
|
|
|
|
|
|
2025-07-18 09:55:23 -03:00
|
|
|
use super::{MockedClient, MockedSequencer};
|
2025-07-18 08:56:12 -03:00
|
|
|
|
|
|
|
|
impl MockedClient {
|
2025-07-18 16:42:55 -03:00
|
|
|
/// A deshielded transaction of the Transfer program.
|
|
|
|
|
/// All of this is executed locally by the sender
|
2025-07-18 15:56:41 -03:00
|
|
|
pub fn transfer_deshielded(
|
2025-07-18 12:04:43 -03:00
|
|
|
&self,
|
2025-07-18 15:56:41 -03:00
|
|
|
from_account: Account,
|
2025-07-18 08:56:12 -03:00
|
|
|
to_address: &Address,
|
|
|
|
|
balance_to_move: u128,
|
|
|
|
|
sequencer: &mut MockedSequencer,
|
2025-07-18 11:19:08 -03:00
|
|
|
) -> Result<Account, ()> {
|
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
|
|
|
// Compute authenticaton path for the input private account
|
|
|
|
|
let sender_commitment_auth_path = sequencer.get_authentication_path_for(&from_account.commitment());
|
|
|
|
|
|
|
|
|
|
// Fetch public account to deshield to
|
2025-07-18 15:56:41 -03:00
|
|
|
let to_account = sequencer.get_account(&to_address).unwrap();
|
2025-07-18 16:42:55 -03:00
|
|
|
|
|
|
|
|
// Set input visibilities
|
|
|
|
|
// First entry is the private sender. Second entry is the public receiver
|
2025-07-18 15:56:41 -03:00
|
|
|
let visibilities = vec![
|
|
|
|
|
InputVisibiility::Private(Some((self.user_private_key, sender_commitment_auth_path))),
|
|
|
|
|
InputVisibiility::Public,
|
|
|
|
|
];
|
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 15:56:41 -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's only one private output account corresponding to the new private account of
|
|
|
|
|
// the sender, with the remaining balance.
|
2025-07-18 15:56:41 -03:00
|
|
|
let [sender_private_account] = private_outputs.try_into().unwrap();
|
|
|
|
|
Ok(sender_private_account)
|
2025-07-18 08:56:12 -03:00
|
|
|
}
|
|
|
|
|
}
|