39 lines
1.4 KiB
Rust
Raw Normal View History

2025-07-18 08:56:12 -03:00
use core::account::Account;
2025-07-18 15:56:41 -03:00
use core::visibility::InputVisibiility;
2025-07-18 08:56:12 -03:00
use core::types::{Address, Commitment, Key, Nullifier};
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 15:56:41 -03:00
pub fn transfer_deshielded(
&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 08:56:12 -03:00
// All of this is executed locally by the sender
let commitment_tree_root = sequencer.get_commitment_tree_root();
let receiver_addr = to_address;
2025-07-18 15:56:41 -03:00
// let from_account = sequencer.get_account(&self.user_address()).ok_or(())?;
let sender_commitment_auth_path =
sequencer.get_authentication_path_for(&from_account.commitment());
let to_account = sequencer.get_account(&to_address).unwrap();
let visibilities = vec![
InputVisibiility::Private(Some((self.user_private_key, sender_commitment_auth_path))),
InputVisibiility::Public,
];
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 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
}
}