]> Untitled Git - bdk/commitdiff
feat(esplora)!: depend on `bdk_core` instead of `bdk_chain`
author志宇 <hello@evanlinjin.me>
Fri, 23 Aug 2024 18:36:07 +0000 (18:36 +0000)
committer志宇 <hello@evanlinjin.me>
Sat, 24 Aug 2024 16:20:37 +0000 (16:20 +0000)
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.

crates/esplora/Cargo.toml
crates/esplora/README.md
crates/esplora/src/async_ext.rs
crates/esplora/src/blocking_ext.rs
crates/esplora/src/lib.rs

index 9148a0f86f48ea4efad56cdce5c78297b7d48cb3..8e0cf046440a1228b56b08162a359e8eebc88307 100644 (file)
@@ -12,13 +12,14 @@ readme = "README.md"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-bdk_chain = { path = "../chain", version = "0.17.0", default-features = false }
+bdk_core = { path = "../core", version = "0.1", default-features = false }
 esplora-client = { version = "0.9.0", default-features = false }
 async-trait = { version = "0.1.66", optional = true }
 futures = { version = "0.3.26", optional = true }
 miniscript = { version = "12.0.0", optional = true, default-features = false }
 
 [dev-dependencies]
+bdk_chain = { path = "../chain", version = "0.17.0" }
 bdk_testenv = { path = "../testenv", default-features = false }
 tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
 
