logos-execution-zone/wallet/src/cli/programs/native_token_transfer.rs

523 lines
19 KiB
Rust
Raw Normal View History

2025-10-14 15:29:18 +03:00
use anyhow::Result;
use clap::Subcommand;
use common::transaction::NSSATransaction;
use nssa::AccountId;
2025-10-14 15:29:18 +03:00
2025-10-27 14:32:28 +02:00
use crate::{
2025-12-11 14:46:16 +02:00
AccDecodeData::Decode,
WalletCore,
2026-05-14 21:19:25 -04:00
account::AccountIdWithPrivacy,
cli::{CliAccountMention, SubcommandReturnValue, WalletSubcommand},
program_facades::native_token_transfer::NativeTokenTransfer,
2025-10-27 14:32:28 +02:00
};
2026-03-10 00:17:43 +03:00
/// Represents generic CLI subcommand for a wallet working with native token transfer program.
2025-10-27 14:32:28 +02:00
#[derive(Subcommand, Debug, Clone)]
pub enum AuthTransferSubcommand {
2026-03-10 00:17:43 +03:00
/// Initialize account under authenticated transfer program.
2025-10-27 14:32:28 +02:00
Init {
/// Either 32 byte base58 account id string with privacy prefix or a label.
2026-05-14 21:19:25 -04:00
#[arg(long)]
account_id: CliAccountMention,
2025-10-27 14:32:28 +02:00
},
2026-03-10 00:17:43 +03:00
/// Send native tokens from one account to another with variable privacy.
2025-10-29 12:02:41 +02:00
///
2026-01-21 17:58:45 -05:00
/// If receiver is private, then `to` and (`to_npk` , `to_vpk`) is a mutually exclusive
2025-11-26 00:27:20 +03:00
/// patterns.
2025-10-29 12:02:41 +02:00
///
2025-11-26 00:27:20 +03:00
/// First is used for owned accounts, second otherwise.
2025-10-27 14:32:28 +02:00
Send {
2026-05-14 21:19:25 -04:00
/// Either 32 byte base58 account id string with privacy prefix or a label.
#[arg(long)]
from: CliAccountMention,
/// Either 32 byte base58 account id string with privacy prefix or a label.
#[arg(long)]
to: Option<CliAccountMention>,
2026-03-10 00:17:43 +03:00
/// `to_npk` - valid 32 byte hex string.
2025-10-27 14:32:28 +02:00
#[arg(long)]
to_npk: Option<String>,
2026-03-10 00:17:43 +03:00
/// `to_vpk` - valid 33 byte hex string.
2025-10-27 14:32:28 +02:00
#[arg(long)]
2026-01-21 17:58:45 -05:00
to_vpk: Option<String>,
/// Identifier for the recipient's private account (only used when sending to a foreign
/// private account via `--to-npk`/`--to-vpk`).
#[arg(long)]
to_identifier: Option<u128>,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-27 14:32:28 +02:00
#[arg(long)]
amount: u128,
},
}
impl WalletSubcommand for AuthTransferSubcommand {
async fn handle_subcommand(
self,
wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> {
match self {
Self::Init { account_id } => {
let resolved = account_id.resolve(wallet_core.storage())?;
2026-05-14 21:19:25 -04:00
match resolved {
2026-05-15 09:07:35 -04:00
AccountIdWithPrivacy::Public(pub_account_id) => {
let tx_hash = NativeTokenTransfer(wallet_core)
2026-05-15 09:07:35 -04:00
.register_account(pub_account_id, &account_id)
2025-10-27 14:32:28 +02:00
.await?;
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-27 14:32:28 +02:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-27 14:32:28 +02:00
println!("Transaction data is {transfer_tx:?}");
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-27 14:32:28 +02:00
}
2026-05-14 21:19:25 -04:00
AccountIdWithPrivacy::Private(account_id) => {
let (tx_hash, secret) = NativeTokenTransfer(wallet_core)
2026-05-15 18:15:54 -04:00
.register_account_private(account_id, &None)
2025-10-27 14:32:28 +02:00
.await?;
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-27 14:32:28 +02:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-27 14:32:28 +02:00
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
2025-12-11 14:46:16 +02:00
let acc_decode_data = vec![Decode(secret, account_id)];
2025-10-27 14:32:28 +02:00
wallet_core.decode_insert_privacy_preserving_transaction_results(
2026-03-03 23:21:08 +03:00
&tx,
2025-10-27 14:32:28 +02:00
&acc_decode_data,
)?;
}
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-27 14:32:28 +02:00
}
}
Ok(SubcommandReturnValue::Empty)
}
2026-03-09 18:27:56 +03:00
Self::Send {
2026-05-14 21:19:25 -04:00
from: from_account,
to: to_account,
2025-10-27 14:32:28 +02:00
to_npk,
2026-01-21 17:58:45 -05:00
to_vpk,
to_identifier,
2025-10-27 14:32:28 +02:00
amount,
} => {
2026-05-14 21:19:25 -04:00
let from = from_account.resolve(wallet_core.storage())?;
let to = to_account
.as_ref()
.map(|m| m.resolve(wallet_core.storage()))
.transpose()?;
2026-01-21 17:58:45 -05:00
let underlying_subcommand = match (to, to_npk, to_vpk) {
2025-10-27 14:32:28 +02:00
(None, None, None) => {
anyhow::bail!(
"Provide either account account_id of receiver or their public keys"
2025-10-27 14:32:28 +02:00
);
}
(Some(_), Some(_), Some(_)) => {
anyhow::bail!(
"Provide only one variant: either account account_id of receiver or their public keys"
2025-10-27 14:32:28 +02:00
);
}
(_, Some(_), None) | (_, None, Some(_)) => {
anyhow::bail!("List of public keys is uncomplete");
}
2026-05-14 21:19:25 -04:00
(Some(to), None, None) => match (from, to) {
(AccountIdWithPrivacy::Public(from), AccountIdWithPrivacy::Public(to)) => {
2026-05-15 09:07:35 -04:00
NativeTokenTransferProgramSubcommand::Public {
from,
to,
amount,
from_mention: from_account,
to_mention: to_account.expect("matched Some branch"),
}
2026-05-14 21:19:25 -04:00
}
(
AccountIdWithPrivacy::Private(from),
AccountIdWithPrivacy::Private(to),
) => NativeTokenTransferProgramSubcommand::Private(
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned {
from,
to,
amount,
},
),
(AccountIdWithPrivacy::Private(from), AccountIdWithPrivacy::Public(to)) => {
NativeTokenTransferProgramSubcommand::Deshielded { from, to, amount }
}
(AccountIdWithPrivacy::Public(from), AccountIdWithPrivacy::Private(to)) => {
NativeTokenTransferProgramSubcommand::Shielded(
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned {
from,
to,
amount,
2026-05-15 18:15:54 -04:00
from_mention: from_account,
2026-05-14 21:19:25 -04:00
},
)
}
},
(None, Some(to_npk), Some(to_vpk)) => match from {
AccountIdWithPrivacy::Private(from) => {
NativeTokenTransferProgramSubcommand::Private(
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
2025-10-28 16:02:30 +02:00
from,
2026-05-14 21:19:25 -04:00
to_npk,
to_vpk,
to_identifier,
2025-10-27 14:32:28 +02:00
amount,
2026-05-14 21:19:25 -04:00
},
)
2025-10-27 14:32:28 +02:00
}
2026-05-14 21:19:25 -04:00
AccountIdWithPrivacy::Public(from) => {
NativeTokenTransferProgramSubcommand::Shielded(
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
from,
to_npk,
to_vpk,
to_identifier,
amount,
2026-05-15 18:15:54 -04:00
from_mention: from_account,
2026-05-14 21:19:25 -04:00
},
)
2025-10-27 14:32:28 +02:00
}
2026-05-14 21:19:25 -04:00
},
2025-10-27 14:32:28 +02:00
};
underlying_subcommand.handle_subcommand(wallet_core).await
}
}
}
}
2025-10-14 15:29:18 +03:00
2026-03-10 00:17:43 +03:00
/// Represents generic CLI subcommand for a wallet working with native token transfer program.
2025-10-14 15:29:18 +03:00
#[derive(Subcommand, Debug, Clone)]
pub enum NativeTokenTransferProgramSubcommand {
2026-03-10 00:17:43 +03:00
/// Send native token transfer from `from` to `to` for `amount`.
2025-10-14 15:29:18 +03:00
///
2026-03-10 00:17:43 +03:00
/// Public operation.
2025-10-20 10:01:54 +03:00
Public {
2026-03-10 00:17:43 +03:00
/// from - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
from: AccountId,
2026-03-10 00:17:43 +03:00
/// to - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
to: AccountId,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-14 15:29:18 +03:00
#[arg(long)]
amount: u128,
2026-04-30 19:02:33 -04:00
#[arg(skip)]
2026-05-14 21:19:25 -04:00
from_mention: CliAccountMention,
#[arg(skip)]
to_mention: CliAccountMention,
2025-10-14 15:29:18 +03:00
},
2026-03-10 00:17:43 +03:00
/// Private execution.
2025-10-14 15:29:18 +03:00
#[command(subcommand)]
Private(NativeTokenTransferProgramSubcommandPrivate),
2026-03-10 00:17:43 +03:00
/// Send native token transfer from `from` to `to` for `amount`.
2025-10-14 15:29:18 +03:00
///
2026-03-10 00:17:43 +03:00
/// Deshielded operation.
2025-10-20 10:01:54 +03:00
Deshielded {
2026-03-10 00:17:43 +03:00
/// from - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
from: AccountId,
2026-03-10 00:17:43 +03:00
/// to - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
to: AccountId,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-14 15:29:18 +03:00
#[arg(long)]
amount: u128,
},
2026-03-10 00:17:43 +03:00
/// Shielded execution.
2025-10-14 15:29:18 +03:00
#[command(subcommand)]
Shielded(NativeTokenTransferProgramSubcommandShielded),
}
2025-11-26 00:27:20 +03:00
/// Represents generic shielded CLI subcommand for a wallet working with native token transfer
2026-03-10 00:17:43 +03:00
/// program.
2025-10-14 15:29:18 +03:00
#[derive(Subcommand, Debug, Clone)]
pub enum NativeTokenTransferProgramSubcommandShielded {
2026-03-10 00:17:43 +03:00
/// Send native token transfer from `from` to `to` for `amount`.
2025-10-14 15:29:18 +03:00
///
2026-03-10 00:17:43 +03:00
/// Shielded operation.
2025-10-20 10:01:54 +03:00
ShieldedOwned {
2026-03-10 00:17:43 +03:00
/// from - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
from: AccountId,
2026-03-10 00:17:43 +03:00
/// to - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
to: AccountId,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-04-27 18:47:02 -04:00
amount: u128,
2026-05-15 18:15:54 -04:00
#[arg(skip)]
from_mention: CliAccountMention,
2025-10-14 15:29:18 +03:00
},
2026-03-10 00:17:43 +03:00
/// Send native token transfer from `from` to `to` for `amount`.
2025-10-14 15:29:18 +03:00
///
2026-03-10 00:17:43 +03:00
/// Shielded operation.
2025-10-20 10:01:54 +03:00
ShieldedForeign {
2026-03-10 00:17:43 +03:00
/// from - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
from: AccountId,
2026-03-10 00:17:43 +03:00
/// `to_npk` - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
to_npk: String,
2026-03-10 00:17:43 +03:00
/// `to_vpk` - valid 33 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-01-21 17:58:45 -05:00
to_vpk: String,
/// Identifier for the recipient's private account.
#[arg(long)]
to_identifier: Option<u128>,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-04-27 18:47:02 -04:00
amount: u128,
2026-05-15 18:15:54 -04:00
#[arg(skip)]
from_mention: CliAccountMention,
2025-10-14 15:29:18 +03:00
},
}
2025-11-26 00:27:20 +03:00
/// Represents generic private CLI subcommand for a wallet working with native token transfer
2026-03-10 00:17:43 +03:00
/// program.
2025-10-14 15:29:18 +03:00
#[derive(Subcommand, Debug, Clone)]
pub enum NativeTokenTransferProgramSubcommandPrivate {
2026-03-10 00:17:43 +03:00
/// Send native token transfer from `from` to `to` for `amount`.
2025-10-14 15:29:18 +03:00
///
2026-03-10 00:17:43 +03:00
/// Private operation.
2025-10-20 10:01:54 +03:00
PrivateOwned {
2026-03-10 00:17:43 +03:00
/// from - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
from: AccountId,
2026-03-10 00:17:43 +03:00
/// to - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
to: AccountId,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-14 15:29:18 +03:00
#[arg(long)]
amount: u128,
},
2026-03-10 00:17:43 +03:00
/// Send native token transfer from `from` to `to` for `amount`.
2025-10-14 15:29:18 +03:00
///
2026-03-10 00:17:43 +03:00
/// Private operation.
2025-10-20 10:01:54 +03:00
PrivateForeign {
2026-03-10 00:17:43 +03:00
/// from - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-05-14 21:19:25 -04:00
from: AccountId,
2026-03-10 00:17:43 +03:00
/// `to_npk` - valid 32 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
to_npk: String,
2026-03-10 00:17:43 +03:00
/// `to_vpk` - valid 33 byte hex string.
2025-10-14 15:29:18 +03:00
#[arg(long)]
2026-01-21 17:58:45 -05:00
to_vpk: String,
/// Identifier for the recipient's private account.
#[arg(long)]
to_identifier: Option<u128>,
2026-03-10 00:17:43 +03:00
/// amount - amount of balance to move.
2025-10-14 15:29:18 +03:00
#[arg(long)]
amount: u128,
},
}
impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate {
async fn handle_subcommand(
self,
wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> {
match self {
2026-03-09 18:27:56 +03:00
Self::PrivateOwned { from, to, amount } => {
let (tx_hash, [secret_from, secret_to]) = NativeTokenTransfer(wallet_core)
2026-05-15 18:15:54 -04:00
.send_private_transfer_to_owned_account(from, to, amount, &None)
.await?;
2025-10-14 15:29:18 +03:00
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-14 15:29:18 +03:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-20 10:01:54 +03:00
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
2025-12-11 14:46:16 +02:00
let acc_decode_data = vec![Decode(secret_from, from), Decode(secret_to, to)];
2025-10-20 10:01:54 +03:00
wallet_core.decode_insert_privacy_preserving_transaction_results(
2026-03-03 23:21:08 +03:00
&tx,
2025-10-20 10:01:54 +03:00
&acc_decode_data,
)?;
}
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-20 10:01:54 +03:00
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
2025-10-14 15:29:18 +03:00
}
2026-03-09 18:27:56 +03:00
Self::PrivateForeign {
2025-10-20 10:01:54 +03:00
from,
to_npk,
2026-01-21 17:58:45 -05:00
to_vpk,
to_identifier,
2025-10-20 10:01:54 +03:00
amount,
} => {
let to_npk_res = hex::decode(to_npk)?;
let mut to_npk = [0; 32];
to_npk.copy_from_slice(&to_npk_res);
let to_npk = nssa_core::NullifierPublicKey(to_npk);
2026-01-21 17:58:45 -05:00
let to_vpk_res = hex::decode(to_vpk)?;
2026-03-04 18:42:33 +03:00
let mut to_vpk = [0_u8; 33];
2026-01-21 17:58:45 -05:00
to_vpk.copy_from_slice(&to_vpk_res);
let to_vpk =
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_vpk.to_vec());
2025-10-20 10:01:54 +03:00
let (tx_hash, [secret_from, _]) = NativeTokenTransfer(wallet_core)
2026-04-19 23:13:51 -03:00
.send_private_transfer_to_outer_account(
from,
to_npk,
to_vpk,
to_identifier.unwrap_or_else(rand::random),
2026-04-19 23:13:51 -03:00
amount,
2026-05-15 18:15:54 -04:00
&None,
2026-04-19 23:13:51 -03:00
)
2025-10-20 10:01:54 +03:00
.await?;
2025-10-14 15:29:18 +03:00
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-14 15:29:18 +03:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-14 15:29:18 +03:00
2025-10-20 10:01:54 +03:00
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
2025-12-11 14:46:16 +02:00
let acc_decode_data = vec![Decode(secret_from, from)];
2025-10-20 10:01:54 +03:00
wallet_core.decode_insert_privacy_preserving_transaction_results(
2026-03-03 23:21:08 +03:00
&tx,
2025-10-20 10:01:54 +03:00
&acc_decode_data,
)?;
}
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-20 10:01:54 +03:00
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
}
2025-10-14 15:29:18 +03:00
}
}
}
impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded {
async fn handle_subcommand(
self,
wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> {
match self {
2026-05-15 18:15:54 -04:00
Self::ShieldedOwned { from, to, amount, from_mention } => {
let (tx_hash, secret) = NativeTokenTransfer(wallet_core)
2026-05-15 18:15:54 -04:00
.send_shielded_transfer(from, to, amount, &from_mention)
2026-04-26 22:50:16 -04:00
.await?;
2025-10-14 15:29:18 +03:00
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-14 15:29:18 +03:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-14 15:29:18 +03:00
2025-10-20 10:01:54 +03:00
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
2025-12-11 14:46:16 +02:00
let acc_decode_data = vec![Decode(secret, to)];
2025-10-14 15:29:18 +03:00
2025-10-20 10:01:54 +03:00
wallet_core.decode_insert_privacy_preserving_transaction_results(
2026-03-03 23:21:08 +03:00
&tx,
2025-10-20 10:01:54 +03:00
&acc_decode_data,
)?;
}
2025-10-14 15:29:18 +03:00
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-14 15:29:18 +03:00
2025-10-20 10:01:54 +03:00
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
}
2026-03-09 18:27:56 +03:00
Self::ShieldedForeign {
2025-10-20 10:01:54 +03:00
from,
to_npk,
2026-01-21 17:58:45 -05:00
to_vpk,
to_identifier,
2025-10-20 10:01:54 +03:00
amount,
2026-05-15 18:15:54 -04:00
from_mention,
2025-10-20 10:01:54 +03:00
} => {
let to_npk_res = hex::decode(to_npk)?;
let mut to_npk = [0; 32];
to_npk.copy_from_slice(&to_npk_res);
let to_npk = nssa_core::NullifierPublicKey(to_npk);
2025-10-14 15:29:18 +03:00
2026-01-21 17:58:45 -05:00
let to_vpk_res = hex::decode(to_vpk)?;
2026-03-04 18:42:33 +03:00
let mut to_vpk = [0_u8; 33];
2026-01-21 17:58:45 -05:00
to_vpk.copy_from_slice(&to_vpk_res);
let to_vpk =
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_vpk.to_vec());
2025-10-20 10:01:54 +03:00
let (tx_hash, _) = NativeTokenTransfer(wallet_core)
2026-04-19 23:13:51 -03:00
.send_shielded_transfer_to_outer_account(
from,
to_npk,
to_vpk,
to_identifier.unwrap_or_else(rand::random),
2026-04-19 23:13:51 -03:00
amount,
2026-05-15 18:15:54 -04:00
&from_mention,
2026-04-19 23:13:51 -03:00
)
2025-10-20 10:01:54 +03:00
.await?;
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-20 10:01:54 +03:00
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-20 10:01:54 +03:00
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
}
2025-10-14 15:29:18 +03:00
}
}
}
impl WalletSubcommand for NativeTokenTransferProgramSubcommand {
async fn handle_subcommand(
self,
wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> {
match self {
2026-03-09 18:27:56 +03:00
Self::Private(private_subcommand) => {
2025-10-14 15:29:18 +03:00
private_subcommand.handle_subcommand(wallet_core).await
}
2026-03-09 18:27:56 +03:00
Self::Shielded(shielded_subcommand) => {
2025-10-14 15:29:18 +03:00
shielded_subcommand.handle_subcommand(wallet_core).await
}
2026-03-09 18:27:56 +03:00
Self::Deshielded { from, to, amount } => {
let (tx_hash, secret) = NativeTokenTransfer(wallet_core)
2026-05-15 18:15:54 -04:00
.send_deshielded_transfer(from, to, amount, &None)
2025-10-14 15:29:18 +03:00
.await?;
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-14 15:29:18 +03:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-14 15:29:18 +03:00
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
2025-12-11 14:46:16 +02:00
let acc_decode_data = vec![Decode(secret, from)];
2025-10-14 15:29:18 +03:00
wallet_core.decode_insert_privacy_preserving_transaction_results(
2026-03-03 23:21:08 +03:00
&tx,
2025-10-14 15:29:18 +03:00
&acc_decode_data,
)?;
}
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-14 15:29:18 +03:00
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
}
2026-05-15 09:07:35 -04:00
Self::Public {
from,
to,
amount,
from_mention,
to_mention,
} => {
let tx_hash = NativeTokenTransfer(wallet_core)
2026-05-14 21:19:25 -04:00
.send_public_transfer(from, to, amount, &from_mention, &to_mention)
2025-10-14 15:29:18 +03:00
.await?;
2026-03-14 03:20:37 +03:00
println!("Transaction hash is {tx_hash}");
2025-10-14 15:29:18 +03:00
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
2025-10-14 15:29:18 +03:00
println!("Transaction data is {transfer_tx:?}");
2026-05-14 21:19:25 -04:00
wallet_core.store_persistent_data()?;
2025-10-14 15:29:18 +03:00
Ok(SubcommandReturnValue::Empty)
}
}
}
}