From eb06bb99f8e70a0c6009e0d44f00459708d5426d Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Mon, 2 Dec 2024 13:40:59 -0400 Subject: [PATCH 1/3] remove getset --- Cargo.lock | 1 - libtonode-tests/tests/concrete.rs | 2 +- libtonode-tests/tests/sync.rs | 6 +-- zingolib/Cargo.toml | 1 - zingolib/src/blaze/trial_decryptions.rs | 15 ++++--- zingolib/src/commands.rs | 16 +++----- zingolib/src/lightclient/send.rs | 12 +++--- zingolib/src/testutils.rs | 6 +-- zingolib/src/wallet.rs | 17 +++----- zingolib/src/wallet/describe.rs | 8 ++-- zingolib/src/wallet/disk.rs | 8 ++-- zingolib/src/wallet/disk/testing.rs | 4 +- zingolib/src/wallet/disk/testing/tests.rs | 6 +-- zingolib/src/wallet/keys/unified.rs | 21 +++++----- zingolib/src/wallet/notes/interface.rs | 16 ++++---- zingolib/src/wallet/notes/query.rs | 40 +++++++------------ zingolib/src/wallet/send.rs | 6 +-- zingolib/src/wallet/sync.rs | 14 +++---- zingolib/src/wallet/traits.rs | 6 +-- zingolib/src/wallet/transaction_context.rs | 2 +- zingolib/src/wallet/transaction_record.rs | 8 ++-- zingolib/src/wallet/tx_map.rs | 9 ++--- zingolib/src/wallet/tx_map/spending_data.rs | 12 ++---- .../src/wallet/tx_map/trait_walletread.rs | 2 +- .../src/wallet/tx_map/trait_walletwrite.rs | 8 ++-- 25 files changed, 102 insertions(+), 144 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa14f2d587..3e75de3857 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4581,7 +4581,6 @@ dependencies = [ "enum_dispatch", "ff", "futures", - "getset", "group", "hex", "http", diff --git a/libtonode-tests/tests/concrete.rs b/libtonode-tests/tests/concrete.rs index 465e79a109..cb04d5a86e 100644 --- a/libtonode-tests/tests/concrete.rs +++ b/libtonode-tests/tests/concrete.rs @@ -70,7 +70,7 @@ fn check_view_capability_bounds( sent_t_value: Option, notes: &JsonValue, ) { - let UnifiedKeyStore::View(ufvk) = watch_wc.unified_key_store() else { + let UnifiedKeyStore::View(ufvk) = &watch_wc.unified_key_store else { panic!("should be viewing key!") }; //Orchard diff --git a/libtonode-tests/tests/sync.rs b/libtonode-tests/tests/sync.rs index 0a2e57551f..0344c6bebf 100644 --- a/libtonode-tests/tests/sync.rs +++ b/libtonode-tests/tests/sync.rs @@ -43,9 +43,9 @@ async fn sync_mainnet_test() { .await .unwrap(); - dbg!(lightclient.wallet.wallet_blocks()); - dbg!(lightclient.wallet.nullifier_map()); - dbg!(lightclient.wallet.sync_state()); + dbg!(lightclient.wallet.wallet_blocks); + dbg!(lightclient.wallet.nullifier_map); + dbg!(lightclient.wallet.sync_state); } #[tokio::test] diff --git a/zingolib/Cargo.toml b/zingolib/Cargo.toml index 94bdff27ca..a8a8eb237f 100644 --- a/zingolib/Cargo.toml +++ b/zingolib/Cargo.toml @@ -51,7 +51,6 @@ dirs.workspace = true enum_dispatch = { workspace = true } ff = { workspace = true } futures = { workspace = true } -getset = { workspace = true } group = { workspace = true } hex = { workspace = true } http.workspace = true diff --git a/zingolib/src/blaze/trial_decryptions.rs b/zingolib/src/blaze/trial_decryptions.rs index 0654d258c3..e5e2df001a 100644 --- a/zingolib/src/blaze/trial_decryptions.rs +++ b/zingolib/src/blaze/trial_decryptions.rs @@ -89,12 +89,11 @@ impl TrialDecryptions { let mut workers = FuturesUnordered::new(); let mut cbs = vec![]; - let sapling_ivk = sapling_crypto::zip32::DiversifiableFullViewingKey::try_from( - wc.unified_key_store(), - ) - .ok() - .map(|key| key.derive_ivk()); - let orchard_ivk = orchard::keys::FullViewingKey::try_from(wc.unified_key_store()) + let sapling_ivk = + sapling_crypto::zip32::DiversifiableFullViewingKey::try_from(&wc.unified_key_store) + .ok() + .map(|key| key.derive_ivk()); + let orchard_ivk = orchard::keys::FullViewingKey::try_from(&wc.unified_key_store) .ok() .map(|key| key.derive_ivk()); @@ -317,7 +316,7 @@ impl TrialDecryptions { let config = config.clone(); workers.push(tokio::spawn(async move { - let Ok(fvk) = D::unified_key_store_to_fvk(wc.unified_key_store()) else { + let Ok(fvk) = D::unified_key_store_to_fvk(&wc.unified_key_store) else { // skip any scanning if the wallet doesn't have viewing capability return Ok::<_, String>(()); }; @@ -452,7 +451,7 @@ where transaction_id, Some(output_index), position + i as u64, - &D::unified_key_store_to_fvk(wc.unified_key_store()).unwrap(), + &D::unified_key_store_to_fvk(&wc.unified_key_store).unwrap(), )?; } nodes_retention.push((node, retention)); diff --git a/zingolib/src/commands.rs b/zingolib/src/commands.rs index 89c58346bf..6c2bf44000 100644 --- a/zingolib/src/commands.rs +++ b/zingolib/src/commands.rs @@ -144,7 +144,7 @@ impl Command for WalletKindCommand { } .pretty(4) } else { - match lightclient.wallet.wallet_capability().unified_key_store() { + match &lightclient.wallet.wallet_capability().unified_key_store { UnifiedKeyStore::Spend(_) => object! { "kind" => "Loaded from unified spending key", "transparent" => true, @@ -746,15 +746,11 @@ impl Command for ExportUfvkCommand { } fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { - let ufvk: UnifiedFullViewingKey = match lightclient - .wallet - .wallet_capability() - .unified_key_store() - .try_into() - { - Ok(ufvk) => ufvk, - Err(e) => return e.to_string(), - }; + let ufvk: UnifiedFullViewingKey = + match (&lightclient.wallet.wallet_capability().unified_key_store).try_into() { + Ok(ufvk) => ufvk, + Err(e) => return e.to_string(), + }; object! { "ufvk" => ufvk.encode(&lightclient.config().chain), "birthday" => RT.block_on(lightclient.wallet.get_birthday()) diff --git a/zingolib/src/lightclient/send.rs b/zingolib/src/lightclient/send.rs index f6ebad2da7..9c93a10a54 100644 --- a/zingolib/src/lightclient/send.rs +++ b/zingolib/src/lightclient/send.rs @@ -142,8 +142,8 @@ pub mod send_with_proposal { .await .map_err(RecordCachedTransactionsError::Height)?; let mut transactions_to_record = vec![]; - if let Some(spending_data) = tx_map.spending_data_mut() { - for (_txid, raw_tx) in spending_data.cached_raw_transactions().iter() { + if let Some(spending_data) = &mut tx_map.spending_data { + for (_txid, raw_tx) in spending_data.cached_raw_transactions.iter() { transactions_to_record.push(Transaction::read( raw_tx.as_slice(), zcash_primitives::consensus::BranchId::for_height( @@ -206,12 +206,12 @@ pub mod send_with_proposal { .await .map_err(BroadcastCachedTransactionsError::Height)?; let calculated_tx_cache = tx_map - .spending_data() + .spending_data .as_ref() .ok_or(BroadcastCachedTransactionsError::Cache( TransactionCacheError::NoSpendCapability, ))? - .cached_raw_transactions() + .cached_raw_transactions .clone(); let mut txids = vec![]; for (txid, raw_tx) in calculated_tx_cache { @@ -251,12 +251,12 @@ pub mod send_with_proposal { } tx_map - .spending_data_mut() + .spending_data .as_mut() .ok_or(BroadcastCachedTransactionsError::Cache( TransactionCacheError::NoSpendCapability, ))? - .cached_raw_transactions_mut() + .cached_raw_transactions .clear(); Ok(txids) diff --git a/zingolib/src/testutils.rs b/zingolib/src/testutils.rs index f6ebfc99b5..ff239e59d4 100644 --- a/zingolib/src/testutils.rs +++ b/zingolib/src/testutils.rs @@ -47,11 +47,11 @@ pub mod regtest; /// TODO: Add Doc Comment Here! pub fn build_fvks_from_wallet_capability(wallet_capability: &WalletCapability) -> [Fvk; 3] { let orchard_vk: orchard::keys::FullViewingKey = - wallet_capability.unified_key_store().try_into().unwrap(); + (&wallet_capability.unified_key_store).try_into().unwrap(); let sapling_vk: sapling_crypto::zip32::DiversifiableFullViewingKey = - wallet_capability.unified_key_store().try_into().unwrap(); + (&wallet_capability.unified_key_store).try_into().unwrap(); let transparent_vk: zcash_primitives::legacy::keys::AccountPubKey = - wallet_capability.unified_key_store().try_into().unwrap(); + (&wallet_capability.unified_key_store).try_into().unwrap(); let mut transparent_vk_bytes = [0u8; 65]; transparent_vk_bytes.copy_from_slice(&transparent_vk.serialize()); diff --git a/zingolib/src/wallet.rs b/zingolib/src/wallet.rs index 57532ed8cc..13fa9b013b 100644 --- a/zingolib/src/wallet.rs +++ b/zingolib/src/wallet.rs @@ -4,7 +4,6 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use error::KeyError; -use getset::{Getters, MutGetters}; use zcash_keys::keys::UnifiedFullViewingKey; #[cfg(feature = "sync")] use zcash_primitives::consensus::BlockHeight; @@ -188,7 +187,6 @@ impl WalletBase { } /// In-memory wallet data struct -#[derive(Getters, MutGetters)] pub struct LightWallet { // The block at which this wallet was born. Rescans // will start from here. @@ -220,28 +218,23 @@ pub struct LightWallet { /// Wallet compact blocks #[cfg(feature = "sync")] - #[getset(get = "pub", get_mut = "pub")] - wallet_blocks: BTreeMap, + pub wallet_blocks: BTreeMap, /// Wallet transactions #[cfg(feature = "sync")] - #[getset(get = "pub", get_mut = "pub")] wallet_transactions: HashMap, /// Nullifier map #[cfg(feature = "sync")] - #[getset(get = "pub", get_mut = "pub")] - nullifier_map: NullifierMap, + pub nullifier_map: NullifierMap, /// Shard trees #[cfg(feature = "sync")] - #[getset(get = "pub", get_mut = "pub")] shard_trees: ShardTrees, /// Sync state #[cfg(feature = "sync")] - #[getset(get = "pub", get_mut = "pub")] - sync_state: SyncState, + pub sync_state: SyncState, } impl LightWallet { @@ -274,7 +267,7 @@ impl LightWallet { ///TODO: Make this work for orchard too pub async fn decrypt_message(&self, enc: Vec) -> Result { let ufvk: UnifiedFullViewingKey = - match self.wallet_capability().unified_key_store().try_into() { + match (&self.wallet_capability().unified_key_store).try_into() { Ok(ufvk) => ufvk, Err(e) => return Err(e.to_string()), }; @@ -386,7 +379,7 @@ impl LightWallet { format!("could not create initial address: {e}"), )); }; - let transaction_metadata_set = if wc.unified_key_store().is_spending_key() { + let transaction_metadata_set = if wc.unified_key_store.is_spending_key() { Arc::new(RwLock::new(TxMap::new_with_witness_trees( wc.transparent_child_addresses().clone(), wc.get_rejection_addresses().clone(), diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index 04a6ca0e0d..818f7d6a20 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -55,7 +55,7 @@ impl LightWallet { ::Recipient: Recipient, { // For the moment we encode lack of view capability as None - match self.wallet_capability().unified_key_store() { + match &self.wallet_capability().unified_key_store { UnifiedKeyStore::Spend(_) => (), UnifiedKeyStore::View(ufvk) => match D::SHIELDED_PROTOCOL { ShieldedProtocol::Sapling => { @@ -100,7 +100,7 @@ impl LightWallet { ::Recipient: Recipient, ::Note: PartialEq + Clone, { - if let UnifiedKeyStore::Spend(_) = self.wallet_capability().unified_key_store() { + if let UnifiedKeyStore::Spend(_) = self.wallet_capability().unified_key_store { self.confirmed_balance::().await } else { None @@ -108,7 +108,7 @@ impl LightWallet { } /// Sums the transparent balance (unspent) pub async fn get_transparent_balance(&self) -> Option { - match self.wallet_capability().unified_key_store() { + match &self.wallet_capability().unified_key_store { UnifiedKeyStore::Spend(_) => (), UnifiedKeyStore::View(ufvk) => { ufvk.transparent()?; @@ -195,7 +195,7 @@ impl LightWallet { ::Recipient: Recipient, ::Note: PartialEq + Clone, { - D::unified_key_store_to_fvk(wallet_capability.unified_key_store()).expect("to get fvk from the unified key store") + D::unified_key_store_to_fvk(&wallet_capability.unified_key_store).expect("to get fvk from the unified key store") .diversified_address(*note.diversifier()) .and_then(|address| { D::ua_from_contained_receiver(wallet_capability, &address) diff --git a/zingolib/src/wallet/disk.rs b/zingolib/src/wallet/disk.rs index d84578fe02..fa641545bd 100644 --- a/zingolib/src/wallet/disk.rs +++ b/zingolib/src/wallet/disk.rs @@ -223,7 +223,7 @@ impl LightWallet { // There is also the issue that the legacy transparent private key is derived an extra level to the external scope. if external_version < 29 { if let Some(mnemonic) = mnemonic.as_ref() { - wallet_capability.set_unified_key_store(UnifiedKeyStore::Spend(Box::new( + wallet_capability.unified_key_store = UnifiedKeyStore::Spend(Box::new( UnifiedSpendingKey::from_seed( &config.chain, &mnemonic.0.to_seed(""), @@ -238,8 +238,8 @@ impl LightWallet { ), ) })?, - ))); - } else if let UnifiedKeyStore::Spend(_) = wallet_capability.unified_key_store() { + )); + } else if let UnifiedKeyStore::Spend(_) = &wallet_capability.unified_key_store { return Err(io::Error::new( ErrorKind::Other, "loading from legacy spending keys with no seed phrase to recover", @@ -248,7 +248,7 @@ impl LightWallet { } info!("Keys in this wallet:"); - match wallet_capability.unified_key_store() { + match &wallet_capability.unified_key_store { UnifiedKeyStore::Spend(_) => { info!(" - orchard spending key"); info!(" - sapling extended spending key"); diff --git a/zingolib/src/wallet/disk/testing.rs b/zingolib/src/wallet/disk/testing.rs index a443b72fdc..282da56425 100644 --- a/zingolib/src/wallet/disk/testing.rs +++ b/zingolib/src/wallet/disk/testing.rs @@ -81,12 +81,12 @@ pub async fn assert_wallet_capability_matches_seed( let wc = wallet.wallet_capability(); // Compare USK - let UnifiedKeyStore::Spend(usk) = &wc.unified_key_store() else { + let UnifiedKeyStore::Spend(usk) = &wc.unified_key_store else { panic!("Expected Unified Spending Key"); }; assert_eq!( usk.to_bytes(Era::Orchard), - UnifiedSpendingKey::try_from(expected_wc.unified_key_store()) + UnifiedSpendingKey::try_from(&expected_wc.unified_key_store) .unwrap() .to_bytes(Era::Orchard) ); diff --git a/zingolib/src/wallet/disk/testing/tests.rs b/zingolib/src/wallet/disk/testing/tests.rs index c8a8644d7f..649e710b81 100644 --- a/zingolib/src/wallet/disk/testing/tests.rs +++ b/zingolib/src/wallet/disk/testing/tests.rs @@ -254,10 +254,10 @@ async fn reload_wallet_from_buffer() { .unwrap(); let wc = wallet.wallet_capability(); - let UnifiedKeyStore::Spend(usk) = wc.unified_key_store() else { + let UnifiedKeyStore::Spend(usk) = &wc.unified_key_store else { panic!("should be spending key!") }; - let UnifiedKeyStore::Spend(expected_usk) = expected_wc.unified_key_store() else { + let UnifiedKeyStore::Spend(expected_usk) = &expected_wc.unified_key_store else { panic!("should be spending key!") }; @@ -289,7 +289,7 @@ async fn reload_wallet_from_buffer() { ) .unwrap(); let v_wc = view_wallet.wallet_capability(); - let UnifiedKeyStore::View(v_ufvk) = v_wc.unified_key_store() else { + let UnifiedKeyStore::View(v_ufvk) = &v_wc.unified_key_store else { panic!("should be viewing key!"); }; let v_ufvk_string = v_ufvk.encode(&wallet.transaction_context.config.chain); diff --git a/zingolib/src/wallet/keys/unified.rs b/zingolib/src/wallet/keys/unified.rs index 3833b5bff0..8ac01d427a 100644 --- a/zingolib/src/wallet/keys/unified.rs +++ b/zingolib/src/wallet/keys/unified.rs @@ -11,7 +11,6 @@ use std::{marker::PhantomData, sync::Arc}; use append_only_vec::AppendOnlyVec; use bip0039::Mnemonic; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use getset::{Getters, Setters}; use orchard::note_encryption::OrchardDomain; use sapling_crypto::note_encryption::SaplingDomain; @@ -218,11 +217,9 @@ impl TryFrom<&UnifiedKeyStore> for zcash_primitives::legacy::keys::AccountPubKey /// loaded from a [`zcash_keys::keys::UnifiedSpendingKey`]
/// or a [`zcash_keys::keys::UnifiedFullViewingKey`].

/// In addition to fundamental spending and viewing keys, the type caches generated addresses. -#[derive(Debug, Getters, Setters)] pub struct WalletCapability { /// Unified key store - #[getset(get = "pub", set = "pub(crate)")] - unified_key_store: UnifiedKeyStore, + pub unified_key_store: UnifiedKeyStore, /// Cache of transparent addresses that the user has created. /// Receipts to a single address are correlated on chain. /// TODO: Is there any reason to have this field, apart from the @@ -344,7 +341,7 @@ impl WalletCapability { let previous_num_addresses = self.unified_addresses.len(); let orchard_receiver = if desired_receivers.orchard { - let fvk: orchard::keys::FullViewingKey = match self.unified_key_store().try_into() { + let fvk: orchard::keys::FullViewingKey = match (&self.unified_key_store).try_into() { Ok(viewkey) => viewkey, Err(e) => { self.addresses_write_lock @@ -363,7 +360,7 @@ impl WalletCapability { let mut address; let mut count = 0; let fvk: sapling_crypto::zip32::DiversifiableFullViewingKey = - match self.unified_key_store().try_into() { + match (&self.unified_key_store).try_into() { Ok(viewkey) => viewkey, Err(e) => { self.addresses_write_lock @@ -446,7 +443,7 @@ impl WalletCapability { }; let child_index = NonHardenedChildIndex::from_index(self.addresses().len() as u32) .expect("hardened bit should not be set for non-hardened child indexes"); - let transparent_receiver = match self.unified_key_store() { + let transparent_receiver = match &self.unified_key_store { UnifiedKeyStore::Spend(usk) => { derive_address(&usk.transparent().to_account_pubkey(), child_index) .map(Option::Some) @@ -467,7 +464,7 @@ impl WalletCapability { &self, chain: &ChainType, ) -> Result, KeyError> { - if let UnifiedKeyStore::Spend(usk) = self.unified_key_store() { + if let UnifiedKeyStore::Spend(usk) = &self.unified_key_store { self.transparent_child_addresses() .iter() .map(|(i, taddr)| -> Result<_, KeyError> { @@ -594,7 +591,7 @@ impl WalletCapability { /// TODO: Add Doc Comment Here! //TODO: NAME?????!! pub fn get_trees_witness_trees(&self) -> Option { - if self.unified_key_store().is_spending_key() { + if self.unified_key_store.is_spending_key() { Some(crate::data::witness_trees::WitnessTrees::default()) } else { None @@ -603,7 +600,7 @@ impl WalletCapability { /// Returns a selection of pools where the wallet can view funds. pub fn can_view(&self) -> ReceiverSelection { - match self.unified_key_store() { + match &self.unified_key_store { UnifiedKeyStore::Spend(_) => ReceiverSelection { orchard: true, sapling: true, @@ -789,7 +786,7 @@ impl ReadableWriteable for WalletCapability { fn write(&self, mut writer: W, input: ChainType) -> io::Result<()> { writer.write_u8(Self::VERSION)?; writer.write_u32::(self.rejection_addresses.len() as u32)?; - self.unified_key_store().write(&mut writer, input)?; + self.unified_key_store.write(&mut writer, input)?; Vector::write( &mut writer, &self.unified_addresses.iter().collect::>(), @@ -914,7 +911,7 @@ mod rejection { pub(crate) fn rejection_ivk( &self, ) -> Result { - AccountPubKey::try_from(self.unified_key_store())? + AccountPubKey::try_from(&self.unified_key_store)? .derive_ephemeral_ivk() .map_err(DerivationError::Transparent) .map_err(KeyError::KeyDerivationError) diff --git a/zingolib/src/wallet/notes/interface.rs b/zingolib/src/wallet/notes/interface.rs index f27c6b4a3f..96855261b1 100644 --- a/zingolib/src/wallet/notes/interface.rs +++ b/zingolib/src/wallet/notes/interface.rs @@ -70,9 +70,9 @@ pub trait OutputInterface: Sized { /// Returns true if the note has one of the spend statuses enumerated by the query fn spend_status_query(&self, query: OutputSpendStatusQuery) -> bool { - (*query.unspent() && !self.is_spent_confirmed() && !self.is_pending_spent()) - || (*query.pending_spent() && self.is_pending_spent()) - || (*query.spent() && self.is_spent_confirmed()) + (query.unspent && !self.is_spent_confirmed() && !self.is_pending_spent()) + || (query.pending_spent && self.is_pending_spent()) + || (query.spent && self.is_spent_confirmed()) } /// Returns true if the note is unspent (spendable). @@ -82,16 +82,14 @@ pub trait OutputInterface: Sized { /// Returns true if the note is one of the pools enumerated by the query. fn pool_query(&self, query: OutputPoolQuery) -> bool { - (*query.transparent() && self.pool_type() == PoolType::Transparent) - || (*query.sapling() - && self.pool_type() == PoolType::Shielded(ShieldedProtocol::Sapling)) - || (*query.orchard() - && self.pool_type() == PoolType::Shielded(ShieldedProtocol::Orchard)) + (query.transparent && self.pool_type() == PoolType::Transparent) + || (query.sapling && self.pool_type() == PoolType::Shielded(ShieldedProtocol::Sapling)) + || (query.orchard && self.pool_type() == PoolType::Shielded(ShieldedProtocol::Orchard)) } /// Returns true if the note is one of the spend statuses enumerated by the query AND one of the pools enumerated by the query. fn query(&self, query: OutputQuery) -> bool { - self.spend_status_query(*query.spend_status()) && self.pool_query(*query.pools()) + self.spend_status_query(query.spend_status) && self.pool_query(query.pools) } } diff --git a/zingolib/src/wallet/notes/query.rs b/zingolib/src/wallet/notes/query.rs index 6bd229b0d8..3741652579 100644 --- a/zingolib/src/wallet/notes/query.rs +++ b/zingolib/src/wallet/notes/query.rs @@ -1,7 +1,5 @@ //! Contains structs for querying a database about notes. -use getset::Getters; - use zcash_client_backend::PoolType; use zcash_client_backend::PoolType::Shielded; use zcash_client_backend::PoolType::Transparent; @@ -9,16 +7,13 @@ use zcash_client_backend::ShieldedProtocol::Orchard; use zcash_client_backend::ShieldedProtocol::Sapling; /// Selects received notes by how they been spent -#[derive(Getters, Clone, Copy)] +#[derive(Clone, Copy)] pub struct OutputSpendStatusQuery { /// will the query include unspent notes? - #[getset(get = "pub")] pub unspent: bool, /// will the query include pending_spent notes? - #[getset(get = "pub")] pub pending_spent: bool, /// will the query include spent notes? - #[getset(get = "pub")] pub spent: bool, } impl OutputSpendStatusQuery { @@ -65,16 +60,13 @@ impl OutputSpendStatusQuery { } /// Selects received notes by pool -#[derive(Getters, Clone, Copy)] +#[derive(Clone, Copy)] pub struct OutputPoolQuery { /// will the query include transparent notes? (coins) - #[getset(get = "pub")] pub transparent: bool, /// will the query include sapling notes? - #[getset(get = "pub")] pub sapling: bool, /// will the query include orchard notes? - #[getset(get = "pub")] pub orchard: bool, } impl OutputPoolQuery { @@ -117,14 +109,12 @@ impl OutputPoolQuery { } /// Selects received notes by any properties -#[derive(Getters, Clone, Copy)] +#[derive(Clone, Copy)] pub struct OutputQuery { /// selects spend status properties /// the query is expected to match note with ANY of the specified spend_stati AND ANY of the specified pools - #[getset(get = "pub")] pub spend_status: OutputSpendStatusQuery, /// selects pools - #[getset(get = "pub")] pub pools: OutputPoolQuery, } @@ -171,27 +161,27 @@ impl OutputQuery { } } /// will the query include unspent notes? - pub fn unspent(&self) -> &bool { - self.spend_status().unspent() + pub fn unspent(&self) -> bool { + self.spend_status.unspent } /// will the query include pending_spent notes? - pub fn pending_spent(&self) -> &bool { - self.spend_status().pending_spent() + pub fn pending_spent(&self) -> bool { + self.spend_status.pending_spent } /// will the query include spent notes? - pub fn spent(&self) -> &bool { - self.spend_status().spent() + pub fn spent(&self) -> bool { + self.spend_status.spent } /// will the query include transparent notes? (coins) - pub fn transparent(&self) -> &bool { - self.pools().transparent() + pub fn transparent(&self) -> bool { + self.pools.transparent } /// will the query include sapling notes? - pub fn sapling(&self) -> &bool { - self.pools().sapling() + pub fn sapling(&self) -> bool { + self.pools.sapling } /// will the query include orchard notes? - pub fn orchard(&self) -> &bool { - self.pools().orchard() + pub fn orchard(&self) -> bool { + self.pools.orchard } } diff --git a/zingolib/src/wallet/send.rs b/zingolib/src/wallet/send.rs index 96e2e7b163..eb08d3c2b0 100644 --- a/zingolib/src/wallet/send.rs +++ b/zingolib/src/wallet/send.rs @@ -139,11 +139,7 @@ impl LightWallet { .transaction_metadata_set .write() .await; - let usk = &self - .transaction_context - .key - .unified_key_store() - .try_into()?; + let usk = &(&self.transaction_context.key.unified_key_store).try_into()?; zcash_client_backend::data_api::wallet::create_proposed_transactions( wallet_db.deref_mut(), &self.transaction_context.config.chain, diff --git a/zingolib/src/wallet/sync.rs b/zingolib/src/wallet/sync.rs index e30d74c889..56bf21a303 100644 --- a/zingolib/src/wallet/sync.rs +++ b/zingolib/src/wallet/sync.rs @@ -25,11 +25,11 @@ impl SyncWallet for LightWallet { } fn get_sync_state(&self) -> Result<&SyncState, Self::Error> { - Ok(self.sync_state()) + Ok(&self.sync_state) } fn get_sync_state_mut(&mut self) -> Result<&mut SyncState, Self::Error> { - Ok(self.sync_state_mut()) + Ok(&mut self.sync_state) } fn get_unified_full_viewing_keys( @@ -63,7 +63,7 @@ impl SyncBlocks for LightWallet { fn get_wallet_blocks_mut( &mut self, ) -> Result<&mut BTreeMap, Self::Error> { - Ok(self.wallet_blocks_mut()) + Ok(&mut self.wallet_blocks) } } @@ -74,7 +74,7 @@ impl SyncTransactions for LightWallet { &HashMap, Self::Error, > { - Ok(self.wallet_transactions()) + Ok(&self.wallet_transactions) } fn get_wallet_transactions_mut( @@ -86,18 +86,18 @@ impl SyncTransactions for LightWallet { >, Self::Error, > { - Ok(self.wallet_transactions_mut()) + Ok(&mut self.wallet_transactions) } } impl SyncNullifiers for LightWallet { fn get_nullifiers_mut(&mut self) -> Result<&mut NullifierMap, ()> { - Ok(self.nullifier_map_mut()) + Ok(&mut self.nullifier_map) } } impl SyncShardTrees for LightWallet { fn get_shard_trees_mut(&mut self) -> Result<&mut ShardTrees, Self::Error> { - Ok(self.shard_trees_mut()) + Ok(&mut self.shard_trees) } } diff --git a/zingolib/src/wallet/traits.rs b/zingolib/src/wallet/traits.rs index bf99cd05ba..3ca991c294 100644 --- a/zingolib/src/wallet/traits.rs +++ b/zingolib/src/wallet/traits.rs @@ -1003,7 +1003,7 @@ impl ReadableWriteable<(sapling_crypto::Diversifier, &WalletCapability)> for sap Ok( ::unified_key_store_to_fvk( - wallet_capability.unified_key_store(), + &wallet_capability.unified_key_store, ) .expect("to get an fvk from the unified key store") .fvk() @@ -1048,7 +1048,7 @@ impl ReadableWriteable<(orchard::keys::Diversifier, &WalletCapability)> for orch ))?; let fvk = ::unified_key_store_to_fvk( - wallet_capability.unified_key_store(), + &wallet_capability.unified_key_store, ) .expect("to get an fvk from the unified key store"); Option::from(orchard::note::Note::from_parts( @@ -1341,7 +1341,7 @@ mod test { 0, ) .unwrap(); - let recipient = orchard::keys::FullViewingKey::try_from(wc.unified_key_store()) + let recipient = orchard::keys::FullViewingKey::try_from(&wc.unified_key_store) .unwrap() .address(Diversifier::from_bytes([0; 11]), zip32::Scope::External); diff --git a/zingolib/src/wallet/transaction_context.rs b/zingolib/src/wallet/transaction_context.rs index c26cdd37c9..7438f9a9fa 100644 --- a/zingolib/src/wallet/transaction_context.rs +++ b/zingolib/src/wallet/transaction_context.rs @@ -508,7 +508,7 @@ mod decrypt_transaction { }) .collect::>(); - let Ok(fvk) = D::unified_key_store_to_fvk(self.key.unified_key_store()) else { + let Ok(fvk) = D::unified_key_store_to_fvk(&self.key.unified_key_store) else { // skip scanning if wallet has no viewing capability return; }; diff --git a/zingolib/src/wallet/transaction_record.rs b/zingolib/src/wallet/transaction_record.rs index d147f1c99e..29b27960a2 100644 --- a/zingolib/src/wallet/transaction_record.rs +++ b/zingolib/src/wallet/transaction_record.rs @@ -190,22 +190,22 @@ impl TransactionRecord { /// Uses a query to select all notes with specific properties and sum them pub fn query_sum_value(&self, include_notes: OutputQuery) -> u64 { let mut sum = 0; - let spend_status_query = *include_notes.spend_status(); - if *include_notes.transparent() { + let spend_status_query = include_notes.spend_status; + if include_notes.transparent() { for note in self.transparent_outputs.iter() { if note.spend_status_query(spend_status_query) { sum += note.value() } } } - if *include_notes.sapling() { + if include_notes.sapling() { for note in self.sapling_notes.iter() { if note.spend_status_query(spend_status_query) { sum += note.value() } } } - if *include_notes.orchard() { + if include_notes.orchard() { for note in self.orchard_notes.iter() { if note.spend_status_query(spend_status_query) { sum += note.value() diff --git a/zingolib/src/wallet/tx_map.rs b/zingolib/src/wallet/tx_map.rs index a721c2c1d5..97a73c964c 100644 --- a/zingolib/src/wallet/tx_map.rs +++ b/zingolib/src/wallet/tx_map.rs @@ -10,7 +10,6 @@ use crate::{ transaction_records_by_id::{trait_inputsource::InputSourceError, TransactionRecordsById}, }, }; -use getset::{Getters, MutGetters}; use spending_data::SpendingData; use std::{fmt::Debug, sync::Arc}; use zcash_client_backend::wallet::TransparentAddressMetadata; @@ -19,12 +18,10 @@ use zcash_primitives::legacy::{keys::EphemeralIvk, TransparentAddress}; /// HashMap of all transactions in a wallet, keyed by txid. /// Note that the parent is expected to hold a RwLock, so we will assume that all accesses to /// this struct are threadsafe/locked properly. -#[derive(Getters, MutGetters)] pub struct TxMap { /// TODO: Doc-comment! pub transaction_records_by_id: TransactionRecordsById, - #[getset(get = "pub(crate)", get_mut = "pub(crate)")] - spending_data: Option, + pub(crate) spending_data: Option, // as below pub(crate) transparent_child_addresses: Arc>, @@ -72,12 +69,12 @@ impl TxMap { pub fn witness_trees(&self) -> Option<&WitnessTrees> { self.spending_data .as_ref() - .map(|spending_data| spending_data.witness_trees()) + .map(|spending_data| &spending_data.witness_trees) } pub(crate) fn witness_trees_mut(&mut self) -> Option<&mut WitnessTrees> { self.spending_data .as_mut() - .map(|spending_data| spending_data.witness_trees_mut()) + .map(|spending_data| &mut spending_data.witness_trees) } /// TODO: Doc-comment! pub fn clear(&mut self) { diff --git a/zingolib/src/wallet/tx_map/spending_data.rs b/zingolib/src/wallet/tx_map/spending_data.rs index 45aae3922a..78a4a7a4f9 100644 --- a/zingolib/src/wallet/tx_map/spending_data.rs +++ b/zingolib/src/wallet/tx_map/spending_data.rs @@ -1,20 +1,14 @@ //! the subsection of TxMap that only applies to spending wallets -use getset::{Getters, MutGetters}; - use zcash_primitives::{legacy::keys::EphemeralIvk, transaction::TxId}; use crate::data::witness_trees::WitnessTrees; /// the subsection of TxMap that only applies to spending wallets -#[derive(Getters, MutGetters)] pub(crate) struct SpendingData { - #[getset(get = "pub(crate)", get_mut = "pub(crate)")] - witness_trees: WitnessTrees, - #[getset(get = "pub(crate)", get_mut = "pub(crate)")] - cached_raw_transactions: Vec<(TxId, Vec)>, - #[getset(get = "pub(crate)", get_mut = "pub(crate)")] - rejection_ivk: EphemeralIvk, + pub(crate) witness_trees: WitnessTrees, + pub(crate) cached_raw_transactions: Vec<(TxId, Vec)>, + pub(crate) rejection_ivk: EphemeralIvk, } impl SpendingData { diff --git a/zingolib/src/wallet/tx_map/trait_walletread.rs b/zingolib/src/wallet/tx_map/trait_walletread.rs index 1e92bea025..52af8812ba 100644 --- a/zingolib/src/wallet/tx_map/trait_walletread.rs +++ b/zingolib/src/wallet/tx_map/trait_walletread.rs @@ -330,7 +330,7 @@ mod tests { .spending_data .as_mut() .unwrap() - .witness_trees_mut() + .witness_trees .witness_tree_orchard .checkpoint(8421.into()) .unwrap(); diff --git a/zingolib/src/wallet/tx_map/trait_walletwrite.rs b/zingolib/src/wallet/tx_map/trait_walletwrite.rs index 14aaa62333..d7d520e3fe 100644 --- a/zingolib/src/wallet/tx_map/trait_walletwrite.rs +++ b/zingolib/src/wallet/tx_map/trait_walletwrite.rs @@ -64,9 +64,9 @@ impl WalletWrite for TxMap { tx.write(&mut raw_tx) .map_err(TxMapTraitError::TransactionWrite)?; - if let Some(spending_data) = self.spending_data_mut() { + if let Some(spending_data) = &mut self.spending_data { spending_data - .cached_raw_transactions_mut() + .cached_raw_transactions .push((tx.txid(), raw_tx)); } else { return Err(TxMapTraitError::NoSpendCapability); @@ -119,13 +119,13 @@ impl WalletWrite for TxMap { )>, Self::Error, > { - self.spending_data() + self.spending_data .as_ref() .map(|spending_data| { iter::repeat_with(|| { crate::wallet::data::new_rejection_address( &self.rejection_addresses, - spending_data.rejection_ivk(), + &spending_data.rejection_ivk, ) .map_err(TxMapTraitError::TexSendError) }) From 2fc0482d8ce8b041074075b80cd48bfbaef57c74 Mon Sep 17 00:00:00 2001 From: Oscar Pepper Date: Tue, 3 Dec 2024 02:02:43 +0000 Subject: [PATCH 2/3] fix doc warnings --- Cargo.lock | 1 + zingo-sync/Cargo.toml | 1 + zingo-sync/src/keys.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa14f2d587..ee74259a60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4558,6 +4558,7 @@ dependencies = [ "zcash_primitives", "zingo-memo", "zingo-netutils", + "zip32", ] [[package]] diff --git a/zingo-sync/Cargo.toml b/zingo-sync/Cargo.toml index 3df25e5ec8..a93e901052 100644 --- a/zingo-sync/Cargo.toml +++ b/zingo-sync/Cargo.toml @@ -17,6 +17,7 @@ sapling-crypto.workspace = true orchard.workspace = true incrementalmerkletree.workspace = true shardtree.workspace = true +zip32.workspace = true # Async futures.workspace = true diff --git a/zingo-sync/src/keys.rs b/zingo-sync/src/keys.rs index 4bfb56e95a..dc39a033d9 100644 --- a/zingo-sync/src/keys.rs +++ b/zingo-sync/src/keys.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use getset::Getters; use incrementalmerkletree::Position; use orchard::{ - keys::{FullViewingKey, IncomingViewingKey, Scope}, + keys::{FullViewingKey, IncomingViewingKey}, note_encryption::OrchardDomain, }; use sapling_crypto::{ @@ -14,6 +14,7 @@ use sapling_crypto::{ use zcash_keys::keys::UnifiedFullViewingKey; use zcash_note_encryption::Domain; use zcash_primitives::zip32::AccountId; +use zip32::Scope; /// Child index for the `address_index` path level in the BIP44 hierarchy. pub type AddressIndex = u32; @@ -90,7 +91,7 @@ pub enum TransparentScope { } /// A key that can be used to perform trial decryption and nullifier -/// computation for a [`CompactSaplingOutput`] or [`CompactOrchardAction`]. +/// computation for a CompactSaplingOutput or CompactOrchardAction. pub trait ScanningKeyOps { /// Prepare the key for use in batch trial decryption. fn prepare(&self) -> D::IncomingViewingKey; From 3d0a36e7326fbe6931841cb817de6bf7a94d45e3 Mon Sep 17 00:00:00 2001 From: Oscar Pepper Date: Tue, 3 Dec 2024 02:15:10 +0000 Subject: [PATCH 3/3] fixed sync trait --- zingolib/src/wallet.rs | 2 +- zingolib/src/wallet/sync.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zingolib/src/wallet.rs b/zingolib/src/wallet.rs index ced02a144f..40a08fb09a 100644 --- a/zingolib/src/wallet.rs +++ b/zingolib/src/wallet.rs @@ -239,7 +239,7 @@ pub struct LightWallet { /// Transparent addresses #[cfg(feature = "sync")] - transparent_addresses: BTreeMap, + pub transparent_addresses: BTreeMap, } impl LightWallet { diff --git a/zingolib/src/wallet/sync.rs b/zingolib/src/wallet/sync.rs index 397b3cbec8..dddf20797b 100644 --- a/zingolib/src/wallet/sync.rs +++ b/zingolib/src/wallet/sync.rs @@ -58,13 +58,13 @@ impl SyncWallet for LightWallet { fn get_transparent_addresses( &self, ) -> Result<&BTreeMap, Self::Error> { - Ok(self.transparent_addresses()) + Ok(&self.transparent_addresses) } fn get_transparent_addresses_mut( &mut self, ) -> Result<&mut BTreeMap, Self::Error> { - Ok(self.transparent_addresses_mut()) + Ok(&mut self.transparent_addresses) } }