From c30c36243a6fc9ea071755fd8c8e34d4f4cd8e22 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Feb 2024 17:41:45 -0700 Subject: [PATCH] zcash_client_backend: Factor out a common type from `WalletSaplingOutput` and `WalletOrchardOutput`. --- zcash_client_backend/CHANGELOG.md | 3 +- zcash_client_backend/src/wallet.rs | 94 ++++++------------------------ 2 files changed, 19 insertions(+), 78 deletions(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 6486e8142..16b865f06 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -71,7 +71,8 @@ and this library adheres to Rust's notion of - `Note` - `ReceivedNote` - `Recipient::{map_internal_account, internal_account_transpose_option}` - - `WalletSaplingOutput::recipient_key_scope` + - `WalletOutput` + - `WalletSaplingOutput::key_source` - `WalletOrchardOutput` behind the `orchard` feature flag. - `WalletSpend` - `WalletTx::{orchard_spends, orchard_outputs}` behind the `orchard` feature flag. diff --git a/zcash_client_backend/src/wallet.rs b/zcash_client_backend/src/wallet.rs index 6ba138244..24ea12b2e 100644 --- a/zcash_client_backend/src/wallet.rs +++ b/zcash_client_backend/src/wallet.rs @@ -272,29 +272,27 @@ impl KeySource { } } -/// A subset of an [`OutputDescription`] relevant to wallets and light clients. -/// -/// [`OutputDescription`]: sapling::bundle::OutputDescription -pub struct WalletSaplingOutput { +/// An output that was successfully decrypted in the process of wallet scanning. +pub struct WalletOutput { index: usize, ephemeral_key: EphemeralKeyBytes, - note: sapling::Note, + note: Note, is_change: bool, note_commitment_tree_position: Position, - nf: Option, + nf: Option, key_source: KeySource, } -impl WalletSaplingOutput { +impl WalletOutput { /// Constructs a new `WalletSaplingOutput` value from its constituent parts. #[allow(clippy::too_many_arguments)] pub fn from_parts( index: usize, ephemeral_key: EphemeralKeyBytes, - note: sapling::Note, + note: Note, is_change: bool, note_commitment_tree_position: Position, - nf: Option, + nf: Option, key_source: KeySource, ) -> Self { Self { @@ -308,16 +306,16 @@ impl WalletSaplingOutput { } } - /// The index of the output in the transaction that created this output. + /// The index of the output or action in the transaction that created this output. pub fn index(&self) -> usize { self.index } - /// The [`EphemeralKeyBytes`] of the transaction output. + /// The [`EphemeralKeyBytes`] value of the transaction output. pub fn ephemeral_key(&self) -> &EphemeralKeyBytes { &self.ephemeral_key } /// The note. - pub fn note(&self) -> &sapling::Note { + pub fn note(&self) -> &Note { &self.note } /// A flag indicating whether the process of note decryption determined that this @@ -325,12 +323,12 @@ impl WalletSaplingOutput { pub fn is_change(&self) -> bool { self.is_change } - /// The position of the note in the global Sapling note commitment tree. + /// The position of the note in the global note commitment tree. pub fn note_commitment_tree_position(&self) -> Position { self.note_commitment_tree_position } /// The nullifier for the note, if the key used to decrypt the note was able to compute it. - pub fn nf(&self) -> Option<&sapling::Nullifier> { + pub fn nf(&self) -> Option<&Nullifier> { self.nf.as_ref() } /// Source metadata for the key that decrypted this note. @@ -339,74 +337,16 @@ impl WalletSaplingOutput { } } -#[cfg(feature = "orchard")] -pub struct WalletOrchardOutput { - index: usize, - ephemeral_key: EphemeralKeyBytes, - note: orchard::note::Note, - is_change: bool, - note_commitment_tree_position: Position, - nf: Option, - key_source: KeySource, -} +/// A subset of an [`OutputDescription`] relevant to wallets and light clients. +/// +/// [`OutputDescription`]: sapling::bundle::OutputDescription +pub type WalletSaplingOutput = WalletOutput; /// The output part of an Orchard [`Action`] that was decrypted in the process of scanning. /// /// [`Action`]: orchard::Action #[cfg(feature = "orchard")] -impl WalletOrchardOutput { - /// Constructs a new `WalletOrchardOutput` value from its constituent parts. - #[allow(clippy::too_many_arguments)] - pub fn from_parts( - index: usize, - ephemeral_key: EphemeralKeyBytes, - note: orchard::note::Note, - is_change: bool, - note_commitment_tree_position: Position, - nf: Option, - key_source: KeySource, - ) -> Self { - Self { - index, - ephemeral_key, - note, - is_change, - note_commitment_tree_position, - nf, - key_source, - } - } - - /// The index of the Orchard action in the transaction that created this output. - pub fn index(&self) -> usize { - self.index - } - /// The [`EphemeralKeyBytes`] of the transaction output. - pub fn ephemeral_key(&self) -> &EphemeralKeyBytes { - &self.ephemeral_key - } - /// The note. - pub fn note(&self) -> &orchard::note::Note { - &self.note - } - /// A flag indicating whether the process of note decryption determined that this - /// output should be classified as change. - pub fn is_change(&self) -> bool { - self.is_change - } - /// The position of the note in the global Orchard note commitment tree. - pub fn note_commitment_tree_position(&self) -> Position { - self.note_commitment_tree_position - } - /// The nullifier for the note, if the key used to decrypt the note was able to compute it. - pub fn nf(&self) -> Option<&orchard::note::Nullifier> { - self.nf.as_ref() - } - /// Source metadata for the key that decrypted this note. - pub fn key_source(&self) -> KeySource { - self.key_source - } -} +pub type WalletOrchardOutput = WalletOutput; /// An enumeration of supported shielded note types for use in [`ReceivedNote`] #[derive(Debug, Clone, PartialEq, Eq)]