Skip to content

Commit befb094

Browse files
committed
chore(bdk-electrum): use new batch_transaction_get_merkle API
- FIXME: bump the electrum-client version used. - update `batch_fetch_anchors` to use `batch_transaction_get_merkle` method instead of manually creating the batch call.
1 parent c496cde commit befb094

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ authors = ["Bitcoin Dev Kit Developers"]
2020
[workspace.lints.clippy]
2121
print_stdout = "deny"
2222
print_stderr = "deny"
23+
24+
# FIXME: should be removed once the new API lands in electrum-client and a new release is done.
25+
[patch.crates-io]
26+
electrum-client = { git = "https://github.com/oleonardolima/rust-electrum-client.git", branch = "feat/add-batch-transaction-get-merkle" }

crates/electrum/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ workspace = true
1414

1515
[dependencies]
1616
bdk_core = { path = "../core", version = "0.6.0" }
17-
electrum-client = { version = "0.23.1", features = [ "proxy" ], default-features = false }
17+
electrum-client = { version = "0.23.1", features = [
18+
"proxy",
19+
], default-features = false }
1820
serde_json = "1.0"
1921

2022
[dev-dependencies]
@@ -35,3 +37,7 @@ required-features = ["use-rustls"]
3537
[[bench]]
3638
name = "test_sync"
3739
harness = false
40+
41+
# FIXME: should be removed once the new API lands in electrum-client and a new release is done.
42+
[patch.crates-io]
43+
electrum-client = { git = "https://github.com/oleonardolima/rust-electrum-client.git", rev = "2dfc299b7ab175e4a62f0797b8f69070415d2afc" }

crates/electrum/src/bdk_electrum_client.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -506,23 +506,17 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
506506
}
507507
}
508508

509-
// Batch all get_merkle calls.
510-
let mut batch = electrum_client::Batch::default();
511-
for &(txid, height, _) in &to_fetch {
512-
batch.raw(
513-
"blockchain.transaction.get_merkle".into(),
514-
vec![
515-
electrum_client::Param::String(format!("{:x}", txid)),
516-
electrum_client::Param::Usize(height),
517-
],
518-
);
519-
}
520-
let resps = self.inner.batch_call(&batch)?;
509+
// Fetch merkle proofs.
510+
let txids_and_heights: Vec<(Txid, usize)> = to_fetch
511+
.iter()
512+
.map(|element| (element.0, element.1))
513+
.collect();
514+
let proofs = self
515+
.inner
516+
.batch_transaction_get_merkle(&txids_and_heights)?;
521517

522518
// Validate each proof, retrying once for each stale header.
523-
for ((txid, height, hash), resp) in to_fetch.into_iter().zip(resps.into_iter()) {
524-
let proof: electrum_client::GetMerkleRes = serde_json::from_value(resp)?;
525-
519+
for ((txid, height, hash), proof) in to_fetch.into_iter().zip(proofs.into_iter()) {
526520
let mut header = {
527521
let cache = self.block_header_cache.lock().unwrap();
528522
cache

0 commit comments

Comments
 (0)