2025-11-30 01:57:59 +03:00
|
|
|
use common::error::ExecutionFailureKind;
|
|
|
|
|
use nssa::{Account, program::Program};
|
|
|
|
|
use nssa_core::program::InstructionData;
|
|
|
|
|
|
|
|
|
|
use crate::WalletCore;
|
|
|
|
|
|
|
|
|
|
pub mod deshielded;
|
|
|
|
|
pub mod private;
|
|
|
|
|
pub mod public;
|
|
|
|
|
pub mod shielded;
|
|
|
|
|
|
2026-03-10 00:17:43 +03:00
|
|
|
#[expect(clippy::multiple_inherent_impl, reason = "impl blocks split across multiple files for organization")]
|
2026-03-04 18:42:33 +03:00
|
|
|
pub struct NativeTokenTransfer<'wallet>(pub &'wallet WalletCore);
|
2025-11-30 01:57:59 +03:00
|
|
|
|
2026-03-10 00:17:43 +03:00
|
|
|
// TODO: handle large Err-variant properly
|
|
|
|
|
#[expect(clippy::result_large_err, reason = "ExecutionFailureKind is large, tracked by TODO")]
|
2025-11-30 01:57:59 +03:00
|
|
|
fn auth_transfer_preparation(
|
|
|
|
|
balance_to_move: u128,
|
|
|
|
|
) -> (
|
|
|
|
|
InstructionData,
|
|
|
|
|
Program,
|
|
|
|
|
impl FnOnce(&[&Account]) -> Result<(), ExecutionFailureKind>,
|
|
|
|
|
) {
|
|
|
|
|
let instruction_data = Program::serialize_instruction(balance_to_move).unwrap();
|
|
|
|
|
let program = Program::authenticated_transfer_program();
|
2026-02-16 14:50:50 -03:00
|
|
|
|
|
|
|
|
// TODO: handle large Err-variant properly
|
2025-11-30 01:57:59 +03:00
|
|
|
let tx_pre_check = move |accounts: &[&Account]| {
|
|
|
|
|
let from = accounts[0];
|
|
|
|
|
if from.balance >= balance_to_move {
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err(ExecutionFailureKind::InsufficientFundsError)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
(instruction_data, program, tx_pre_check)
|
|
|
|
|
}
|