diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 7aa804d5f..236c3fb8d 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -95,6 +95,8 @@ and this library adheres to Rust's notion of ### Removed - `zcash_client_backend::PoolType::is_receiver`: use `zcash_keys::Address::has_receiver` instead. +- `zcash_client_backend::wallet::ReceivedNote::traverse_opt` removed as + unnecessary. ### Fixed - This release fixes an error in amount parsing in `zip321` that previously diff --git a/zcash_client_backend/src/data_api/wallet/input_selection.rs b/zcash_client_backend/src/data_api/wallet/input_selection.rs index 8467407cf..104c78a6c 100644 --- a/zcash_client_backend/src/data_api/wallet/input_selection.rs +++ b/zcash_client_backend/src/data_api/wallet/input_selection.rs @@ -404,12 +404,10 @@ where &shielded_inputs .iter() .cloned() - .filter_map(|i| { - i.traverse_opt(|wn| match wn { - Note::Sapling(n) => Some(n), - #[cfg(feature = "orchard")] - _ => None, - }) + .filter_map(|i| match i.note() { + Note::Sapling(n) => Some((*i.internal_note_id(), n.value())), + #[cfg(feature = "orchard")] + Note::Orchard(_) => None, }) .collect::>()[..], &sapling_outputs[..], @@ -419,11 +417,9 @@ where ::orchard::builder::BundleType::DEFAULT, &shielded_inputs .iter() - .filter_map(|i| { - i.clone().traverse_opt(|wn| match wn { - Note::Orchard(n) => Some(n), - _ => None, - }) + .filter_map(|i| match i.note() { + Note::Sapling(_) => None, + Note::Orchard(n) => Some((*i.internal_note_id(), n.value())), }) .collect::>()[..], &orchard_outputs[..], diff --git a/zcash_client_backend/src/wallet.rs b/zcash_client_backend/src/wallet.rs index c65103a2e..5e65ddd0d 100644 --- a/zcash_client_backend/src/wallet.rs +++ b/zcash_client_backend/src/wallet.rs @@ -430,26 +430,18 @@ impl ReceivedNote { pub fn note_commitment_tree_position(&self) -> Position { self.note_commitment_tree_position } +} - /// Applies the given function to the `note` field of this ReceivedNote and returns - /// `None` if that function returns `None`, or otherwise a `Some` containing - /// a `ReceivedNote` with its `note` field swapped out for the result of the function. - /// - /// The name `traverse` refers to the general operation that has the Haskell type - /// `Applicative f => (a -> f b) -> t a -> f (t b)`, that this method specializes - /// with `ReceivedNote` for `t` and `Option<_>` for `f`. - pub fn traverse_opt( - self, - f: impl FnOnce(NoteT) -> Option, - ) -> Option> { - f(self.note).map(|n0| ReceivedNote { - note_id: self.note_id, - txid: self.txid, - output_index: self.output_index, - note: n0, - spending_key_scope: self.spending_key_scope, - note_commitment_tree_position: self.note_commitment_tree_position, - }) +impl<'a, NoteRef> sapling_fees::InputView for (NoteRef, sapling::value::NoteValue) { + fn note_id(&self) -> &NoteRef { + &self.0 + } + + fn value(&self) -> NonNegativeAmount { + self.1 + .inner() + .try_into() + .expect("Sapling note values are indirectly checked by consensus.") } } @@ -467,6 +459,20 @@ impl sapling_fees::InputView for ReceivedNote orchard_fees::InputView for (NoteRef, orchard::value::NoteValue) { + fn note_id(&self) -> &NoteRef { + &self.0 + } + + fn value(&self) -> NonNegativeAmount { + self.1 + .inner() + .try_into() + .expect("Orchard note values are indirectly checked by consensus.") + } +} + #[cfg(feature = "orchard")] impl orchard_fees::InputView for ReceivedNote { fn note_id(&self) -> &NoteRef {