From 0426bfe9c9ac00554cc95c7a61865ce4fad8d9e3 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 15 Jan 2026 12:05:35 +0200 Subject: [PATCH] fix: suggestions fix 1 --- Cargo.toml | 1 - wallet/Cargo.toml | 2 +- wallet/src/cli/programs/mod.rs | 38 +++++++++---------- wallet/src/privacy_preserving_tx.rs | 2 +- wallet/src/program_facades/mod.rs | 4 +- .../native_token_transfer/mod.rs | 4 +- wallet/src/program_facades/token.rs | 12 +++--- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc6ee0c..ef1b881 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,6 @@ chrono = "0.4.41" borsh = "1.5.7" base58 = "0.2.0" itertools = "0.14.0" -paste = "1.0.15" rocksdb = { version = "0.24.0", default-features = false, features = [ "snappy", diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index 3ef4857..a5e97ad 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -28,5 +28,5 @@ futures.workspace = true risc0-zkvm.workspace = true async-stream = "0.3.6" indicatif = { version = "0.18.3", features = ["improved_unicode"] } -paste.workspace = true +paste = "1.0.15" optfield = "0.4.0" diff --git a/wallet/src/cli/programs/mod.rs b/wallet/src/cli/programs/mod.rs index 475d5b5..3c94e57 100644 --- a/wallet/src/cli/programs/mod.rs +++ b/wallet/src/cli/programs/mod.rs @@ -18,15 +18,15 @@ trait ParsePrivacyPreservingAccount { #[macro_export] macro_rules! owned_account_name { - ($classname: ident, $field: ident) => { + ($structname: ident, $field: ident) => { #[derive(Debug, Args, Clone)] - pub struct $classname { + pub struct $structname { /// $field - valid 32 byte base58 string with privacy prefix #[arg(long)] pub $field: String, } - impl ParsePrivacyPreservingAccount for $classname { + impl ParsePrivacyPreservingAccount for $structname { fn parse(&self) -> Result { let (account_id, privacy) = parse_addr_with_privacy_prefix(&self.$field)?; @@ -47,10 +47,10 @@ owned_account_name!(ArgsSenderOwned, from); #[macro_export] macro_rules! maybe_unowned_account_name { - ($classname: ident, $field: ident) => { + ($structname: ident, $field: ident) => { paste! { #[derive(Debug, Args, Clone)] - pub struct $classname { + pub struct $structname { /// $field - valid 32 byte base58 string with privacy prefix #[arg(long)] pub $field: Option, @@ -62,7 +62,7 @@ macro_rules! maybe_unowned_account_name { pub [<$field _ipk>]: Option, } - impl ParsePrivacyPreservingAccount for $classname { + impl ParsePrivacyPreservingAccount for $structname { fn parse(&self) -> Result { match (&self.$field, &self.[<$field _npk>], &self.[<$field _ipk>]) { (None, None, None) => { @@ -74,28 +74,28 @@ macro_rules! maybe_unowned_account_name { ); } (_, Some(_), None) | (_, None, Some(_)) => { - anyhow::bail!("List of public keys is uncomplete"); + anyhow::bail!("List of public keys is incomplete"); } (Some($field), None, None) => ArgsSenderOwned { from: $field.clone(), } .parse(), - (None, Some([<$field _npk>]), Some([<$field _ipk>])) => { - let [<$field _npk_res>] = hex::decode([<$field _npk>])?; - let mut [<$field _npk>] = [0; 32]; - [<$field _npk>].copy_from_slice(&[<$field _npk_res>]); - let [<$field _npk>] = nssa_core::NullifierPublicKey([<$field _npk>]); + (None, Some(npk), Some(ipk)) => { + let npk_res = hex::decode(npk)?; + let mut npk = [0; 32]; + npk.copy_from_slice(&npk_res); + let npk = nssa_core::NullifierPublicKey(npk); - let [<$field _ipk_res>] = hex::decode([<$field _ipk>])?; - let mut [<$field _ipk>] = [0u8; 33]; - [<$field _ipk>].copy_from_slice(&[<$field _ipk_res>]); - let [<$field _ipk>] = nssa_core::encryption::shared_key_derivation::Secp256k1Point( - [<$field _ipk>].to_vec(), + let ipk_res = hex::decode(ipk)?; + let mut ipk = [0u8; 33]; + ipk.copy_from_slice(&ipk_res); + let ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point( + ipk.to_vec(), ); Ok(PrivacyPreservingAccount::PrivateForeign { - npk: [<$field _npk>], - ipk: [<$field _ipk>], + npk, + ipk, }) } } diff --git a/wallet/src/privacy_preserving_tx.rs b/wallet/src/privacy_preserving_tx.rs index c063ca3..07d45e8 100644 --- a/wallet/src/privacy_preserving_tx.rs +++ b/wallet/src/privacy_preserving_tx.rs @@ -39,7 +39,7 @@ impl PrivacyPreservingAccount { ) } - pub fn prepare_authorized_account(account_id: AccountId, privacy: AccountPrivacyKind) -> Self { + pub fn from_privacy_kind(account_id: AccountId, privacy: AccountPrivacyKind) -> Self { match privacy { AccountPrivacyKind::Private => Self::PrivateOwned(account_id), AccountPrivacyKind::Public => Self::Public(account_id), diff --git a/wallet/src/program_facades/mod.rs b/wallet/src/program_facades/mod.rs index c9eed32..20090cc 100644 --- a/wallet/src/program_facades/mod.rs +++ b/wallet/src/program_facades/mod.rs @@ -13,7 +13,7 @@ pub mod pinata; pub mod token; pub trait ProgramArgs { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData, @@ -27,7 +27,7 @@ pub async fn send_privacy_preserving_transaction_unified( acc_vector: Vec, method_data: PD, ) -> Result<(SendTxResponse, Vec), ExecutionFailureKind> { - let (instruction_data, program, tx_pre_check) = method_data.private_transfer_preparation(); + let (instruction_data, program, tx_pre_check) = method_data.prepare_private_transfer(); wallet_core .send_privacy_preserving_tx_with_pre_check( diff --git a/wallet/src/program_facades/native_token_transfer/mod.rs b/wallet/src/program_facades/native_token_transfer/mod.rs index 2c394b3..7d8ce95 100644 --- a/wallet/src/program_facades/native_token_transfer/mod.rs +++ b/wallet/src/program_facades/native_token_transfer/mod.rs @@ -17,7 +17,7 @@ pub struct NativeBalanceToMove { pub struct InitArgs {} impl ProgramArgs for NativeBalanceToMove { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData, @@ -40,7 +40,7 @@ impl ProgramArgs for NativeBalanceToMove { } impl ProgramArgs for InitArgs { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData, diff --git a/wallet/src/program_facades/token.rs b/wallet/src/program_facades/token.rs index c501fc4..4a9388b 100644 --- a/wallet/src/program_facades/token.rs +++ b/wallet/src/program_facades/token.rs @@ -82,7 +82,7 @@ impl Token<'_> { amount: u128, ) -> Result { let account_ids = vec![definition_account_id, holder_account_id]; - let (instruction, program, _) = TokenBurnArgs { amount }.private_transfer_preparation(); + let (instruction, program, _) = TokenBurnArgs { amount }.prepare_private_transfer(); let Ok(nonces) = self.0.get_accounts_nonces(vec![holder_account_id]).await else { return Err(ExecutionFailureKind::SequencerError); @@ -115,7 +115,7 @@ impl Token<'_> { amount: u128, ) -> Result { let account_ids = vec![definition_account_id, holder_account_id]; - let (instruction, program, _) = TokenMintArgs { amount }.private_transfer_preparation(); + let (instruction, program, _) = TokenMintArgs { amount }.prepare_private_transfer(); let Ok(nonces) = self .0 @@ -155,7 +155,7 @@ pub struct TokenDefinitionArgs { } impl ProgramArgs for TokenDefinitionArgs { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData, @@ -179,7 +179,7 @@ pub struct TokenTransferArgs { } impl ProgramArgs for TokenTransferArgs { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData, @@ -204,7 +204,7 @@ pub struct TokenBurnArgs { } impl ProgramArgs for TokenBurnArgs { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData, @@ -229,7 +229,7 @@ pub struct TokenMintArgs { } impl ProgramArgs for TokenMintArgs { - fn private_transfer_preparation( + fn prepare_private_transfer( &self, ) -> ( InstructionData,