From 1b036f1e0df8e3f0cf2a07f0bfc5d5ff8bb827e4 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 5 Jan 2024 09:13:31 -0700 Subject: [PATCH] zcash_client_backend: rename `WalletNote` to `Note` --- zcash_client_backend/CHANGELOG.md | 2 +- zcash_client_backend/src/data_api/wallet.rs | 6 +++--- zcash_client_backend/src/wallet.rs | 14 +++++++------- zcash_client_sqlite/src/wallet/sapling.rs | 19 ++++++++++--------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 599b45902..2780788b2 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -29,7 +29,7 @@ and this library adheres to Rust's notion of functionality and move it behind the `transparent-inputs` feature flag. - `zcash_client_backend::fees::{standard, sapling}` - `zcash_client_backend::wallet`: - - `WalletNote` + - `Note` - `ReceivedNote` - `WalletSaplingOutput::recipient_key_scope` - `zcash_client_backend::zip321::TransactionRequest::total` diff --git a/zcash_client_backend/src/data_api/wallet.rs b/zcash_client_backend/src/data_api/wallet.rs index ab41f1cc7..24e10367c 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -26,7 +26,7 @@ use crate::{ decrypt_transaction, fees::{self, ChangeValue, DustOutputPolicy}, keys::UnifiedSpendingKey, - wallet::{OvkPolicy, Recipient, WalletNote}, + wallet::{Note, OvkPolicy, Recipient}, zip321::{self, Payment}, PoolType, ShieldedProtocol, }; @@ -586,7 +586,7 @@ where .iter() .map(|selected| { match selected.note() { - WalletNote::Sapling(note) => { + Note::Sapling(note) => { let key = match selected.spending_key_scope() { Scope::External => usk.sapling().clone(), Scope::Internal => usk.sapling().derive_internal(), @@ -600,7 +600,7 @@ where Ok((key, note, merkle_path)) } #[cfg(feature = "orchard")] - WalletNote::Orchard(_) => { + Note::Orchard(_) => { // FIXME: Implement this once `Proposal` has been refactored to // include Orchard notes. panic!("Orchard spends are not yet supported"); diff --git a/zcash_client_backend/src/wallet.rs b/zcash_client_backend/src/wallet.rs index 8e7242a65..dd5f71513 100644 --- a/zcash_client_backend/src/wallet.rs +++ b/zcash_client_backend/src/wallet.rs @@ -237,20 +237,20 @@ impl WalletSaplingOutput { /// An enumeration of supported shielded note types for use in [`ReceivedNote`] #[derive(Debug, Clone, PartialEq, Eq)] -pub enum WalletNote { +pub enum Note { Sapling(sapling::Note), #[cfg(feature = "orchard")] Orchard(orchard::Note), } -impl WalletNote { +impl Note { pub fn value(&self) -> NonNegativeAmount { match self { - WalletNote::Sapling(n) => n.value().try_into().expect( + Note::Sapling(n) => n.value().try_into().expect( "Sapling notes must have values in the range of valid non-negative ZEC values.", ), #[cfg(feature = "orchard")] - WalletNote::Orchard(n) => NonNegativeAmount::from_u64(n.value().inner()).expect( + Note::Orchard(n) => NonNegativeAmount::from_u64(n.value().inner()).expect( "Orchard notes must have values in the range of valid non-negative ZEC values.", ), } @@ -264,7 +264,7 @@ pub struct ReceivedNote { note_id: NoteRef, txid: TxId, output_index: u16, - note: WalletNote, + note: Note, spending_key_scope: Scope, note_commitment_tree_position: Position, } @@ -274,7 +274,7 @@ impl ReceivedNote { note_id: NoteRef, txid: TxId, output_index: u16, - note: WalletNote, + note: Note, spending_key_scope: Scope, note_commitment_tree_position: Position, ) -> Self { @@ -297,7 +297,7 @@ impl ReceivedNote { pub fn output_index(&self) -> u16 { self.output_index } - pub fn note(&self) -> &WalletNote { + pub fn note(&self) -> &Note { &self.note } pub fn value(&self) -> NonNegativeAmount { diff --git a/zcash_client_sqlite/src/wallet/sapling.rs b/zcash_client_sqlite/src/wallet/sapling.rs index 02b8972f4..825c4983a 100644 --- a/zcash_client_sqlite/src/wallet/sapling.rs +++ b/zcash_client_sqlite/src/wallet/sapling.rs @@ -5,7 +5,7 @@ use incrementalmerkletree::Position; use rusqlite::{named_params, params, types::Value, Connection, Row}; use std::rc::Rc; -use sapling::{Diversifier, Note, Nullifier, Rseed}; +use sapling::{self, Diversifier, Nullifier, Rseed}; use zcash_primitives::{ consensus::{self, BlockHeight}, memo::MemoBytes, @@ -18,7 +18,7 @@ use zcash_primitives::{ use zcash_client_backend::{ keys::UnifiedFullViewingKey, - wallet::{ReceivedNote, WalletNote, WalletSaplingOutput}, + wallet::{Note, ReceivedNote, WalletSaplingOutput}, DecryptedOutput, TransferType, }; @@ -30,7 +30,7 @@ use super::{memo_repr, parse_scope, scope_code, wallet_birthday}; pub(crate) trait ReceivedSaplingOutput { fn index(&self) -> usize; fn account(&self) -> AccountId; - fn note(&self) -> &Note; + fn note(&self) -> &sapling::Note; fn memo(&self) -> Option<&MemoBytes>; fn is_change(&self) -> bool; fn nullifier(&self) -> Option<&sapling::Nullifier>; @@ -45,7 +45,7 @@ impl ReceivedSaplingOutput for WalletSaplingOutput { fn account(&self) -> AccountId { WalletSaplingOutput::account(self) } - fn note(&self) -> &Note { + fn note(&self) -> &sapling::Note { WalletSaplingOutput::note(self) } fn memo(&self) -> Option<&MemoBytes> { @@ -66,14 +66,14 @@ impl ReceivedSaplingOutput for WalletSaplingOutput { } } -impl ReceivedSaplingOutput for DecryptedOutput { +impl ReceivedSaplingOutput for DecryptedOutput { fn index(&self) -> usize { self.index } fn account(&self) -> AccountId { self.account } - fn note(&self) -> &Note { + fn note(&self) -> &sapling::Note { &self.note } fn memo(&self) -> Option<&MemoBytes> { @@ -163,7 +163,7 @@ fn to_spendable_note( note_id, txid, output_index, - WalletNote::Sapling(sapling::Note::from_parts( + Note::Sapling(sapling::Note::from_parts( recipient, note_value.into(), rseed, @@ -471,10 +471,11 @@ pub(crate) mod tests { use zcash_proofs::prover::LocalTxProver; use sapling::{ + self, note_encryption::try_sapling_output_recovery, prover::{OutputProver, SpendProver}, zip32::ExtendedSpendingKey, - Node, Note, PaymentAddress, + Node, PaymentAddress, }; use zcash_primitives::{ block::BlockHash, @@ -1045,7 +1046,7 @@ pub(crate) mod tests { let send_and_recover_with_policy = |st: &mut TestState, ovk_policy| -> Result< - Option<(Note, PaymentAddress, MemoBytes)>, + Option<(sapling::Note, PaymentAddress, MemoBytes)>, Error< SqliteClientError, commitment_tree::Error,