]> Untitled Git - bdk/commitdiff
chore(bdk-electrum): use new `batch_transaction_get_merkle` API
authorLeonardo Lima <oleonardolima@users.noreply.github.com>
Fri, 4 Jul 2025 18:46:03 +0000 (15:46 -0300)
committerLeonardo Lima <oleonardolima@users.noreply.github.com>
Sat, 2 Aug 2025 18:07:27 +0000 (15:07 -0300)
- removes the now unused `serde_json` dependency from `bdk_electrum`.
- update `batch_fetch_anchors` to use `batch_transaction_get_merkle`
  method instead of manually creating the batch call.

crates/electrum/Cargo.toml
crates/electrum/src/bdk_electrum_client.rs

index c09bfcbacdbc924cc723b8e3a5dd07211fa8f53e..c37eee642666de9e93014cc6442798a25eeb140f 100644 (file)
@@ -14,8 +14,7 @@ workspace = true
 
 [dependencies]
 bdk_core = { path = "../core", version = "0.6.0" }
-electrum-client = { version = "0.23.1", features = [ "proxy" ], default-features = false }
-serde_json = "1.0"
+electrum-client = { version = "0.24.0", features = [ "proxy" ], default-features = false }
 
 [dev-dependencies]
 bdk_testenv = { path = "../testenv" }
index d277c6f734f5dd77d2152ca5c62c0f3328aee4e9..f20feb2cd94d620461ed24351721a22035b34ea1 100644 (file)
@@ -506,23 +506,12 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             }
         }
 
-        // Batch all get_merkle calls.
-        let mut batch = electrum_client::Batch::default();
-        for &(txid, height, _) in &to_fetch {
-            batch.raw(
-                "blockchain.transaction.get_merkle".into(),
-                vec![
-                    electrum_client::Param::String(format!("{txid:x}")),
-                    electrum_client::Param::Usize(height),
-                ],
-            );
-        }
-        let resps = self.inner.batch_call(&batch)?;
+        // Fetch merkle proofs.
+        let txids_and_heights = to_fetch.iter().map(|&(txid, height, _)| (txid, height));
+        let proofs = self.inner.batch_transaction_get_merkle(txids_and_heights)?;
 
         // Validate each proof, retrying once for each stale header.
-        for ((txid, height, hash), resp) in to_fetch.into_iter().zip(resps.into_iter()) {
-            let proof: electrum_client::GetMerkleRes = serde_json::from_value(resp)?;
-
+        for ((txid, height, hash), proof) in to_fetch.into_iter().zip(proofs.into_iter()) {
             let mut header = {
                 let cache = self.block_header_cache.lock().unwrap();
                 cache