Skip to content

Commit

Permalink
zcash_client_backend: Remove unnecessary ReceivedNote::traverse_opt
Browse files Browse the repository at this point in the history
nuttycom committed Mar 13, 2024
1 parent b2597aa commit dd63a6e
Showing 3 changed files with 34 additions and 30 deletions.
2 changes: 2 additions & 0 deletions zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 7 additions & 11 deletions zcash_client_backend/src/data_api/wallet/input_selection.rs
Original file line number Diff line number Diff line change
@@ -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::<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[..],
44 changes: 25 additions & 19 deletions zcash_client_backend/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit dd63a6e

Please sign in to comment.