From: bhuvan-somisetty Date: Tue, 20 Oct 2026 20:07:26 +0000 (+0530) Subject: fix(core): generalize is_empty for SyncResponse and FullScanResponse and derive Clone... X-Git-Url: http://internal-gitweb-vhost/-client-interface/%22https:/encode/struct.CommandStringError.html?a=commitdiff_plain;h=cb1deabcac7a1ad19742f117656ebc08bb14d2ab;p=bdk fix(core): generalize is_empty for SyncResponse and FullScanResponse and derive Clone, PartialEq 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 --- diff --git a/crates/core/src/spk_client.rs b/crates/core/src/spk_client.rs index 76d8a4e1..36cc076e 100644 --- a/crates/core/src/spk_client.rs +++ b/crates/core/src/spk_client.rs @@ -446,7 +446,7 @@ impl SyncRequest { /// /// See also [`SyncRequest`]. #[must_use] -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq)] pub struct SyncResponse { /// Relevant transaction data discovered during the scan. pub tx_update: crate::TxUpdate, @@ -463,7 +463,7 @@ impl Default for SyncResponse { } } -impl SyncResponse { +impl SyncResponse { /// 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 FullScanRequest { /// /// See also [`FullScanRequest`]. #[must_use] -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq)] pub struct FullScanResponse { /// Relevant transaction data discovered during the scan. pub tx_update: crate::TxUpdate, @@ -650,7 +650,7 @@ impl Default for FullScanResponse { } } -impl FullScanResponse { +impl FullScanResponse { /// Returns true if the `FullScanResponse` is empty. pub fn is_empty(&self) -> bool { self.tx_update.is_empty() diff --git a/crates/core/src/tx_update.rs b/crates/core/src/tx_update.rs index f92cf3e9..bf4afed2 100644 --- a/crates/core/src/tx_update.rs +++ b/crates/core/src/tx_update.rs @@ -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 { /// Full transactions. These are transactions that were determined to be relevant to the wallet diff --git a/crates/core/tests/test_spk_client.rs b/crates/core/tests/test_spk_client.rs index e65a3c63..0d147e32 100644 --- a/crates/core/tests/test_spk_client.rs +++ b/crates/core/tests/test_spk_client.rs @@ -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]