From: 志宇 Date: Fri, 23 Aug 2024 18:36:07 +0000 (+0000) Subject: feat(esplora)!: depend on `bdk_core` instead of `bdk_chain` X-Git-Tag: v1.0.0-beta.2~2^2~2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.OddLengthStringError.html?a=commitdiff_plain;h=fea8eede760130db32c2cfaecc272f6c1ed979db;p=bdk 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. --- diff --git a/crates/esplora/Cargo.toml b/crates/esplora/Cargo.toml index 9148a0f8..8e0cf046 100644 --- a/crates/esplora/Cargo.toml +++ b/crates/esplora/Cargo.toml @@ -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"] } diff --git a/crates/esplora/README.md b/crates/esplora/README.md index ef2e6517..0535b9a3 100644 --- a/crates/esplora/README.md +++ b/crates/esplora/README.md @@ -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 diff --git a/crates/esplora/src/async_ext.rs b/crates/esplora/src/async_ext.rs index f3c8e966..041205c5 100644 --- a/crates/esplora/src/async_ext.rs +++ b/crates/esplora/src/async_ext.rs @@ -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( +async fn chain_update( client: &esplora_client::AsyncClient, latest_blocks: &BTreeMap, local_tip: &CheckPoint, - anchors: &BTreeSet<(A, Txid)>, + anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>, ) -> Result { let mut point_of_agreement = None; let mut conflicts = vec![]; @@ -242,8 +238,8 @@ async fn chain_update( .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, )) diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 62f0d351..d0744b4e 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -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( +fn chain_update( client: &esplora_client::BlockingClient, latest_blocks: &BTreeMap, local_tip: &CheckPoint, - anchors: &BTreeSet<(A, Txid)>, + anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>, ) -> Result { let mut point_of_agreement = None; let mut conflicts = vec![]; @@ -232,8 +228,8 @@ fn chain_update( .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) }) diff --git a/crates/esplora/src/lib.rs b/crates/esplora/src/lib.rs index 9a6e8f1d..7aad133b 100644 --- a/crates/esplora/src/lib.rs +++ b/crates/esplora/src/lib.rs @@ -19,14 +19,9 @@ //! 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;