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
|
|
|
|
2025-11-30 01:57:59 +03:00
|
|
|
use super::NativeTokenTransfer;
|
2026-05-14 21:19:25 -04:00
|
|
|
use crate::{
|
2026-05-18 08:54:50 -04:00
|
|
|
ExecutionFailureKind, cli::CliAccountMention, signing::SigningGroups,
|
2026-05-14 21:19:25 -04:00
|
|
|
};
|
2025-09-22 16:38:25 +03:00
|
|
|
|
2025-11-30 01:57:59 +03:00
|
|
|
impl NativeTokenTransfer<'_> {
|
|
|
|
|
pub async fn send_public_transfer(
|
2025-09-22 16:38:25 +03:00
|
|
|
&self,
|
2025-11-24 17:09:30 +03:00
|
|
|
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,
|
2026-03-13 22:38:23 +03:00
|
|
|
) -> Result<HashType, ExecutionFailureKind> {
|
2026-05-15 18:15:54 -04:00
|
|
|
let mut groups = SigningGroups::new();
|
|
|
|
|
groups
|
|
|
|
|
.add_sender(from_mention, from, self.0)
|
|
|
|
|
.and_then(|()| groups.add_recipient(to_mention, to, self.0))
|
2026-05-17 12:32:43 -04:00
|
|
|
.map_err(ExecutionFailureKind::from_anyhow)?;
|
|
|
|
|
|
|
|
|
|
self.0
|
|
|
|
|
.send_public_tx(
|
|
|
|
|
&Program::authenticated_transfer_program(),
|
|
|
|
|
vec![from, to],
|
|
|
|
|
AuthTransferInstruction::Transfer {
|
|
|
|
|
amount: balance_to_move,
|
|
|
|
|
},
|
|
|
|
|
groups,
|
|
|
|
|
)
|
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
|
|
|
|
2025-11-30 01:57:59 +03:00
|
|
|
pub async fn register_account(
|
2025-10-10 17:47:23 -03:00
|
|
|
&self,
|
2025-11-24 17:09:30 +03:00
|
|
|
from: AccountId,
|
2026-05-14 21:19:25 -04:00
|
|
|
account_mention: &CliAccountMention,
|
2026-03-13 22:38:23 +03:00
|
|
|
) -> Result<HashType, ExecutionFailureKind> {
|
2026-05-15 18:15:54 -04:00
|
|
|
let mut groups = SigningGroups::new();
|
|
|
|
|
groups
|
|
|
|
|
.add_sender(account_mention, from, self.0)
|
2026-05-17 12:32:43 -04:00
|
|
|
.map_err(ExecutionFailureKind::from_anyhow)?;
|
|
|
|
|
|
|
|
|
|
self.0
|
|
|
|
|
.send_public_tx(
|
|
|
|
|
&Program::authenticated_transfer_program(),
|
|
|
|
|
vec![from],
|
|
|
|
|
AuthTransferInstruction::Initialize,
|
|
|
|
|
groups,
|
|
|
|
|
)
|
|
|
|
|
.await
|
2025-10-10 17:47:23 -03:00
|
|
|
}
|
2025-09-22 16:38:25 +03:00
|
|
|
}
|