zcash_client_backend: Remove unnecessary `ReceivedNote::traverse_opt`

This commit is contained in:
Kris Nuttycombe 2024-03-13 13:57:34 -06:00
parent b2597aa952
commit dd63a6e3dd
3 changed files with 34 additions and 30 deletions

View File

@ -95,6 +95,8 @@ and this library adheres to Rust's notion of
### Removed ### Removed
- `zcash_client_backend::PoolType::is_receiver`: use - `zcash_client_backend::PoolType::is_receiver`: use
`zcash_keys::Address::has_receiver` instead. `zcash_keys::Address::has_receiver` instead.
- `zcash_client_backend::wallet::ReceivedNote::traverse_opt` removed as
unnecessary.
### Fixed ### Fixed
- This release fixes an error in amount parsing in `zip321` that previously - This release fixes an error in amount parsing in `zip321` that previously

View File

@ -404,12 +404,10 @@ where
&shielded_inputs &shielded_inputs
.iter() .iter()
.cloned() .cloned()
.filter_map(|i| { .filter_map(|i| match i.note() {
i.traverse_opt(|wn| match wn { Note::Sapling(n) => Some((*i.internal_note_id(), n.value())),
Note::Sapling(n) => Some(n), #[cfg(feature = "orchard")]
#[cfg(feature = "orchard")] Note::Orchard(_) => None,
_ => None,
})
}) })
.collect::<Vec<_>>()[..], .collect::<Vec<_>>()[..],
&sapling_outputs[..], &sapling_outputs[..],
@ -419,11 +417,9 @@ where
::orchard::builder::BundleType::DEFAULT, ::orchard::builder::BundleType::DEFAULT,
&shielded_inputs &shielded_inputs
.iter() .iter()
.filter_map(|i| { .filter_map(|i| match i.note() {
i.clone().traverse_opt(|wn| match wn { Note::Sapling(_) => None,
Note::Orchard(n) => Some(n), Note::Orchard(n) => Some((*i.internal_note_id(), n.value())),
_ => None,
})
}) })
.collect::<Vec<_>>()[..], .collect::<Vec<_>>()[..],
&orchard_outputs[..], &orchard_outputs[..],

View File

@ -430,26 +430,18 @@ impl<NoteRef, NoteT> ReceivedNote<NoteRef, NoteT> {
pub fn note_commitment_tree_position(&self) -> Position { pub fn note_commitment_tree_position(&self) -> Position {
self.note_commitment_tree_position self.note_commitment_tree_position
} }
}
/// Applies the given function to the `note` field of this ReceivedNote and returns impl<'a, NoteRef> sapling_fees::InputView<NoteRef> for (NoteRef, sapling::value::NoteValue) {
/// `None` if that function returns `None`, or otherwise a `Some` containing fn note_id(&self) -> &NoteRef {
/// a `ReceivedNote` with its `note` field swapped out for the result of the function. &self.0
/// }
/// 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 fn value(&self) -> NonNegativeAmount {
/// with `ReceivedNote<NoteRef, _>` for `t` and `Option<_>` for `f`. self.1
pub fn traverse_opt<B>( .inner()
self, .try_into()
f: impl FnOnce(NoteT) -> Option<B>, .expect("Sapling note values are indirectly checked by consensus.")
) -> Option<ReceivedNote<NoteRef, B>> {
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,
})
} }
} }
@ -467,6 +459,20 @@ impl<NoteRef> sapling_fees::InputView<NoteRef> for ReceivedNote<NoteRef, sapling
} }
} }
#[cfg(feature = "orchard")]
impl<'a, NoteRef> orchard_fees::InputView<NoteRef> 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")] #[cfg(feature = "orchard")]
impl<NoteRef> orchard_fees::InputView<NoteRef> for ReceivedNote<NoteRef, orchard::Note> { impl<NoteRef> orchard_fees::InputView<NoteRef> for ReceivedNote<NoteRef, orchard::Note> {
fn note_id(&self) -> &NoteRef { fn note_id(&self) -> &NoteRef {