Skip to content

Commit fea8eed

Browse files
committed
feat(esplora)!: depend on bdk_core instead of bdk_chain
Helper methods have been changed to use concrete types (instead of `A: Anchor` generic) - since `Anchor` is still part of `bdk_chain`. Also fix esplora docs.
1 parent 0d302f5 commit fea8eed

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

crates/esplora/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ readme = "README.md"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
bdk_chain = { path = "../chain", version = "0.17.0", default-features = false }
15+
bdk_core = { path = "../core", version = "0.1", default-features = false }
1616
esplora-client = { version = "0.9.0", default-features = false }
1717
async-trait = { version = "0.1.66", optional = true }
1818
futures = { version = "0.3.26", optional = true }
1919
miniscript = { version = "12.0.0", optional = true, default-features = false }
2020

2121
[dev-dependencies]
22+
bdk_chain = { path = "../chain", version = "0.17.0" }
2223
bdk_testenv = { path = "../testenv", default-features = false }
2324
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
2425

crates/esplora/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ For full examples, refer to [`example-crates/wallet_esplora_blocking`](https://g
3737
[`bdk_chain`]: https://docs.rs/bdk-chain/
3838
[`EsploraExt`]: crate::EsploraExt
3939
[`EsploraAsyncExt`]: crate::EsploraAsyncExt
40-
[`SyncRequest`]: bdk_chain::spk_client::SyncRequest
41-
[`FullScanRequest`]: bdk_chain::spk_client::FullScanRequest
40+
[`SyncRequest`]: bdk_core::spk_client::SyncRequest
41+
[`FullScanRequest`]: bdk_core::spk_client::FullScanRequest
4242
[`sync`]: crate::EsploraExt::sync
4343
[`full_scan`]: crate::EsploraExt::full_scan

crates/esplora/src/async_ext.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
use std::collections::{BTreeSet, HashSet};
2-
31
use async_trait::async_trait;
4-
use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
5-
use bdk_chain::{
2+
use bdk_core::collections::{BTreeMap, BTreeSet, HashSet};
3+
use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
4+
use bdk_core::{
65
bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
7-
collections::BTreeMap,
8-
local_chain::CheckPoint,
9-
BlockId, ConfirmationBlockTime,
6+
tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed,
107
};
11-
use bdk_chain::{tx_graph, Anchor, Indexed};
128
use futures::{stream::FuturesOrdered, TryStreamExt};
139

1410
use crate::{insert_anchor_from_status, insert_prevouts};
@@ -209,11 +205,11 @@ async fn fetch_block(
209205
///
210206
/// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
211207
/// should not surpass `latest_blocks`.
212-
async fn chain_update<A: Anchor>(
208+
async fn chain_update(
213209
client: &esplora_client::AsyncClient,
214210
latest_blocks: &BTreeMap<u32, BlockHash>,
215211
local_tip: &CheckPoint,
216-
anchors: &BTreeSet<(A, Txid)>,
212+
anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>,
217213
) -> Result<CheckPoint, Error> {
218214
let mut point_of_agreement = None;
219215
let mut conflicts = vec![];
@@ -242,8 +238,8 @@ async fn chain_update<A: Anchor>(
242238
.extend(conflicts.into_iter().rev())
243239
.expect("evicted are in order");
244240

245-
for anchor in anchors {
246-
let height = anchor.0.anchor_block().height;
241+
for (anchor, _txid) in anchors {
242+
let height = anchor.block_id.height;
247243
if tip.get(height).is_none() {
248244
let hash = match fetch_block(client, latest_blocks, height).await? {
249245
Some(hash) => hash,
@@ -494,6 +490,7 @@ mod test {
494490
local_chain::LocalChain,
495491
BlockId,
496492
};
493+
use bdk_core::ConfirmationBlockTime;
497494
use bdk_testenv::{anyhow, bitcoincore_rpc::RpcApi, TestEnv};
498495
use esplora_client::Builder;
499496

@@ -572,9 +569,12 @@ mod test {
572569
.iter()
573570
.map(|&height| -> anyhow::Result<_> {
574571
Ok((
575-
BlockId {
576-
height,
577-
hash: env.bitcoind.client.get_block_hash(height as _)?,
572+
ConfirmationBlockTime {
573+
block_id: BlockId {
574+
height,
575+
hash: env.bitcoind.client.get_block_hash(height as _)?,
576+
},
577+
confirmation_time: height as _,
578578
},
579579
Txid::all_zeros(),
580580
))
@@ -610,9 +610,12 @@ mod test {
610610
.iter()
611611
.map(|&(height, txid)| -> anyhow::Result<_> {
612612
Ok((
613-
BlockId {
614-
height,
615-
hash: env.bitcoind.client.get_block_hash(height as _)?,
613+
ConfirmationBlockTime {
614+
block_id: BlockId {
615+
height,
616+
hash: env.bitcoind.client.get_block_hash(height as _)?,
617+
},
618+
confirmation_time: height as _,
616619
},
617620
txid,
618621
))

crates/esplora/src/blocking_ext.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use std::collections::{BTreeSet, HashSet};
2-
use std::thread::JoinHandle;
3-
4-
use bdk_chain::collections::BTreeMap;
5-
use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
6-
use bdk_chain::{
1+
use bdk_core::collections::{BTreeMap, BTreeSet, HashSet};
2+
use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
3+
use bdk_core::{
74
bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
8-
local_chain::CheckPoint,
9-
BlockId, ConfirmationBlockTime,
5+
tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed,
106
};
11-
use bdk_chain::{tx_graph, Anchor, Indexed};
127
use esplora_client::{OutputStatus, Tx};
8+
use std::thread::JoinHandle;
139

1410
use crate::{insert_anchor_from_status, insert_prevouts};
1511

@@ -199,11 +195,11 @@ fn fetch_block(
199195
///
200196
/// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
201197
/// should not surpass `latest_blocks`.
202-
fn chain_update<A: Anchor>(
198+
fn chain_update(
203199
client: &esplora_client::BlockingClient,
204200
latest_blocks: &BTreeMap<u32, BlockHash>,
205201
local_tip: &CheckPoint,
206-
anchors: &BTreeSet<(A, Txid)>,
202+
anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>,
207203
) -> Result<CheckPoint, Error> {
208204
let mut point_of_agreement = None;
209205
let mut conflicts = vec![];
@@ -232,8 +228,8 @@ fn chain_update<A: Anchor>(
232228
.extend(conflicts.into_iter().rev())
233229
.expect("evicted are in order");
234230

235-
for anchor in anchors {
236-
let height = anchor.0.anchor_block().height;
231+
for (anchor, _) in anchors {
232+
let height = anchor.block_id.height;
237233
if tip.get(height).is_none() {
238234
let hash = match fetch_block(client, latest_blocks, height)? {
239235
Some(hash) => hash,
@@ -475,6 +471,7 @@ mod test {
475471
use bdk_chain::bitcoin::Txid;
476472
use bdk_chain::local_chain::LocalChain;
477473
use bdk_chain::BlockId;
474+
use bdk_core::ConfirmationBlockTime;
478475
use bdk_testenv::{anyhow, bitcoincore_rpc::RpcApi, TestEnv};
479476
use esplora_client::{BlockHash, Builder};
480477
use std::collections::{BTreeMap, BTreeSet};
@@ -561,9 +558,12 @@ mod test {
561558
.iter()
562559
.map(|&height| -> anyhow::Result<_> {
563560
Ok((
564-
BlockId {
565-
height,
566-
hash: env.bitcoind.client.get_block_hash(height as _)?,
561+
ConfirmationBlockTime {
562+
block_id: BlockId {
563+
height,
564+
hash: env.bitcoind.client.get_block_hash(height as _)?,
565+
},
566+
confirmation_time: height as _,
567567
},
568568
Txid::all_zeros(),
569569
))
@@ -598,9 +598,12 @@ mod test {
598598
.iter()
599599
.map(|&(height, txid)| -> anyhow::Result<_> {
600600
Ok((
601-
BlockId {
602-
height,
603-
hash: env.bitcoind.client.get_block_hash(height as _)?,
601+
ConfirmationBlockTime {
602+
block_id: BlockId {
603+
height,
604+
hash: env.bitcoind.client.get_block_hash(height as _)?,
605+
},
606+
confirmation_time: height as _,
604607
},
605608
txid,
606609
))
@@ -794,9 +797,12 @@ mod test {
794797
let txid: Txid = bdk_chain::bitcoin::hashes::Hash::hash(
795798
&format!("txid_at_height_{}", h).into_bytes(),
796799
);
797-
let anchor = BlockId {
798-
height: h,
799-
hash: anchor_blockhash,
800+
let anchor = ConfirmationBlockTime {
801+
block_id: BlockId {
802+
height: h,
803+
hash: anchor_blockhash,
804+
},
805+
confirmation_time: h as _,
800806
};
801807
(anchor, txid)
802808
})

crates/esplora/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@
1919
//! Just like how [`EsploraExt`] extends the functionality of an
2020
//! [`esplora_client::BlockingClient`], [`EsploraAsyncExt`] is the async version which extends
2121
//! [`esplora_client::AsyncClient`].
22-
//!
23-
//! [`TxGraph`]: bdk_chain::tx_graph::TxGraph
24-
//! [`LocalChain`]: bdk_chain::local_chain::LocalChain
25-
//! [`ChainOracle`]: bdk_chain::ChainOracle
26-
//! [`example_esplora`]: https://github.com/bitcoindevkit/bdk/tree/master/example-crates/example_esplora
2722
28-
use bdk_chain::bitcoin::{Amount, OutPoint, TxOut, Txid};
29-
use bdk_chain::{tx_graph, BlockId, ConfirmationBlockTime};
23+
use bdk_core::bitcoin::{Amount, OutPoint, TxOut, Txid};
24+
use bdk_core::{tx_graph, BlockId, ConfirmationBlockTime};
3025
use esplora_client::TxStatus;
3126

3227
pub use esplora_client;

0 commit comments

Comments
 (0)