]> Untitled Git - bdk/commitdiff
fix(core): generalize is_empty for SyncResponse and FullScanResponse and derive Clone...
authorbhuvan-somisetty <somisettybhuvan5@gmail.com>
Tue, 20 Oct 2026 20:07:26 +0000 (01:37 +0530)
committerbhuvan-somisetty <somisettybhuvan5@gmail.com>
Wed, 21 Oct 2026 09:38:09 +0000 (15:08 +0530)
Make `SyncResponse::is_empty` and `FullScanResponse::is_empty` generic
over all checkpoint data types `D`. Also derive `Clone` and `PartialEq`
on `SyncResponse`, `FullScanResponse`, and `TxUpdate`.

Fixes #2416

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
crates/core/src/spk_client.rs
crates/core/src/tx_update.rs
crates/core/tests/test_spk_client.rs

index 76d8a4e1a06615104fc228c3bc0f32f3ba855c9a..36cc076e261b040457e662b48b0748c51ce78799 100644 (file)
@@ -446,7 +446,7 @@ impl<I, D> SyncRequest<I, D> {
 ///
 /// See also [`SyncRequest`].
 #[must_use]
-#[derive(Debug)]
+#[derive(Debug, Clone, PartialEq)]
 pub struct SyncResponse<A = ConfirmationBlockTime, D = BlockHash> {
     /// Relevant transaction data discovered during the scan.
     pub tx_update: crate::TxUpdate<A>,
@@ -463,7 +463,7 @@ impl<A, D> Default for SyncResponse<A, D> {
     }
 }
 
-impl<A> SyncResponse<A> {
+impl<A, D> SyncResponse<A, D> {
     /// Returns true if the `SyncResponse` is empty.
     pub fn is_empty(&self) -> bool {
         self.tx_update.is_empty() && self.chain_update.is_none()
@@ -629,7 +629,7 @@ impl<K: Ord + Clone, D> FullScanRequest<K, D> {
 ///
 /// See also [`FullScanRequest`].
 #[must_use]
-#[derive(Debug)]
+#[derive(Debug, Clone, PartialEq)]
 pub struct FullScanResponse<K, A = ConfirmationBlockTime, D = BlockHash> {
     /// Relevant transaction data discovered during the scan.
     pub tx_update: crate::TxUpdate<A>,
@@ -650,7 +650,7 @@ impl<K, A, D> Default for FullScanResponse<K, A, D> {
     }
 }
 
-impl<K, A> FullScanResponse<K, A> {
+impl<K, A, D> FullScanResponse<K, A, D> {
     /// Returns true if the `FullScanResponse` is empty.
     pub fn is_empty(&self) -> bool {
         self.tx_update.is_empty()
index f92cf3e92bc0c6f5301e32b7d31db7a07686e58f..bf4afed2494d544c1ee62afab62f7ed5eb5a6867 100644 (file)
@@ -25,7 +25,7 @@ use bitcoin::{OutPoint, Transaction, TxOut, Txid};
 ///
 /// The built-in chain-source crates (`bdk_electrum`, `bdk_esplora`, `bdk_bitcoind_rpc`) handle this
 /// automatically. Transactions lacking temporal context are stored but ignored by canonicalization.
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq)]
 #[non_exhaustive]
 pub struct TxUpdate<A = ()> {
     /// Full transactions. These are transactions that were determined to be relevant to the wallet
index e65a3c63ab6c5f6b258d65c485548ac96207d1ce..0d147e32d0af60b4d202a8c0dccafdfa182041c6 100644 (file)
@@ -12,6 +12,15 @@ fn test_empty() {
         SyncResponse::<()>::default().is_empty(),
         "Default `SyncResponse` must be empty"
     );
+    // Custom checkpoint data type `D` must also support `is_empty()`
+    assert!(
+        FullScanResponse::<(), (), ()>::default().is_empty(),
+        "Default `FullScanResponse` with custom checkpoint type must be empty"
+    );
+    assert!(
+        SyncResponse::<(), ()>::default().is_empty(),
+        "Default `SyncResponse` with custom checkpoint type must be empty"
+    );
 }
 
 #[test]