Skip to content

Commit

Permalink
collected value_ref_pairs for note_selection
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidvanadium committed Mar 22, 2024
1 parent 1b9832d commit 7c0f689
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
38 changes: 38 additions & 0 deletions zingo-status/src/confirmation_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,44 @@ impl ConfirmationStatus {
_ => false,
}
}
/// To return true, the status must be confirmed earlier than specified height.
/// # Examples
///
/// ```
/// use zingo_status::confirmation_status::ConfirmationStatus;
/// use zcash_primitives::consensus::BlockHeight;
///
/// let status = ConfirmationStatus::Confirmed(10.into());
/// assert_eq!(status.is_confirmed_before(&8.into()), false);
///
/// let status = ConfirmationStatus::Confirmed(10.into());
/// assert_eq!(status.is_confirmed_before(&10.into()), false);
///
/// let status = ConfirmationStatus::Confirmed(10.into());
/// assert_eq!(status.is_confirmed_before(&12.into()), true);
/// ```
pub fn is_confirmed_before(&self, comparison_height: &BlockHeight) -> bool {
match self {
Self::Confirmed(self_height) => self_height <= comparison_height,
_ => false,
}
}
/// To return true, the status must have broadcast at or later than specified height.
/// # Examples
///
/// ```
/// use zingo_status::confirmation_status::ConfirmationStatus;
/// use zcash_primitives::consensus::BlockHeight;
///
/// let status = ConfirmationStatus::Confirmed(10.into());
/// assert_eq!(status.is_broadcast_after_or_at(&8.into()), false);
///
/// let status = ConfirmationStatus::Broadcast(10.into());
/// assert_eq!(status.is_broadcast_after_or_at(&10.into()), true);
///
/// let status = ConfirmationStatus::Broadcast(10.into());
/// assert_eq!(status.is_broadcast_after_or_at(&12.into()), false);
/// ```
pub fn is_broadcast_after_or_at(&self, comparison_height: &BlockHeight) -> bool {
match self {
Self::Broadcast(self_height) => self_height >= comparison_height,
Expand Down
22 changes: 18 additions & 4 deletions zingolib/src/wallet/record_book/trait_inputsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sapling_crypto::note_encryption::SaplingDomain;
use zcash_client_backend::{data_api::InputSource, ShieldedProtocol};
use zcash_primitives::zip32::AccountId;

use crate::error::ZingoLibError;
use crate::{error::ZingoLibError, wallet::transaction_record};

use super::{NoteRecordReference, RecordBook};

Expand Down Expand Up @@ -56,12 +56,26 @@ impl InputSource for RecordBook<'_> {
return Err(ZingoLibError::UnknownError);
}
let mut value_ref_pairs: BTreeMap<u64, NoteRecordReference> = BTreeMap::new();
for transaction_record in self.all_transactions.values() {
for transaction_record in self.all_transactions.values().filter(|transaction_record| {
transaction_record
.status
.is_confirmed_before_or_at(&anchor_height)
}) {
if sources.contains(&ShieldedProtocol::Sapling) {
value_ref_pairs.extend(transaction_record.select_value_ref_pairs_sapling());
value_ref_pairs.extend(
transaction_record
.select_value_ref_pairs_sapling()
.into_iter()
.filter(|value_ref_pair| !exclude.contains(&value_ref_pair.1)),
);
}
if sources.contains(&ShieldedProtocol::Orchard) {
value_ref_pairs.extend(transaction_record.select_value_ref_pairs_orchard());
value_ref_pairs.extend(
transaction_record
.select_value_ref_pairs_orchard()
.into_iter()
.filter(|value_ref_pair| !exclude.contains(&value_ref_pair.1)),
);
}
}
let mut noteset: Vec<
Expand Down

0 comments on commit 7c0f689

Please sign in to comment.