74 lines
2.3 KiB
Rust
Raw Normal View History

2026-05-14 21:19:25 -04:00
use authenticated_transfer_core::Instruction as AuthTransferInstruction;
2026-05-17 12:32:43 -04:00
use common::HashType;
use nssa::{AccountId, program::Program};
2025-09-22 16:38:25 +03:00
use super::NativeTokenTransfer;
use crate::{
AccountIdentity, ExecutionFailureKind, cli::CliAccountMention,
program_facades::native_token_transfer::auth_transfer_preparation,
};
2025-09-22 16:38:25 +03:00
impl NativeTokenTransfer<'_> {
pub async fn send_public_transfer(
2025-09-22 16:38:25 +03:00
&self,
from: AccountId,
to: AccountId,
2025-09-22 16:38:25 +03:00
balance_to_move: u128,
2026-05-14 21:19:25 -04:00
from_mention: &CliAccountMention,
to_mention: &CliAccountMention,
) -> Result<HashType, ExecutionFailureKind> {
let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move);
let from_identity =
from_mention
.key_path()
.map_or(AccountIdentity::Public(from), |key_path| {
AccountIdentity::PublicKeycard {
account_id: from,
key_path: key_path.to_owned(),
}
});
let to_identity = to_mention
.key_path()
.map_or(AccountIdentity::Public(to), |key_path| {
AccountIdentity::PublicKeycard {
account_id: to,
key_path: key_path.to_owned(),
}
});
2026-05-17 12:32:43 -04:00
self.0
.send_pub_tx_with_pre_check(
vec![from_identity, to_identity],
instruction_data,
&program.into(),
tx_pre_check,
2026-05-17 12:32:43 -04:00
)
2026-04-28 20:48:02 -04:00
.await
2025-09-22 16:38:25 +03:00
}
2025-10-10 17:47:23 -03:00
pub async fn register_account(
2025-10-10 17:47:23 -03:00
&self,
from: AccountId,
2026-05-14 21:19:25 -04:00
account_mention: &CliAccountMention,
) -> Result<HashType, ExecutionFailureKind> {
let from_identity =
account_mention
.key_path()
.map_or(AccountIdentity::Public(from), |key_path| {
AccountIdentity::PublicKeycard {
account_id: from,
key_path: key_path.to_owned(),
}
});
let program = Program::authenticated_transfer_program();
let instruction_data = Program::serialize_instruction(AuthTransferInstruction::Initialize)?;
2026-05-17 12:32:43 -04:00
self.0
.send_pub_tx(vec![from_identity], instruction_data, &program.into())
2026-05-17 12:32:43 -04:00
.await
2025-10-10 17:47:23 -03:00
}
2025-09-22 16:38:25 +03:00
}