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
- `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

View File

@ -404,12 +404,10 @@ where
&shielded_inputs
.iter()
.cloned()
.filter_map(|i| {
i.traverse_opt(|wn| match wn {
Note::Sapling(n) => Some(n),
.filter_map(|i| match i.note() {
Note::Sapling(n) => Some((*i.internal_note_id(), n.value())),
#[cfg(feature = "orchard")]
_ => None,
})
Note::Orchard(_) => None,
})
.collect::<Vec<_>>()[..],
&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::<Vec<_>>()[..],
&orchard_outputs[..],

View File

@ -430,26 +430,18 @@ impl<NoteRef, NoteT> ReceivedNote<NoteRef, NoteT> {
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<NoteRef, _>` for `t` and `Option<_>` for `f`.
pub fn traverse_opt<B>(
self,
f: impl FnOnce(NoteT) -> Option<B>,
) -> 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,
})
impl<'a, NoteRef> sapling_fees::InputView<NoteRef> 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<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")]
impl<NoteRef> orchard_fees::InputView<NoteRef> for ReceivedNote<NoteRef, orchard::Note> {
fn note_id(&self) -> &NoteRef {