Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/core/src/spk_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ impl<A> Default for SyncResponse<A> {
}
}

impl<A> SyncResponse<A> {
/// Returns true if the `SyncResponse` is empty.
pub fn is_empty(&self) -> bool {
self.tx_update.is_empty() && self.chain_update.is_none()
}
}

/// Builds a [`FullScanRequest`].
///
/// Construct with [`FullScanRequest::builder`].
Expand Down Expand Up @@ -560,6 +567,15 @@ impl<K, A> Default for FullScanResponse<K, A> {
}
}

impl<K, A> FullScanResponse<K, A> {
/// Returns true if the `FullScanResponse` is empty.
pub fn is_empty(&self) -> bool {
self.tx_update.is_empty()
&& self.last_active_indices.is_empty()
&& self.chain_update.is_none()
}
}

struct KeychainSpkIter<'r, K> {
keychain: K,
spks: Option<&'r mut Box<dyn Iterator<Item = Indexed<ScriptBuf>> + Send>>,
Expand Down
11 changes: 11 additions & 0 deletions crates/core/src/tx_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ impl<A> Default for TxUpdate<A> {
}
}

impl<A> TxUpdate<A> {
/// Returns true if the `TxUpdate` contains no elements in any of its fields.
pub fn is_empty(&self) -> bool {
self.txs.is_empty()
&& self.txouts.is_empty()
&& self.anchors.is_empty()
&& self.seen_ats.is_empty()
&& self.evicted_ats.is_empty()
}
}

impl<A: Ord> TxUpdate<A> {
/// Transforms the [`TxUpdate`] to have `anchors` (`A`) of another type (`A2`).
///
Expand Down
13 changes: 13 additions & 0 deletions crates/core/tests/test_spk_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use bdk_core::spk_client::{FullScanResponse, SyncResponse};

#[test]
fn test_empty() {
assert!(
FullScanResponse::<(), ()>::default().is_empty(),
"Default `FullScanResponse` must be empty"
);
assert!(
SyncResponse::<()>::default().is_empty(),
"Default `SyncResponse` must be empty"
);
}
9 changes: 9 additions & 0 deletions crates/core/tests/test_tx_update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use bdk_core::TxUpdate;

#[test]
fn test_empty() {
assert!(
TxUpdate::<()>::default().is_empty(),
"Default `TxUpdate` must be empty"
);
}
Loading