2025-10-14 15:29:18 +03:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use clap::Subcommand;
|
|
|
|
|
use common::transaction::NSSATransaction;
|
2025-11-24 17:09:30 +03:00
|
|
|
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,
|
2025-11-27 22:07:53 +03:00
|
|
|
WalletCore,
|
|
|
|
|
cli::{SubcommandReturnValue, WalletSubcommand},
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
helperfunctions::{
|
|
|
|
|
AccountPrivacyKind, parse_addr_with_privacy_prefix, resolve_account_label,
|
|
|
|
|
resolve_id_or_label,
|
|
|
|
|
},
|
2025-11-30 01:57:59 +03:00
|
|
|
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 {
|
2026-03-10 00:17:43 +03:00
|
|
|
/// `account_id` - valid 32 byte base58 string with privacy prefix.
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
#[arg(
|
|
|
|
|
long,
|
|
|
|
|
conflicts_with = "account_label",
|
|
|
|
|
required_unless_present = "account_label"
|
|
|
|
|
)]
|
|
|
|
|
account_id: Option<String>,
|
|
|
|
|
/// Account label (alternative to --account-id).
|
|
|
|
|
#[arg(long, conflicts_with = "account_id")]
|
|
|
|
|
account_label: Option<String>,
|
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-03-10 00:17:43 +03:00
|
|
|
/// from - valid 32 byte base58 string with privacy prefix.
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
#[arg(
|
|
|
|
|
long,
|
|
|
|
|
conflicts_with = "from_label",
|
|
|
|
|
required_unless_present = "from_label"
|
|
|
|
|
)]
|
|
|
|
|
from: Option<String>,
|
|
|
|
|
/// From account label (alternative to --from).
|
|
|
|
|
#[arg(long, conflicts_with = "from")]
|
|
|
|
|
from_label: Option<String>,
|
2026-03-10 00:17:43 +03:00
|
|
|
/// to - valid 32 byte base58 string with privacy prefix.
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
#[arg(long, conflicts_with = "to_label")]
|
2025-10-27 14:32:28 +02:00
|
|
|
to: Option<String>,
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
/// To account label (alternative to --to).
|
|
|
|
|
#[arg(long, conflicts_with = "to")]
|
|
|
|
|
to_label: Option<String>,
|
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>,
|
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 {
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
Self::Init {
|
|
|
|
|
account_id,
|
|
|
|
|
account_label,
|
|
|
|
|
} => {
|
|
|
|
|
let resolved = resolve_id_or_label(
|
|
|
|
|
account_id,
|
|
|
|
|
account_label,
|
|
|
|
|
&wallet_core.storage.labels,
|
|
|
|
|
&wallet_core.storage.user_data,
|
|
|
|
|
)?;
|
|
|
|
|
let (account_id, addr_privacy) = parse_addr_with_privacy_prefix(&resolved)?;
|
2025-10-27 14:32:28 +02:00
|
|
|
|
|
|
|
|
match addr_privacy {
|
2025-11-24 17:09:30 +03:00
|
|
|
AccountPrivacyKind::Public => {
|
|
|
|
|
let account_id = account_id.parse()?;
|
2025-10-28 14:40:16 +02:00
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let tx_hash = NativeTokenTransfer(wallet_core)
|
2025-11-30 01:57:59 +03:00
|
|
|
.register_account(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
|
|
|
|
2026-03-13 22:38:23 +03: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:?}");
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
2025-10-27 14:32:28 +02:00
|
|
|
}
|
2025-11-24 17:09:30 +03:00
|
|
|
AccountPrivacyKind::Private => {
|
|
|
|
|
let account_id = account_id.parse()?;
|
2025-10-28 16:02:30 +02:00
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let (tx_hash, secret) = NativeTokenTransfer(wallet_core)
|
2025-11-30 02:18:38 +03:00
|
|
|
.register_account_private(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
|
|
|
|
2026-01-29 22:20:42 +03: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,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
2025-10-27 14:32:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
|
|
|
|
}
|
2026-03-09 18:27:56 +03:00
|
|
|
Self::Send {
|
2025-10-27 14:32:28 +02:00
|
|
|
from,
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
from_label,
|
2025-10-27 14:32:28 +02:00
|
|
|
to,
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
to_label,
|
2025-10-27 14:32:28 +02:00
|
|
|
to_npk,
|
2026-01-21 17:58:45 -05:00
|
|
|
to_vpk,
|
2025-10-27 14:32:28 +02:00
|
|
|
amount,
|
|
|
|
|
} => {
|
feat: add --account-label as alternative to --account-id across all wallet subcommands
Allow users to identify accounts by their human-readable label instead of the
full `Privacy/base58` account ID. This makes the CLI much more ergonomic for
users who have labeled their accounts.
- [x] Add `resolve_account_label()` in `helperfunctions.rs` that looks up a label,
determines account privacy (public/private), and returns the full `Privacy/id` string
- [x] Add `--account-label` (or `--from-label`, `--to-label`, `--definition-label`,
`--holder-label`, `--user-holding-*-label`) as mutually exclusive alternative to
every `--account-id`-style flag across all subcommands:
- `account get`, `account label`
- `auth-transfer init`, `auth-transfer send`
- `token new`, `token send`, `token burn`, `token mint`
- `pinata claim`
- `amm new`, `amm swap`, `amm add-liquidity`, `amm remove-liquidity`
- [x] Update zsh completion script with `_wallet_account_labels()` helper
- [x] Add bash completion script with `_wallet_get_account_labels()` helper
1. Start a local sequencer
2. Create accounts and label them: `wallet account new public --label alice`
3. Use labels in commands: `wallet account get --account-label alice`
4. Verify mutual exclusivity: `wallet account get --account-id <id> --account-label alice` should error
5. Test shell completions: `wallet account get --account-label <TAB>` should list labels
None
None
- [x] Complete PR description
- [x] Implement the core functionality
- [ ] Add/update tests
- [x] Add/update documentation and inline comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:33:51 +11:00
|
|
|
let from = resolve_id_or_label(
|
|
|
|
|
from,
|
|
|
|
|
from_label,
|
|
|
|
|
&wallet_core.storage.labels,
|
|
|
|
|
&wallet_core.storage.user_data,
|
|
|
|
|
)?;
|
|
|
|
|
let to = match (to, to_label) {
|
|
|
|
|
(v, None) => v,
|
|
|
|
|
(None, Some(label)) => Some(resolve_account_label(
|
|
|
|
|
&label,
|
|
|
|
|
&wallet_core.storage.labels,
|
|
|
|
|
&wallet_core.storage.user_data,
|
|
|
|
|
)?),
|
|
|
|
|
(Some(_), Some(_)) => {
|
|
|
|
|
anyhow::bail!("Provide only one of --to or --to-label")
|
|
|
|
|
}
|
|
|
|
|
};
|
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!(
|
2025-11-24 17:09:30 +03:00
|
|
|
"Provide either account account_id of receiver or their public keys"
|
2025-10-27 14:32:28 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
(Some(_), Some(_), Some(_)) => {
|
|
|
|
|
anyhow::bail!(
|
2025-11-24 17:09:30 +03:00
|
|
|
"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");
|
|
|
|
|
}
|
|
|
|
|
(Some(to), None, None) => {
|
|
|
|
|
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
|
|
|
|
|
let (to, to_privacy) = parse_addr_with_privacy_prefix(&to)?;
|
|
|
|
|
|
|
|
|
|
match (from_privacy, to_privacy) {
|
2025-11-24 17:09:30 +03:00
|
|
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Public) => {
|
2025-10-28 16:02:30 +02:00
|
|
|
NativeTokenTransferProgramSubcommand::Public { from, to, amount }
|
2025-10-27 14:32:28 +02:00
|
|
|
}
|
2025-11-24 17:09:30 +03:00
|
|
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Private) => {
|
2025-10-27 14:32:28 +02:00
|
|
|
NativeTokenTransferProgramSubcommand::Private(
|
|
|
|
|
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned {
|
2025-10-28 16:02:30 +02:00
|
|
|
from,
|
|
|
|
|
to,
|
2025-10-27 14:32:28 +02:00
|
|
|
amount,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-11-24 17:09:30 +03:00
|
|
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Public) => {
|
2025-10-27 14:32:28 +02:00
|
|
|
NativeTokenTransferProgramSubcommand::Deshielded {
|
2025-10-28 16:02:30 +02:00
|
|
|
from,
|
|
|
|
|
to,
|
2025-10-27 14:32:28 +02:00
|
|
|
amount,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-24 17:09:30 +03:00
|
|
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Private) => {
|
2025-10-27 14:32:28 +02:00
|
|
|
NativeTokenTransferProgramSubcommand::Shielded(
|
|
|
|
|
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned {
|
2025-10-28 16:02:30 +02:00
|
|
|
from,
|
|
|
|
|
to,
|
2025-10-27 14:32:28 +02:00
|
|
|
amount,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-21 17:58:45 -05:00
|
|
|
(None, Some(to_npk), Some(to_vpk)) => {
|
2025-10-27 14:32:28 +02:00
|
|
|
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
|
|
|
|
|
|
|
|
|
|
match from_privacy {
|
2025-11-24 17:09:30 +03:00
|
|
|
AccountPrivacyKind::Private => {
|
2025-10-27 14:32:28 +02:00
|
|
|
NativeTokenTransferProgramSubcommand::Private(
|
|
|
|
|
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
2025-10-28 16:02:30 +02:00
|
|
|
from,
|
2025-10-27 14:32:28 +02:00
|
|
|
to_npk,
|
2026-01-21 17:58:45 -05:00
|
|
|
to_vpk,
|
2025-10-27 14:32:28 +02:00
|
|
|
amount,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-11-24 17:09:30 +03:00
|
|
|
AccountPrivacyKind::Public => {
|
2025-10-27 14:32:28 +02:00
|
|
|
NativeTokenTransferProgramSubcommand::Shielded(
|
|
|
|
|
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
|
2025-10-28 16:02:30 +02:00
|
|
|
from,
|
2025-10-27 14:32:28 +02:00
|
|
|
to_npk,
|
2026-01-21 17:58:45 -05:00
|
|
|
to_vpk,
|
2025-10-27 14:32:28 +02:00
|
|
|
amount,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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)]
|
|
|
|
|
from: String,
|
2026-03-10 00:17:43 +03:00
|
|
|
/// to - valid 32 byte hex string.
|
2025-10-14 15:29:18 +03:00
|
|
|
#[arg(long)]
|
|
|
|
|
to: String,
|
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
|
|
|
/// 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)]
|
|
|
|
|
from: String,
|
2026-03-10 00:17:43 +03:00
|
|
|
/// to - valid 32 byte hex string.
|
2025-10-14 15:29:18 +03:00
|
|
|
#[arg(long)]
|
|
|
|
|
to: String,
|
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)]
|
|
|
|
|
from: String,
|
2026-03-10 00:17:43 +03:00
|
|
|
/// to - valid 32 byte hex string.
|
2025-10-14 15:29:18 +03:00
|
|
|
#[arg(long)]
|
|
|
|
|
to: String,
|
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
|
|
|
/// 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)]
|
|
|
|
|
from: String,
|
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,
|
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,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
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)]
|
|
|
|
|
from: String,
|
2026-03-10 00:17:43 +03:00
|
|
|
/// to - valid 32 byte hex string.
|
2025-10-14 15:29:18 +03:00
|
|
|
#[arg(long)]
|
|
|
|
|
to: String,
|
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)]
|
|
|
|
|
from: String,
|
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,
|
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 } => {
|
2025-11-24 17:09:30 +03:00
|
|
|
let from: AccountId = from.parse().unwrap();
|
|
|
|
|
let to: AccountId = to.parse().unwrap();
|
2025-10-14 15:29:18 +03:00
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let (tx_hash, [secret_from, secret_to]) = NativeTokenTransfer(wallet_core)
|
2025-11-30 01:57:59 +03:00
|
|
|
.send_private_transfer_to_owned_account(from, to, amount)
|
2025-11-30 01:19:06 +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
|
|
|
|
2026-01-29 22:20:42 +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,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
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,
|
2025-10-20 10:01:54 +03:00
|
|
|
amount,
|
|
|
|
|
} => {
|
2025-11-24 17:09:30 +03:00
|
|
|
let from: AccountId = from.parse().unwrap();
|
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);
|
|
|
|
|
|
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
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let (tx_hash, [secret_from, _]) = NativeTokenTransfer(wallet_core)
|
2026-01-21 17:58:45 -05:00
|
|
|
.send_private_transfer_to_outer_account(from, to_npk, to_vpk, amount)
|
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
|
|
|
|
2026-01-29 22:20:42 +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,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
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-03-09 18:27:56 +03:00
|
|
|
Self::ShieldedOwned { from, to, amount } => {
|
2025-11-24 17:09:30 +03:00
|
|
|
let from: AccountId = from.parse().unwrap();
|
|
|
|
|
let to: AccountId = to.parse().unwrap();
|
2025-10-14 15:29:18 +03:00
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let (tx_hash, secret) = NativeTokenTransfer(wallet_core)
|
2025-11-30 01:57:59 +03:00
|
|
|
.send_shielded_transfer(from, to, amount)
|
2025-11-30 01:19:06 +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
|
|
|
|
2026-01-29 22:20:42 +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
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
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,
|
2025-10-20 10:01:54 +03:00
|
|
|
amount,
|
|
|
|
|
} => {
|
2025-11-24 17:09:30 +03:00
|
|
|
let from: AccountId = from.parse().unwrap();
|
2025-10-14 15:29:18 +03:00
|
|
|
|
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
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let (tx_hash, _) = NativeTokenTransfer(wallet_core)
|
2026-01-21 17:58:45 -05:00
|
|
|
.send_shielded_transfer_to_outer_account(from, to_npk, to_vpk, amount)
|
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
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
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 } => {
|
2025-11-24 17:09:30 +03:00
|
|
|
let from: AccountId = from.parse().unwrap();
|
|
|
|
|
let to: AccountId = to.parse().unwrap();
|
2025-10-14 15:29:18 +03:00
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let (tx_hash, secret) = NativeTokenTransfer(wallet_core)
|
2025-11-30 01:57:59 +03:00
|
|
|
.send_deshielded_transfer(from, to, amount)
|
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
|
|
|
|
2026-01-29 22:20:42 +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,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
2025-10-14 15:29:18 +03:00
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
|
|
|
|
}
|
2026-03-09 18:27:56 +03:00
|
|
|
Self::Public { from, to, amount } => {
|
2025-11-24 17:09:30 +03:00
|
|
|
let from: AccountId = from.parse().unwrap();
|
|
|
|
|
let to: AccountId = to.parse().unwrap();
|
2025-10-14 15:29:18 +03:00
|
|
|
|
2026-03-13 22:38:23 +03:00
|
|
|
let tx_hash = NativeTokenTransfer(wallet_core)
|
2025-11-30 01:57:59 +03:00
|
|
|
.send_public_transfer(from, to, amount)
|
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
|
|
|
|
2026-03-13 22:38:23 +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:?}");
|
|
|
|
|
|
2025-12-31 04:02:25 +03:00
|
|
|
wallet_core.store_persistent_data().await?;
|
2025-10-14 15:29:18 +03:00
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|