From 28c1fd39a47d95297172e23326f2107f1c8dcf7c Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Mon, 20 Oct 2025 10:01:54 +0300 Subject: [PATCH] fix: suggestions added 1 --- integration_tests/src/lib.rs | 257 ++++++++--------- wallet/src/cli/account.rs | 253 +++++++++++++++++ wallet/src/cli/chain.rs | 250 ++-------------- wallet/src/cli/mod.rs | 1 + .../src/cli/native_token_transfer_program.rs | 266 +++++++++--------- wallet/src/cli/pinata_program.rs | 8 +- wallet/src/lib.rs | 10 +- wallet/src/main.rs | 5 +- 8 files changed, 539 insertions(+), 511 deletions(-) create mode 100644 wallet/src/cli/account.rs diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index bf919da..2c89fbd 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -20,7 +20,7 @@ use tokio::task::JoinHandle; use wallet::{ Command, SubcommandReturnValue, WalletCore, cli::{ - chain::{ChainSubcommand, FetchSubcommand, RegisterSubcommand}, + account::{AccountSubcommand, FetchSubcommand, RegisterSubcommand}, native_token_transfer_program::{ NativeTokenTransferProgramSubcommand, NativeTokenTransferProgramSubcommandPrivate, NativeTokenTransferProgramSubcommandShielded, @@ -112,13 +112,11 @@ pub async fn post_test(residual: (ServerHandle, JoinHandle>, TempDir) pub async fn test_success() { info!("test_success"); - let command = Command::Transfer( - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic { - from: ACC_SENDER.to_string(), - to: ACC_RECEIVER.to_string(), - amount: 100, - }, - ); + let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { + from: ACC_SENDER.to_string(), + to: ACC_RECEIVER.to_string(), + amount: 100, + }); let wallet_config = fetch_config().await.unwrap(); @@ -150,9 +148,7 @@ pub async fn test_success() { pub async fn test_success_move_to_another_account() { info!("test_success_move_to_another_account"); - let command = Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, - )); + let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Public {})); let wallet_config = fetch_config().await.unwrap(); @@ -176,13 +172,11 @@ pub async fn test_success_move_to_another_account() { panic!("Failed to produce new account, not present in persistent accounts"); } - let command = Command::Transfer( - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic { - from: ACC_SENDER.to_string(), - to: new_persistent_account_addr.clone(), - amount: 100, - }, - ); + let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { + from: ACC_SENDER.to_string(), + to: new_persistent_account_addr.clone(), + amount: 100, + }); wallet::execute_subcommand(command).await.unwrap(); @@ -210,13 +204,11 @@ pub async fn test_success_move_to_another_account() { pub async fn test_failure() { info!("test_failure"); - let command = Command::Transfer( - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic { - from: ACC_SENDER.to_string(), - to: ACC_RECEIVER.to_string(), - amount: 1000000, - }, - ); + let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { + from: ACC_SENDER.to_string(), + to: ACC_RECEIVER.to_string(), + amount: 1000000, + }); let wallet_config = fetch_config().await.unwrap(); @@ -250,13 +242,11 @@ pub async fn test_failure() { pub async fn test_success_two_transactions() { info!("test_success_two_transactions"); - let command = Command::Transfer( - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic { - from: ACC_SENDER.to_string(), - to: ACC_RECEIVER.to_string(), - amount: 100, - }, - ); + let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { + from: ACC_SENDER.to_string(), + to: ACC_RECEIVER.to_string(), + amount: 100, + }); let wallet_config = fetch_config().await.unwrap(); @@ -285,13 +275,11 @@ pub async fn test_success_two_transactions() { info!("First TX Success!"); - let command = Command::Transfer( - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic { - from: ACC_SENDER.to_string(), - to: ACC_RECEIVER.to_string(), - amount: 100, - }, - ); + let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { + from: ACC_SENDER.to_string(), + to: ACC_RECEIVER.to_string(), + amount: 100, + }); wallet::execute_subcommand(command).await.unwrap(); @@ -343,20 +331,20 @@ pub async fn test_success_token_program() { let wallet_config = fetch_config().await.unwrap(); // Create new account for the token definition - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap(); // Create new account for the token supply holder - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap(); // Create new account for receiving a token transaction - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap(); @@ -492,8 +480,8 @@ pub async fn test_success_token_program_private_owned() { // Create new account for the token definition (public) let SubcommandReturnValue::RegisterAccount { addr: definition_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap() @@ -501,20 +489,18 @@ pub async fn test_success_token_program_private_owned() { panic!("invalid subcommand return value"); }; // Create new account for the token supply holder (private) - let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, - ))) - .await - .unwrap() - else { + let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand( + Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})), + ) + .await + .unwrap() else { panic!("invalid subcommand return value"); }; // Create new account for receiving a token transaction let SubcommandReturnValue::RegisterAccount { addr: recipient_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Private {}, ))) .await .unwrap() @@ -637,8 +623,8 @@ pub async fn test_success_token_program_private_claiming_path() { // Create new account for the token definition (public) let SubcommandReturnValue::RegisterAccount { addr: definition_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap() @@ -646,20 +632,18 @@ pub async fn test_success_token_program_private_claiming_path() { panic!("invalid subcommand return value"); }; // Create new account for the token supply holder (private) - let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, - ))) - .await - .unwrap() - else { + let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand( + Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})), + ) + .await + .unwrap() else { panic!("invalid subcommand return value"); }; // Create new account for receiving a token transaction let SubcommandReturnValue::RegisterAccount { addr: recipient_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Private {}, ))) .await .unwrap() @@ -740,13 +724,11 @@ pub async fn test_success_token_program_private_claiming_path() { info!("Waiting for next block creation"); tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; - let command = Command::Chain(ChainSubcommand::Fetch( - FetchSubcommand::FetchPrivateAccount { - tx_hash, - acc_addr: recipient_addr.to_string(), - output_id: 1, - }, - )); + let command = Command::Account(AccountSubcommand::Fetch(FetchSubcommand::PrivateAccount { + tx_hash, + acc_addr: recipient_addr.to_string(), + output_id: 1, + })); wallet::execute_subcommand(command).await.unwrap(); @@ -774,29 +756,27 @@ pub async fn test_success_token_program_shielded_owned() { // Create new account for the token definition (public) let SubcommandReturnValue::RegisterAccount { addr: definition_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap() else { panic!("invalid subcommand return value"); }; - // Create new account for the token supply holder (private) - let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, - ))) - .await - .unwrap() - else { + // Create new account for the token supply holder (public) + let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand( + Command::Account(AccountSubcommand::Register(RegisterSubcommand::Public {})), + ) + .await + .unwrap() else { panic!("invalid subcommand return value"); }; // Create new account for receiving a token transaction let SubcommandReturnValue::RegisterAccount { addr: recipient_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Private {}, ))) .await .unwrap() @@ -899,8 +879,8 @@ pub async fn test_success_token_program_deshielded_owned() { // Create new account for the token definition (public) let SubcommandReturnValue::RegisterAccount { addr: definition_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap() @@ -908,20 +888,18 @@ pub async fn test_success_token_program_deshielded_owned() { panic!("invalid subcommand return value"); }; // Create new account for the token supply holder (private) - let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, - ))) - .await - .unwrap() - else { + let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand( + Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})), + ) + .await + .unwrap() else { panic!("invalid subcommand return value"); }; // Create new account for receiving a token transaction let SubcommandReturnValue::RegisterAccount { addr: recipient_addr, - } = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPublic {}, + } = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( + RegisterSubcommand::Public {}, ))) .await .unwrap() @@ -1034,7 +1012,7 @@ pub async fn test_success_private_transfer_to_another_owned_account() { let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap(); let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private( - NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateOwnedAccount { + NativeTokenTransferProgramSubcommandPrivate::PrivateOwned { from: from.to_string(), to: to.to_string(), amount: 100, @@ -1071,7 +1049,7 @@ pub async fn test_success_private_transfer_to_another_foreign_account() { let to_ipk = Secp256k1Point::from_scalar(to_npk.0); let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private( - NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount { + NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { from: from.to_string(), to_npk: to_npk_string, to_ipk: hex::encode(to_ipk.0), @@ -1113,9 +1091,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_claiming_pat info!("test_success_private_transfer_to_another_owned_account_claiming_path"); let from: Address = ACC_SENDER_PRIVATE.parse().unwrap(); - let command = Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, - )); + let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})); let sub_ret = wallet::execute_subcommand(command).await.unwrap(); let SubcommandReturnValue::RegisterAccount { addr: to_addr } = sub_ret else { @@ -1137,7 +1113,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_claiming_pat .unwrap(); let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private( - NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount { + NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { from: from.to_string(), to_npk: hex::encode(to_keys.nullifer_public_key.0), to_ipk: hex::encode(to_keys.incoming_viewing_public_key.0), @@ -1152,13 +1128,11 @@ pub async fn test_success_private_transfer_to_another_owned_account_claiming_pat let tx = fetch_privacy_preserving_tx(&seq_client, tx_hash.clone()).await; - let command = Command::Chain(ChainSubcommand::Fetch( - FetchSubcommand::FetchPrivateAccount { - tx_hash, - acc_addr: to_addr.to_string(), - output_id: 1, - }, - )); + let command = Command::Account(AccountSubcommand::Fetch(FetchSubcommand::PrivateAccount { + tx_hash, + acc_addr: to_addr.to_string(), + output_id: 1, + })); wallet::execute_subcommand(command).await.unwrap(); let wallet_storage = WalletCore::start_from_config_update_chain(wallet_config) .await @@ -1187,9 +1161,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_cont_run_pat let from: Address = ACC_SENDER_PRIVATE.parse().unwrap(); - let command = Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, - )); + let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})); let sub_ret = wallet::execute_subcommand(command).await.unwrap(); let SubcommandReturnValue::RegisterAccount { addr: to_addr } = sub_ret else { @@ -1211,7 +1183,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_cont_run_pat .unwrap(); let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private( - NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount { + NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { from: from.to_string(), to_npk: hex::encode(to_keys.nullifer_public_key.0), to_ipk: hex::encode(to_keys.incoming_viewing_public_key.0), @@ -1257,13 +1229,11 @@ pub async fn test_success_deshielded_transfer_to_another_account() { info!("test_success_deshielded_transfer_to_another_account"); let from: Address = ACC_SENDER_PRIVATE.parse().unwrap(); let to: Address = ACC_RECEIVER.parse().unwrap(); - let command = Command::Transfer( - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferDeshielded { - from: from.to_string(), - to: to.to_string(), - amount: 100, - }, - ); + let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Deshielded { + from: from.to_string(), + to: to.to_string(), + amount: 100, + }); let wallet_config = fetch_config().await.unwrap(); let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap(); @@ -1305,7 +1275,7 @@ pub async fn test_success_shielded_transfer_to_another_owned_account() { let from: Address = ACC_SENDER.parse().unwrap(); let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap(); let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded( - NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShielded { + NativeTokenTransferProgramSubcommandShielded::ShieldedOwned { from: from.to_string(), to: to.to_string(), amount: 100, @@ -1348,12 +1318,13 @@ pub async fn test_success_shielded_transfer_to_another_foreign_account() { let from: Address = ACC_SENDER.parse().unwrap(); let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded( - NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShieldedForeignAccount { - from: from.to_string(), - to_npk: to_npk_string, - to_ipk: hex::encode(to_ipk.0), - amount: 100, - })); + NativeTokenTransferProgramSubcommandShielded::ShieldedForeign { + from: from.to_string(), + to_npk: to_npk_string, + to_ipk: hex::encode(to_ipk.0), + amount: 100, + }, + )); let wallet_config = fetch_config().await.unwrap(); @@ -1390,7 +1361,7 @@ pub async fn test_pinata() { let pinata_prize = 150; let solution = 989106; let command = Command::PinataProgram(PinataProgramSubcommand::Public( - PinataProgramSubcommandPublic::ClaimPinata { + PinataProgramSubcommandPublic::Claim { pinata_addr: pinata_addr.clone(), winner_addr: ACC_SENDER.to_string(), solution, @@ -1438,7 +1409,7 @@ pub async fn test_pinata_private_receiver() { let solution = 989106; let command = Command::PinataProgram(PinataProgramSubcommand::Private( - PinataProgramSubcommandPrivate::ClaimPinataPrivateReceiverOwned { + PinataProgramSubcommandPrivate::ClaimPrivateOwned { pinata_addr: pinata_addr.clone(), winner_addr: ACC_SENDER_PRIVATE.to_string(), solution, @@ -1471,13 +1442,11 @@ pub async fn test_pinata_private_receiver() { .unwrap() .balance; - let command = Command::Chain(ChainSubcommand::Fetch( - FetchSubcommand::FetchPrivateAccount { - tx_hash: tx_hash.clone(), - acc_addr: ACC_SENDER_PRIVATE.to_string(), - output_id: 0, - }, - )); + let command = Command::Account(AccountSubcommand::Fetch(FetchSubcommand::PrivateAccount { + tx_hash: tx_hash.clone(), + acc_addr: ACC_SENDER_PRIVATE.to_string(), + output_id: 0, + })); wallet::execute_subcommand(command).await.unwrap(); let wallet_config = fetch_config().await.unwrap(); @@ -1503,18 +1472,16 @@ pub async fn test_pinata_private_receiver_new_account() { let solution = 989106; // Create new account for the token supply holder (private) - let SubcommandReturnValue::RegisterAccount { addr: winner_addr } = - wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register( - RegisterSubcommand::RegisterAccountPrivate {}, - ))) - .await - .unwrap() - else { + let SubcommandReturnValue::RegisterAccount { addr: winner_addr } = wallet::execute_subcommand( + Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})), + ) + .await + .unwrap() else { panic!("invalid subcommand return value"); }; let command = Command::PinataProgram(PinataProgramSubcommand::Private( - PinataProgramSubcommandPrivate::ClaimPinataPrivateReceiverOwned { + PinataProgramSubcommandPrivate::ClaimPrivateOwned { pinata_addr: pinata_addr.clone(), winner_addr: winner_addr.to_string(), solution, diff --git a/wallet/src/cli/account.rs b/wallet/src/cli/account.rs new file mode 100644 index 0000000..9ec4b20 --- /dev/null +++ b/wallet/src/cli/account.rs @@ -0,0 +1,253 @@ +use std::str::FromStr; + +use anyhow::Result; +use clap::Subcommand; +use common::transaction::NSSATransaction; +use nssa::Address; + +use crate::{ + SubcommandReturnValue, WalletCore, cli::WalletSubcommand, helperfunctions::HumanReadableAccount, +}; + +///Represents generic chain CLI subcommand +#[derive(Subcommand, Debug, Clone)] +pub enum AccountSubcommand { + ///Get + #[command(subcommand)] + Get(GetSubcommand), + ///Fetch + #[command(subcommand)] + Fetch(FetchSubcommand), + ///Register + #[command(subcommand)] + Register(RegisterSubcommand), +} + +///Represents generic getter CLI subcommand +#[derive(Subcommand, Debug, Clone)] +pub enum GetSubcommand { + ///Get account `addr` balance + PublicAccountBalance { + #[arg(short, long)] + addr: String, + }, + ///Get account `addr` nonce + PublicAccountNonce { + #[arg(short, long)] + addr: String, + }, + ///Get account at address `addr` + PublicAccount { + #[arg(short, long)] + addr: String, + }, + ///Get private account with `addr` from storage + PrivateAccount { + #[arg(short, long)] + addr: String, + }, +} + +///Represents generic getter CLI subcommand +#[derive(Subcommand, Debug, Clone)] +pub enum FetchSubcommand { + ///Fetch transaction by `hash` + Tx { + #[arg(short, long)] + tx_hash: String, + }, + ///Claim account `acc_addr` generated in transaction `tx_hash`, using secret `sh_secret` at ciphertext id `ciph_id` + PrivateAccount { + ///tx_hash - valid 32 byte hex string + #[arg(long)] + tx_hash: String, + ///acc_addr - valid 32 byte hex string + #[arg(long)] + acc_addr: String, + ///output_id - id of the output in the transaction + #[arg(long)] + output_id: usize, + }, +} + +///Represents generic register CLI subcommand +#[derive(Subcommand, Debug, Clone)] +pub enum RegisterSubcommand { + ///Register new public account + Public {}, + ///Register new private account + Private {}, +} + +impl WalletSubcommand for GetSubcommand { + async fn handle_subcommand( + self, + wallet_core: &mut WalletCore, + ) -> Result { + match self { + GetSubcommand::PublicAccountBalance { addr } => { + let addr = Address::from_str(&addr)?; + + let balance = wallet_core.get_account_balance(addr).await?; + println!("Accounts {addr} balance is {balance}"); + + Ok(SubcommandReturnValue::Empty) + } + GetSubcommand::PublicAccountNonce { addr } => { + let addr = Address::from_str(&addr)?; + + let nonce = wallet_core.get_accounts_nonces(vec![addr]).await?[0]; + println!("Accounts {addr} nonce is {nonce}"); + + Ok(SubcommandReturnValue::Empty) + } + GetSubcommand::PublicAccount { addr } => { + let addr: Address = addr.parse()?; + let account = wallet_core.get_account_public(addr).await?; + let account_hr: HumanReadableAccount = account.clone().into(); + println!("{}", serde_json::to_string(&account_hr).unwrap()); + + Ok(SubcommandReturnValue::Account(account)) + } + GetSubcommand::PrivateAccount { addr } => { + let addr: Address = addr.parse()?; + if let Some(account) = wallet_core.get_account_private(&addr) { + println!("{}", serde_json::to_string(&account).unwrap()); + } else { + println!("Private account not found."); + } + Ok(SubcommandReturnValue::Empty) + } + } + } +} + +impl WalletSubcommand for FetchSubcommand { + async fn handle_subcommand( + self, + wallet_core: &mut WalletCore, + ) -> Result { + match self { + FetchSubcommand::Tx { tx_hash } => { + let tx_obj = wallet_core + .sequencer_client + .get_transaction_by_hash(tx_hash) + .await?; + + println!("Transaction object {tx_obj:#?}"); + + Ok(SubcommandReturnValue::Empty) + } + FetchSubcommand::PrivateAccount { + tx_hash, + acc_addr, + output_id: ciph_id, + } => { + let acc_addr: Address = acc_addr.parse().unwrap(); + + let account_key_chain = wallet_core + .storage + .user_data + .user_private_accounts + .get(&acc_addr); + + let Some((account_key_chain, _)) = account_key_chain else { + anyhow::bail!("Account not found"); + }; + + let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?; + + if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { + let to_ebc = tx.message.encrypted_private_post_states[ciph_id].clone(); + let to_comm = tx.message.new_commitments[ciph_id].clone(); + let shared_secret = + account_key_chain.calculate_shared_secret_receiver(to_ebc.epk); + + let res_acc_to = nssa_core::EncryptionScheme::decrypt( + &to_ebc.ciphertext, + &shared_secret, + &to_comm, + ciph_id as u32, + ) + .unwrap(); + + println!("RES acc to {res_acc_to:#?}"); + + println!("Transaction data is {:?}", tx.message); + + wallet_core + .storage + .insert_private_account_data(acc_addr, res_acc_to); + } + + let path = wallet_core.store_persistent_accounts().await?; + + println!("Stored persistent accounts at {path:#?}"); + + Ok(SubcommandReturnValue::Empty) + } + } + } +} + +impl WalletSubcommand for RegisterSubcommand { + async fn handle_subcommand( + self, + wallet_core: &mut WalletCore, + ) -> Result { + match self { + RegisterSubcommand::Public {} => { + let addr = wallet_core.create_new_account_public(); + + println!("Generated new account with addr {addr}"); + + let path = wallet_core.store_persistent_accounts().await?; + + println!("Stored persistent accounts at {path:#?}"); + + Ok(SubcommandReturnValue::RegisterAccount { addr }) + } + RegisterSubcommand::Private {} => { + let addr = wallet_core.create_new_account_private(); + + let (key, _) = wallet_core + .storage + .user_data + .get_private_account(&addr) + .unwrap(); + + println!("Generated new account with addr {addr}"); + println!("With npk {}", hex::encode(&key.nullifer_public_key)); + println!( + "With ipk {}", + hex::encode(key.incoming_viewing_public_key.to_bytes()) + ); + + let path = wallet_core.store_persistent_accounts().await?; + + println!("Stored persistent accounts at {path:#?}"); + + Ok(SubcommandReturnValue::RegisterAccount { addr }) + } + } + } +} + +impl WalletSubcommand for AccountSubcommand { + async fn handle_subcommand( + self, + wallet_core: &mut WalletCore, + ) -> Result { + match self { + AccountSubcommand::Get(get_subcommand) => { + get_subcommand.handle_subcommand(wallet_core).await + } + AccountSubcommand::Fetch(fetch_subcommand) => { + fetch_subcommand.handle_subcommand(wallet_core).await + } + AccountSubcommand::Register(register_subcommand) => { + register_subcommand.handle_subcommand(wallet_core).await + } + } + } +} diff --git a/wallet/src/cli/chain.rs b/wallet/src/cli/chain.rs index 258c545..4db18fc 100644 --- a/wallet/src/cli/chain.rs +++ b/wallet/src/cli/chain.rs @@ -1,236 +1,20 @@ -use std::str::FromStr; - use anyhow::Result; use clap::Subcommand; -use common::transaction::NSSATransaction; -use nssa::Address; -use crate::{ - SubcommandReturnValue, WalletCore, cli::WalletSubcommand, helperfunctions::HumanReadableAccount, -}; +use crate::{SubcommandReturnValue, WalletCore, cli::WalletSubcommand}; ///Represents generic chain CLI subcommand #[derive(Subcommand, Debug, Clone)] pub enum ChainSubcommand { - ///Get - #[command(subcommand)] - Get(GetSubcommand), - ///Fetch - #[command(subcommand)] - Fetch(FetchSubcommand), - ///Register - #[command(subcommand)] - Register(RegisterSubcommand), -} - -///Represents generic getter CLI subcommand -#[derive(Subcommand, Debug, Clone)] -pub enum GetSubcommand { - ///Get account `addr` balance - GetPublicAccountBalance { + GetLatestBlockId {}, + GetBlockAtId { #[arg(short, long)] - addr: String, + id: u64, }, - ///Get account `addr` nonce - GetPublicAccountNonce { + GetTransactionAtHash { #[arg(short, long)] - addr: String, + hash: String, }, - ///Get account at address `addr` - GetPublicAccount { - #[arg(short, long)] - addr: String, - }, - ///Get private account with `addr` from storage - GetPrivateAccount { - #[arg(short, long)] - addr: String, - }, -} - -///Represents generic getter CLI subcommand -#[derive(Subcommand, Debug, Clone)] -pub enum FetchSubcommand { - ///Fetch transaction by `hash` - FetchTx { - #[arg(short, long)] - tx_hash: String, - }, - ///Claim account `acc_addr` generated in transaction `tx_hash`, using secret `sh_secret` at ciphertext id `ciph_id` - FetchPrivateAccount { - ///tx_hash - valid 32 byte hex string - #[arg(long)] - tx_hash: String, - ///acc_addr - valid 32 byte hex string - #[arg(long)] - acc_addr: String, - ///output_id - id of the output in the transaction - #[arg(long)] - output_id: usize, - }, -} - -///Represents generic register CLI subcommand -#[derive(Subcommand, Debug, Clone)] -pub enum RegisterSubcommand { - ///Register new public account - RegisterAccountPublic {}, - ///Register new private account - RegisterAccountPrivate {}, -} - -impl WalletSubcommand for GetSubcommand { - async fn handle_subcommand( - self, - wallet_core: &mut WalletCore, - ) -> Result { - match self { - GetSubcommand::GetPublicAccountBalance { addr } => { - let addr = Address::from_str(&addr)?; - - let balance = wallet_core.get_account_balance(addr).await?; - println!("Accounts {addr} balance is {balance}"); - - Ok(SubcommandReturnValue::Empty) - } - GetSubcommand::GetPublicAccountNonce { addr } => { - let addr = Address::from_str(&addr)?; - - let nonce = wallet_core.get_accounts_nonces(vec![addr]).await?[0]; - println!("Accounts {addr} nonce is {nonce}"); - - Ok(SubcommandReturnValue::Empty) - } - GetSubcommand::GetPublicAccount { addr } => { - let addr: Address = addr.parse()?; - let account = wallet_core.get_account_public(addr).await?; - let account_hr: HumanReadableAccount = account.clone().into(); - println!("{}", serde_json::to_string(&account_hr).unwrap()); - - Ok(SubcommandReturnValue::Account(account)) - } - GetSubcommand::GetPrivateAccount { addr } => { - let addr: Address = addr.parse()?; - if let Some(account) = wallet_core.get_account_private(&addr) { - println!("{}", serde_json::to_string(&account).unwrap()); - } else { - println!("Private account not found."); - } - Ok(SubcommandReturnValue::Empty) - } - } - } -} - -impl WalletSubcommand for FetchSubcommand { - async fn handle_subcommand( - self, - wallet_core: &mut WalletCore, - ) -> Result { - match self { - FetchSubcommand::FetchTx { tx_hash } => { - let tx_obj = wallet_core - .sequencer_client - .get_transaction_by_hash(tx_hash) - .await?; - - println!("Transaction object {tx_obj:#?}"); - - Ok(SubcommandReturnValue::Empty) - } - FetchSubcommand::FetchPrivateAccount { - tx_hash, - acc_addr, - output_id: ciph_id, - } => { - let acc_addr: Address = acc_addr.parse().unwrap(); - - let account_key_chain = wallet_core - .storage - .user_data - .user_private_accounts - .get(&acc_addr); - - let Some((account_key_chain, _)) = account_key_chain else { - anyhow::bail!("Account not found"); - }; - - let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?; - - if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { - let to_ebc = tx.message.encrypted_private_post_states[ciph_id].clone(); - let to_comm = tx.message.new_commitments[ciph_id].clone(); - let shared_secret = - account_key_chain.calculate_shared_secret_receiver(to_ebc.epk); - - let res_acc_to = nssa_core::EncryptionScheme::decrypt( - &to_ebc.ciphertext, - &shared_secret, - &to_comm, - ciph_id as u32, - ) - .unwrap(); - - println!("RES acc to {res_acc_to:#?}"); - - println!("Transaction data is {:?}", tx.message); - - wallet_core - .storage - .insert_private_account_data(acc_addr, res_acc_to); - } - - let path = wallet_core.store_persistent_accounts().await?; - - println!("Stored persistent accounts at {path:#?}"); - - Ok(SubcommandReturnValue::Empty) - } - } - } -} - -impl WalletSubcommand for RegisterSubcommand { - async fn handle_subcommand( - self, - wallet_core: &mut WalletCore, - ) -> Result { - match self { - RegisterSubcommand::RegisterAccountPublic {} => { - let addr = wallet_core.create_new_account_public(); - - println!("Generated new account with addr {addr}"); - - let path = wallet_core.store_persistent_accounts().await?; - - println!("Stored persistent accounts at {path:#?}"); - - Ok(SubcommandReturnValue::RegisterAccount { addr }) - } - RegisterSubcommand::RegisterAccountPrivate {} => { - let addr = wallet_core.create_new_account_private(); - - let (key, _) = wallet_core - .storage - .user_data - .get_private_account(&addr) - .unwrap(); - - println!("Generated new account with addr {addr}"); - println!("With npk {}", hex::encode(&key.nullifer_public_key)); - println!( - "With ipk {}", - hex::encode(key.incoming_viewing_public_key.to_bytes()) - ); - - let path = wallet_core.store_persistent_accounts().await?; - - println!("Stored persistent accounts at {path:#?}"); - - Ok(SubcommandReturnValue::RegisterAccount { addr }) - } - } - } } impl WalletSubcommand for ChainSubcommand { @@ -239,15 +23,25 @@ impl WalletSubcommand for ChainSubcommand { wallet_core: &mut WalletCore, ) -> Result { match self { - ChainSubcommand::Get(get_subcommand) => { - get_subcommand.handle_subcommand(wallet_core).await + ChainSubcommand::GetLatestBlockId {} => { + let latest_block_res = wallet_core.sequencer_client.get_last_block().await?; + + println!("Last block id is {}", latest_block_res.last_block); } - ChainSubcommand::Fetch(fetch_subcommand) => { - fetch_subcommand.handle_subcommand(wallet_core).await + ChainSubcommand::GetBlockAtId { id } => { + let block_res = wallet_core.sequencer_client.get_block(id).await?; + + println!("Last block id is {:#?}", block_res.block); } - ChainSubcommand::Register(register_subcommand) => { - register_subcommand.handle_subcommand(wallet_core).await + ChainSubcommand::GetTransactionAtHash { hash } => { + let tx_res = wallet_core + .sequencer_client + .get_transaction_by_hash(hash) + .await?; + + println!("Last block id is {:#?}", tx_res.transaction); } } + Ok(SubcommandReturnValue::Empty) } } diff --git a/wallet/src/cli/mod.rs b/wallet/src/cli/mod.rs index 093a501..3aa1b7f 100644 --- a/wallet/src/cli/mod.rs +++ b/wallet/src/cli/mod.rs @@ -2,6 +2,7 @@ use anyhow::Result; use crate::{SubcommandReturnValue, WalletCore}; +pub mod account; pub mod chain; pub mod native_token_transfer_program; pub mod pinata_program; diff --git a/wallet/src/cli/native_token_transfer_program.rs b/wallet/src/cli/native_token_transfer_program.rs index eb6310c..666ea68 100644 --- a/wallet/src/cli/native_token_transfer_program.rs +++ b/wallet/src/cli/native_token_transfer_program.rs @@ -11,7 +11,7 @@ pub enum NativeTokenTransferProgramSubcommand { ///Send native token transfer from `from` to `to` for `amount` /// /// Public operation - SendNativeTokenTransferPublic { + Public { ///from - valid 32 byte hex string #[arg(long)] from: String, @@ -28,7 +28,7 @@ pub enum NativeTokenTransferProgramSubcommand { ///Send native token transfer from `from` to `to` for `amount` /// /// Deshielded operation - SendNativeTokenTransferDeshielded { + Deshielded { ///from - valid 32 byte hex string #[arg(long)] from: String, @@ -50,7 +50,7 @@ pub enum NativeTokenTransferProgramSubcommandShielded { ///Send native token transfer from `from` to `to` for `amount` /// /// Shielded operation - SendNativeTokenTransferShielded { + ShieldedOwned { ///from - valid 32 byte hex string #[arg(long)] from: String, @@ -64,7 +64,7 @@ pub enum NativeTokenTransferProgramSubcommandShielded { ///Send native token transfer from `from` to `to` for `amount` /// /// Shielded operation - SendNativeTokenTransferShieldedForeignAccount { + ShieldedForeign { ///from - valid 32 byte hex string #[arg(long)] from: String, @@ -86,7 +86,7 @@ pub enum NativeTokenTransferProgramSubcommandPrivate { ///Send native token transfer from `from` to `to` for `amount` /// /// Private operation - SendNativeTokenTransferPrivateOwnedAccount { + PrivateOwned { ///from - valid 32 byte hex string #[arg(long)] from: String, @@ -100,7 +100,7 @@ pub enum NativeTokenTransferProgramSubcommandPrivate { ///Send native token transfer from `from` to `to` for `amount` /// /// Private operation - SendNativeTokenTransferPrivateForeignAccount { + PrivateForeign { ///from - valid 32 byte hex string #[arg(long)] from: String, @@ -122,84 +122,92 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate { wallet_core: &mut WalletCore, ) -> Result { match self { - NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateOwnedAccount { from, to, amount } => { - let from: Address = from.parse().unwrap(); - let to: Address = to.parse().unwrap(); + NativeTokenTransferProgramSubcommandPrivate::PrivateOwned { from, to, amount } => { + let from: Address = from.parse().unwrap(); + let to: Address = to.parse().unwrap(); - let to_initialization = wallet_core.check_private_account_initialized(&to).await?; + let to_initialization = wallet_core.check_private_account_initialized(&to).await?; - let (res, [secret_from, secret_to]) = if let Some(to_proof) = to_initialization { - wallet_core - .send_private_native_token_transfer_owned_account_already_initialized(from, to, amount, to_proof) - .await? - } else { - wallet_core - .send_private_native_token_transfer_owned_account_not_initialized(from, to, amount) - .await? - }; + let (res, [secret_from, secret_to]) = if let Some(to_proof) = to_initialization { + wallet_core + .send_private_native_token_transfer_owned_account_already_initialized( + from, to, amount, to_proof, + ) + .await? + } else { + wallet_core + .send_private_native_token_transfer_owned_account_not_initialized( + from, to, amount, + ) + .await? + }; - println!("Results of tx send is {res:#?}"); + println!("Results of tx send is {res:#?}"); - let tx_hash = res.tx_hash; - let transfer_tx = wallet_core - .poll_native_token_transfer(tx_hash.clone()) - .await?; + let tx_hash = res.tx_hash; + let transfer_tx = wallet_core + .poll_native_token_transfer(tx_hash.clone()) + .await?; - if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { - let acc_decode_data = vec![(secret_from, from), (secret_to, to)]; + if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { + let acc_decode_data = vec![(secret_from, from), (secret_to, to)]; - wallet_core - .decode_insert_privacy_preserving_transaction_results(tx, &acc_decode_data)?; + wallet_core.decode_insert_privacy_preserving_transaction_results( + tx, + &acc_decode_data, + )?; + } + + let path = wallet_core.store_persistent_accounts().await?; + + println!("Stored persistent accounts at {path:#?}"); + + Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) } + NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { + from, + to_npk, + to_ipk, + amount, + } => { + let from: Address = from.parse().unwrap(); + 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); - let path = wallet_core.store_persistent_accounts().await?; + let to_ipk_res = hex::decode(to_ipk)?; + let mut to_ipk = [0u8; 33]; + to_ipk.copy_from_slice(&to_ipk_res); + let to_ipk = + nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec()); - println!("Stored persistent accounts at {path:#?}"); + let (res, [secret_from, _]) = wallet_core + .send_private_native_token_transfer_outer_account(from, to_npk, to_ipk, amount) + .await?; - Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) - } - NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount { - from, - to_npk, - to_ipk, - amount, - } => { - let from: Address = from.parse().unwrap(); - 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); + println!("Results of tx send is {res:#?}"); - let to_ipk_res = hex::decode(to_ipk)?; - let mut to_ipk = [0u8; 33]; - to_ipk.copy_from_slice(&to_ipk_res); - let to_ipk = - nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec()); + let tx_hash = res.tx_hash; + let transfer_tx = wallet_core + .poll_native_token_transfer(tx_hash.clone()) + .await?; - let (res, [secret_from, _]) = wallet_core - .send_private_native_token_transfer_outer_account(from, to_npk, to_ipk, amount) - .await?; + if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { + let acc_decode_data = vec![(secret_from, from)]; - println!("Results of tx send is {res:#?}"); + wallet_core.decode_insert_privacy_preserving_transaction_results( + tx, + &acc_decode_data, + )?; + } - let tx_hash = res.tx_hash; - let transfer_tx = wallet_core - .poll_native_token_transfer(tx_hash.clone()) - .await?; + let path = wallet_core.store_persistent_accounts().await?; - if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { - let acc_decode_data = vec![(secret_from, from)]; + println!("Stored persistent accounts at {path:#?}"); - wallet_core - .decode_insert_privacy_preserving_transaction_results(tx, &acc_decode_data)?; + Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) } - - let path = wallet_core.store_persistent_accounts().await?; - - println!("Stored persistent accounts at {path:#?}"); - - Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) - } } } } @@ -210,75 +218,79 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded { wallet_core: &mut WalletCore, ) -> Result { match self { - NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShielded { from, to, amount } => { - let from: Address = from.parse().unwrap(); - let to: Address = to.parse().unwrap(); + NativeTokenTransferProgramSubcommandShielded::ShieldedOwned { from, to, amount } => { + let from: Address = from.parse().unwrap(); + let to: Address = to.parse().unwrap(); - let to_initialization = wallet_core.check_private_account_initialized(&to).await?; + let to_initialization = wallet_core.check_private_account_initialized(&to).await?; - let (res, secret) = if let Some(to_proof) = to_initialization { - wallet_core - .send_shielded_native_token_transfer_already_initialized(from, to, amount, to_proof) - .await? - } else { - wallet_core - .send_shielded_native_token_transfer_not_initialized(from, to, amount) - .await? - }; + let (res, secret) = if let Some(to_proof) = to_initialization { + wallet_core + .send_shielded_native_token_transfer_already_initialized( + from, to, amount, to_proof, + ) + .await? + } else { + wallet_core + .send_shielded_native_token_transfer_not_initialized(from, to, amount) + .await? + }; - println!("Results of tx send is {res:#?}"); + println!("Results of tx send is {res:#?}"); - let tx_hash = res.tx_hash; - let transfer_tx = wallet_core - .poll_native_token_transfer(tx_hash.clone()) - .await?; + let tx_hash = res.tx_hash; + let transfer_tx = wallet_core + .poll_native_token_transfer(tx_hash.clone()) + .await?; - if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { - let acc_decode_data = vec![(secret, to)]; + if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx { + let acc_decode_data = vec![(secret, to)]; - wallet_core - .decode_insert_privacy_preserving_transaction_results(tx, &acc_decode_data)?; + wallet_core.decode_insert_privacy_preserving_transaction_results( + tx, + &acc_decode_data, + )?; + } + + let path = wallet_core.store_persistent_accounts().await?; + + println!("Stored persistent accounts at {path:#?}"); + + Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) } + NativeTokenTransferProgramSubcommandShielded::ShieldedForeign { + from, + to_npk, + to_ipk, + amount, + } => { + let from: Address = from.parse().unwrap(); - let path = wallet_core.store_persistent_accounts().await?; + 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); - println!("Stored persistent accounts at {path:#?}"); + let to_ipk_res = hex::decode(to_ipk)?; + let mut to_ipk = [0u8; 33]; + to_ipk.copy_from_slice(&to_ipk_res); + let to_ipk = + nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec()); - Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) - } - NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShieldedForeignAccount { - from, - to_npk, - to_ipk, - amount, - } => { - let from: Address = from.parse().unwrap(); + let (res, _) = wallet_core + .send_shielded_native_token_transfer_outer_account(from, to_npk, to_ipk, amount) + .await?; - 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); + println!("Results of tx send is {res:#?}"); - let to_ipk_res = hex::decode(to_ipk)?; - let mut to_ipk = [0u8; 33]; - to_ipk.copy_from_slice(&to_ipk_res); - let to_ipk = - nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec()); + let tx_hash = res.tx_hash; - let (res, _) = wallet_core - .send_shielded_native_token_transfer_outer_account(from, to_npk, to_ipk, amount) - .await?; + let path = wallet_core.store_persistent_accounts().await?; - println!("Results of tx send is {res:#?}"); + println!("Stored persistent accounts at {path:#?}"); - let tx_hash = res.tx_hash; - - let path = wallet_core.store_persistent_accounts().await?; - - println!("Stored persistent accounts at {path:#?}"); - - Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) - } + Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) + } } } } @@ -295,11 +307,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand { NativeTokenTransferProgramSubcommand::Shielded(shielded_subcommand) => { shielded_subcommand.handle_subcommand(wallet_core).await } - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferDeshielded { - from, - to, - amount, - } => { + NativeTokenTransferProgramSubcommand::Deshielded { from, to, amount } => { let from: Address = from.parse().unwrap(); let to: Address = to.parse().unwrap(); @@ -329,11 +337,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand { Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash }) } - NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic { - from, - to, - amount, - } => { + NativeTokenTransferProgramSubcommand::Public { from, to, amount } => { let from: Address = from.parse().unwrap(); let to: Address = to.parse().unwrap(); diff --git a/wallet/src/cli/pinata_program.rs b/wallet/src/cli/pinata_program.rs index 6ccfb97..75d3d6a 100644 --- a/wallet/src/cli/pinata_program.rs +++ b/wallet/src/cli/pinata_program.rs @@ -21,7 +21,7 @@ pub enum PinataProgramSubcommand { pub enum PinataProgramSubcommandPublic { // TODO: Testnet only. Refactor to prevent compilation on mainnet. // Claim piñata prize - ClaimPinata { + Claim { ///pinata_addr - valid 32 byte hex string #[arg(long)] pinata_addr: String, @@ -39,7 +39,7 @@ pub enum PinataProgramSubcommandPublic { pub enum PinataProgramSubcommandPrivate { // TODO: Testnet only. Refactor to prevent compilation on mainnet. // Claim piñata prize - ClaimPinataPrivateReceiverOwned { + ClaimPrivateOwned { ///pinata_addr - valid 32 byte hex string #[arg(long)] pinata_addr: String, @@ -58,7 +58,7 @@ impl WalletSubcommand for PinataProgramSubcommandPublic { wallet_core: &mut WalletCore, ) -> Result { match self { - PinataProgramSubcommandPublic::ClaimPinata { + PinataProgramSubcommandPublic::Claim { pinata_addr, winner_addr, solution, @@ -84,7 +84,7 @@ impl WalletSubcommand for PinataProgramSubcommandPrivate { wallet_core: &mut WalletCore, ) -> Result { match self { - PinataProgramSubcommandPrivate::ClaimPinataPrivateReceiverOwned { + PinataProgramSubcommandPrivate::ClaimPrivateOwned { pinata_addr, winner_addr, solution, diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index ae96064..501d096 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -18,7 +18,7 @@ use nssa_core::{Commitment, MembershipProof}; use tokio::io::AsyncWriteExt; use crate::cli::{ - WalletSubcommand, chain::ChainSubcommand, + WalletSubcommand, account::AccountSubcommand, chain::ChainSubcommand, native_token_transfer_program::NativeTokenTransferProgramSubcommand, pinata_program::PinataProgramSubcommand, }; @@ -193,6 +193,9 @@ pub enum Command { ///Chain command #[command(subcommand)] Chain(ChainSubcommand), + ///Chain command + #[command(subcommand)] + Account(AccountSubcommand), ///Pinata command #[command(subcommand)] PinataProgram(PinataProgramSubcommand), @@ -234,6 +237,11 @@ pub async fn execute_subcommand(command: Command) -> Result { chain_subcommand.handle_subcommand(&mut wallet_core).await? } + Command::Account(account_subcommand) => { + account_subcommand + .handle_subcommand(&mut wallet_core) + .await? + } Command::PinataProgram(pinata_subcommand) => { pinata_subcommand .handle_subcommand(&mut wallet_core) diff --git a/wallet/src/main.rs b/wallet/src/main.rs index 9cab532..ecc50d2 100644 --- a/wallet/src/main.rs +++ b/wallet/src/main.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use clap::Parser; +use clap::{CommandFactory, Parser}; use tokio::runtime::Builder; use wallet::{Args, execute_continious_run, execute_subcommand}; @@ -22,7 +22,8 @@ fn main() -> Result<()> { } else if args.continious_run { execute_continious_run().await.unwrap(); } else { - println!("NOTHING TO DO"); + let help = Args::command().render_long_help(); + println!("{help}"); } });