index ef2e65176065214cf0b399736ccf576f30c33b26..0535b9a385c21127d5f00ac1d0ac1f992826c7d7 100644 (file)
@@ -37,7 +37,7 @@ For full examples, refer to [`example-crates/wallet_esplora_blocking`](https://g
 [`bdk_chain`]: https://docs.rs/bdk-chain/
 [`EsploraExt`]: crate::EsploraExt
 [`EsploraAsyncExt`]: crate::EsploraAsyncExt
-[`SyncRequest`]: bdk_chain::spk_client::SyncRequest
-[`FullScanRequest`]: bdk_chain::spk_client::FullScanRequest
+[`SyncRequest`]: bdk_core::spk_client::SyncRequest
+[`FullScanRequest`]: bdk_core::spk_client::FullScanRequest
 [`sync`]: crate::EsploraExt::sync
 [`full_scan`]: crate::EsploraExt::full_scan
index f3c8e966aad782e1790ca0a0a55aff4cbd66a77b..041205c5e744a9586a97347d82bdfe8ca45808a3 100644 (file)
@@ -1,14 +1,10 @@
-use std::collections::{BTreeSet, HashSet};
-
 use async_trait::async_trait;
-use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
-use bdk_chain::{
+use bdk_core::collections::{BTreeMap, BTreeSet, HashSet};
+use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
+use bdk_core::{
     bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
-    collections::BTreeMap,
-    local_chain::CheckPoint,
-    BlockId, ConfirmationBlockTime,
+    tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed,
 };
-use bdk_chain::{tx_graph, Anchor, Indexed};
 use futures::{stream::FuturesOrdered, TryStreamExt};
 
 use crate::{insert_anchor_from_status, insert_prevouts};
@@ -209,11 +205,11 @@ async fn fetch_block(
 ///
 /// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
 /// should not surpass `latest_blocks`.
-async fn chain_update<A: Anchor>(
+async fn chain_update(
     client: &esplora_client::AsyncClient,
     latest_blocks: &BTreeMap<u32, BlockHash>,
     local_tip: &CheckPoint,
-    anchors: &BTreeSet<(A, Txid)>,
+    anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>,
 ) -> Result<CheckPoint, Error> {
     let mut point_of_agreement = None;
     let mut conflicts = vec![];
@@ -242,8 +238,8 @@ async fn chain_update<A: Anchor>(
         .extend(conflicts.into_iter().rev())
         .expect("evicted are in order");
 
-    for anchor in anchors {
-        let height = anchor.0.anchor_block().height;
+    for (anchor, _txid) in anchors {
+        let height = anchor.block_id.height;
         if tip.get(height).is_none() {
             let hash = match fetch_block(client, latest_blocks, height).await? {
                 Some(hash) => hash,
@@ -494,6 +490,7 @@ mod test {
         local_chain::LocalChain,
         BlockId,
     };
+    use bdk_core::ConfirmationBlockTime;
     use bdk_testenv::{anyhow, bitcoincore_rpc::RpcApi, TestEnv};
     use esplora_client::Builder;
 
@@ -572,9 +569,12 @@ mod test {
                     .iter()
                     .map(|&height| -> anyhow::Result<_> {
                         Ok((
-                            BlockId {
-                                height,
-                                hash: env.bitcoind.client.get_block_hash(height as _)?,
+                            ConfirmationBlockTime {
+                                block_id: BlockId {
+                                    height,
+                                    hash: env.bitcoind.client.get_block_hash(height as _)?,
+                                },
+                                confirmation_time: height as _,
                             },
                             Txid::all_zeros(),
                         ))
@@ -610,9 +610,12 @@ mod test {
                     .iter()
                     .map(|&(height, txid)| -> anyhow::Result<_> {
                         Ok((
-                            BlockId {
-                                height,
-                                hash: env.bitcoind.client.get_block_hash(height as _)?,
+                            ConfirmationBlockTime {
+                                block_id: BlockId {
+                                    height,
+                                    hash: env.bitcoind.client.get_block_hash(height as _)?,
+                                },
+                                confirmation_time: height as _,
                             },
                             txid,
                         ))
index 62f0d351eaf782677ec8ffd69b2d1af2098e84ba..d0744b4edd8c7cce8b2e00926d623b38c8feec9f 100644 (file)
@@ -1,15 +1,11 @@
-use std::collections::{BTreeSet, HashSet};
-use std::thread::JoinHandle;
-
-use bdk_chain::collections::BTreeMap;
-use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
-use bdk_chain::{
+use bdk_core::collections::{BTreeMap, BTreeSet, HashSet};
+use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
+use bdk_core::{
     bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
-    local_chain::CheckPoint,
-    BlockId, ConfirmationBlockTime,
+    tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed,
 };
-use bdk_chain::{tx_graph, Anchor, Indexed};
 use esplora_client::{OutputStatus, Tx};
+use std::thread::JoinHandle;
 
 use crate::{insert_anchor_from_status, insert_prevouts};
 
@@ -199,11 +195,11 @@ fn fetch_block(
 ///
 /// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
 /// should not surpass `latest_blocks`.
-fn chain_update<A: Anchor>(
+fn chain_update(
     client: &esplora_client::BlockingClient,
     latest_blocks: &BTreeMap<u32, BlockHash>,
     local_tip: &CheckPoint,
-    anchors: &BTreeSet<(A, Txid)>,
+    anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>,
 ) -> Result<CheckPoint, Error> {
     let mut point_of_agreement = None;
     let mut conflicts = vec![];
@@ -232,8 +228,8 @@ fn chain_update<A: Anchor>(
         .extend(conflicts.into_iter().rev())
         .expect("evicted are in order");
 
-    for anchor in anchors {
-        let height = anchor.0.anchor_block().height;
+    for (anchor, _) in anchors {
+        let height = anchor.block_id.height;
         if tip.get(height).is_none() {
             let hash = match fetch_block(client, latest_blocks, height)? {
                 Some(hash) => hash,
@@ -475,6 +471,7 @@ mod test {
     use bdk_chain::bitcoin::Txid;
     use bdk_chain::local_chain::LocalChain;
     use bdk_chain::BlockId;
+    use bdk_core::ConfirmationBlockTime;
     use bdk_testenv::{anyhow, bitcoincore_rpc::RpcApi, TestEnv};
     use esplora_client::{BlockHash, Builder};
     use std::collections::{BTreeMap, BTreeSet};
@@ -561,9 +558,12 @@ mod test {
                     .iter()
                     .map(|&height| -> anyhow::Result<_> {
                         Ok((
-                            BlockId {
-                                height,
-                                hash: env.bitcoind.client.get_block_hash(height as _)?,
+                            ConfirmationBlockTime {
+                                block_id: BlockId {
+                                    height,
+                                    hash: env.bitcoind.client.get_block_hash(height as _)?,
+                                },
+                                confirmation_time: height as _,
                             },
                             Txid::all_zeros(),
                         ))
@@ -598,9 +598,12 @@ mod test {
                     .iter()
                     .map(|&(height, txid)| -> anyhow::Result<_> {
                         Ok((
-                            BlockId {
-                                height,
-                                hash: env.bitcoind.client.get_block_hash(height as _)?,
+                            ConfirmationBlockTime {
+                                block_id: BlockId {
+                                    height,
+                                    hash: env.bitcoind.client.get_block_hash(height as _)?,
+                                },
+                                confirmation_time: height as _,
                             },
                             txid,
                         ))
@@ -794,9 +797,12 @@ mod test {
                     let txid: Txid = bdk_chain::bitcoin::hashes::Hash::hash(
                         &format!("txid_at_height_{}", h).into_bytes(),
                     );
-                    let anchor = BlockId {
-                        height: h,
-                        hash: anchor_blockhash,
+                    let anchor = ConfirmationBlockTime {
+                        block_id: BlockId {
+                            height: h,
+                            hash: anchor_blockhash,
+                        },
+                        confirmation_time: h as _,
                     };
                     (anchor, txid)
                 })
index 9a6e8f1df2c0d3e5168a09c915969bc3b31ee385..7aad133b4497f30771fc6efe7841a6d77c3d3f52 100644 (file)
 //! Just like how [`EsploraExt`] extends the functionality of an
 //! [`esplora_client::BlockingClient`], [`EsploraAsyncExt`] is the async version which extends
 //! [`esplora_client::AsyncClient`].
-//!
-//! [`TxGraph`]: bdk_chain::tx_graph::TxGraph
-//! [`LocalChain`]: bdk_chain::local_chain::LocalChain
-//! [`ChainOracle`]: bdk_chain::ChainOracle
-//! [`example_esplora`]: https://github.com/bitcoindevkit/bdk/tree/master/example-crates/example_esplora
 
-use bdk_chain::bitcoin::{Amount, OutPoint, TxOut, Txid};
-use bdk_chain::{tx_graph, BlockId, ConfirmationBlockTime};
+use bdk_core::bitcoin::{Amount, OutPoint, TxOut, Txid};
+use bdk_core::{tx_graph, BlockId, ConfirmationBlockTime};
 use esplora_client::TxStatus;
 
 pub use esplora_client;