diff --git a/zingo-status/src/confirmation_status.rs b/zingo-status/src/confirmation_status.rs index 64ab4e667..8ea02e16d 100644 --- a/zingo-status/src/confirmation_status.rs +++ b/zingo-status/src/confirmation_status.rs @@ -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, diff --git a/zingolib/src/wallet/record_book/trait_inputsource.rs b/zingolib/src/wallet/record_book/trait_inputsource.rs index f0123a51a..18038d6c6 100644 --- a/zingolib/src/wallet/record_book/trait_inputsource.rs +++ b/zingolib/src/wallet/record_book/trait_inputsource.rs @@ -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}; @@ -56,12 +56,26 @@ impl InputSource for RecordBook<'_> { return Err(ZingoLibError::UnknownError); } let mut value_ref_pairs: BTreeMap = 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<