Skip to content

Commit

Permalink
Merge #1746: deps(esplora): bump esplora-client to 0.11.0
Browse files Browse the repository at this point in the history
90fd1a2 docs(esplora): update README.md (valued mammal)
f0e6395 deps(esplora): bump `esplora-client` to 0.11.0 (valued mammal)

Pull request description:

  Update `bdk_esplora` to depend on esplora-client 0.11.0

  ### Notes to the reviewers

  bitcoindevkit/rust-esplora-client#103 added a generic type parameter to `AsyncClient` representing a user-defined `Sleeper` and that change is reflected here in order to call the underlying API methods. We also add a new build feature "tokio" that enables the corresponding feature in rust-esplora-client.

  closes #1742

  ### Changelog notice

  `bdk_esplora`: Bump `esplora-client` to 0.11.0

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing
  * [x] This pull request breaks the existing API
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  notmandatory:
    tACK 90fd1a2
  oleonardolima:
    ACK 90fd1a2

Tree-SHA512: 98d529d3bb0dbbf4bbafeea7d30ec5e5816ac9800ba2cb7981fc6189b4b02774956c3ddbb74bf0b3e6e22798bfced36508263e4e89c248b7a6240c5c7109107b
  • Loading branch information
notmandatory committed Dec 6, 2024
2 parents f6c1c61 + 90fd1a2 commit 2a1787b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
4 changes: 3 additions & 1 deletion crates/esplora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ workspace = true

[dependencies]
bdk_core = { path = "../core", version = "0.3.0", default-features = false }
esplora-client = { version = "0.10.0", default-features = false }
esplora-client = { version = "0.11.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]
esplora-client = { version = "0.11.0" }
bdk_chain = { path = "../chain" }
bdk_testenv = { path = "../testenv" }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }

[features]
default = ["std", "async-https", "blocking-https"]
std = ["bdk_chain/std", "miniscript?/std"]
tokio = ["esplora-client/tokio"]
async = ["async-trait", "futures", "esplora-client/async"]
async-https = ["async", "esplora-client/async-https"]
async-https-rustls = ["async", "esplora-client/async-https-rustls"]
Expand Down
15 changes: 11 additions & 4 deletions crates/esplora/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ The extension traits are primarily intended to satisfy [`SyncRequest`]s with [`s

For blocking-only:
```toml
bdk_esplora = { version = "0.3", features = ["blocking"] }
bdk_esplora = { version = "0.19", features = ["blocking"] }
```

For async-only:
```toml
bdk_esplora = { version = "0.3", features = ["async"] }
bdk_esplora = { version = "0.19", features = ["async"] }
```

For async-only (with https):

You can additionally specify to use either rustls or native-tls, e.g. `async-https-native`, and this applies to both async and blocking features.
```toml
bdk_esplora = { version = "0.19", features = ["async-https"] }
```

For async-only (with tokio):
```toml
bdk_esplora = { version = "0.3", features = ["async-https"] }
bdk_esplora = { version = "0.19", features = ["async", "tokio"] }
```

To use the extension traits:
Expand All @@ -34,7 +41,7 @@ use bdk_esplora::EsploraExt;
use bdk_esplora::EsploraAsyncExt;
```

For full examples, refer to [`example-crates/wallet_esplora_blocking`](https://github.com/bitcoindevkit/bdk/tree/master/example-crates/wallet_esplora_blocking) and [`example-crates/wallet_esplora_async`](https://github.com/bitcoindevkit/bdk/tree/master/example-crates/wallet_esplora_async).
For full examples, refer to [`example_wallet_esplora_blocking`](https://github.com/bitcoindevkit/bdk/tree/master/example-crates/example_wallet_esplora_blocking) and [`example_wallet_esplora_async`](https://github.com/bitcoindevkit/bdk/tree/master/example-crates/example_wallet_esplora_async).

[`esplora-client`]: https://docs.rs/esplora-client/
[`bdk_chain`]: https://docs.rs/bdk-chain/
Expand Down
47 changes: 31 additions & 16 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bdk_core::{
bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
BlockId, CheckPoint, ConfirmationBlockTime, Indexed, TxUpdate,
};
use esplora_client::Sleeper;
use futures::{stream::FuturesOrdered, TryStreamExt};

use crate::{insert_anchor_from_status, insert_prevouts};
Expand Down Expand Up @@ -50,7 +51,11 @@ pub trait EsploraAsyncExt {

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl EsploraAsyncExt for esplora_client::AsyncClient {
impl<S> EsploraAsyncExt for esplora_client::AsyncClient<S>
where
S: Sleeper + Clone + Send + Sync,
S::Sleep: Send,
{
async fn full_scan<K: Ord + Clone + Send, R: Into<FullScanRequest<K>> + Send>(
&self,
request: R,
Expand Down Expand Up @@ -165,8 +170,8 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
/// block-based chain-sources). Therefore it's better to be conservative when setting the tip (use
/// an earlier tip rather than a later tip) otherwise the caller may accidentally skip blocks when
/// alternating between chain-sources.
async fn fetch_latest_blocks(
client: &esplora_client::AsyncClient,
async fn fetch_latest_blocks<S: Sleeper>(
client: &esplora_client::AsyncClient<S>,
) -> Result<BTreeMap<u32, BlockHash>, Error> {
Ok(client
.get_blocks(None)
Expand All @@ -179,8 +184,8 @@ async fn fetch_latest_blocks(
/// Used instead of [`esplora_client::BlockingClient::get_block_hash`].
///
/// This first checks the previously fetched `latest_blocks` before fetching from Esplora again.
async fn fetch_block(
client: &esplora_client::AsyncClient,
async fn fetch_block<S: Sleeper>(
client: &esplora_client::AsyncClient<S>,
latest_blocks: &BTreeMap<u32, BlockHash>,
height: u32,
) -> Result<Option<BlockHash>, Error> {
Expand All @@ -205,8 +210,8 @@ 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(
client: &esplora_client::AsyncClient,
async fn chain_update<S: Sleeper>(
client: &esplora_client::AsyncClient<S>,
latest_blocks: &BTreeMap<u32, BlockHash>,
local_tip: &CheckPoint,
anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>,
Expand Down Expand Up @@ -271,13 +276,17 @@ async fn chain_update(
/// script pubkey that contains a non-empty transaction history.
///
/// Refer to [crate-level docs](crate) for more.
async fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<ScriptBuf>> + Send>(
client: &esplora_client::AsyncClient,
async fn fetch_txs_with_keychain_spks<I, S>(
client: &esplora_client::AsyncClient<S>,
inserted_txs: &mut HashSet<Txid>,
mut keychain_spks: I,
stop_gap: usize,
parallel_requests: usize,
) -> Result<(TxUpdate<ConfirmationBlockTime>, Option<u32>), Error> {
) -> Result<(TxUpdate<ConfirmationBlockTime>, Option<u32>), Error>
where
I: Iterator<Item = Indexed<ScriptBuf>> + Send,
S: Sleeper + Clone + Send + Sync,
{
type TxsOfSpkIndex = (u32, Vec<esplora_client::Tx>);

let mut update = TxUpdate::<ConfirmationBlockTime>::default();
Expand Down Expand Up @@ -346,14 +355,16 @@ async fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<ScriptBuf>> + S
/// HTTP requests to make in parallel.
///
/// Refer to [crate-level docs](crate) for more.
async fn fetch_txs_with_spks<I: IntoIterator<Item = ScriptBuf> + Send>(
client: &esplora_client::AsyncClient,
async fn fetch_txs_with_spks<I, S>(
client: &esplora_client::AsyncClient<S>,
inserted_txs: &mut HashSet<Txid>,
spks: I,
parallel_requests: usize,
) -> Result<TxUpdate<ConfirmationBlockTime>, Error>
where
I: IntoIterator<Item = ScriptBuf> + Send,
I::IntoIter: Send,
S: Sleeper + Clone + Send + Sync,
{
fetch_txs_with_keychain_spks(
client,
Expand All @@ -372,14 +383,16 @@ where
/// `parallel_requests` specifies the maximum number of HTTP requests to make in parallel.
///
/// Refer to [crate-level docs](crate) for more.
async fn fetch_txs_with_txids<I: IntoIterator<Item = Txid> + Send>(
client: &esplora_client::AsyncClient,
async fn fetch_txs_with_txids<I, S>(
client: &esplora_client::AsyncClient<S>,
inserted_txs: &mut HashSet<Txid>,
txids: I,
parallel_requests: usize,
) -> Result<TxUpdate<ConfirmationBlockTime>, Error>
where
I: IntoIterator<Item = Txid> + Send,
I::IntoIter: Send,
S: Sleeper + Clone + Send + Sync,
{
let mut update = TxUpdate::<ConfirmationBlockTime>::default();
// Only fetch for non-inserted txs.
Expand Down Expand Up @@ -421,14 +434,16 @@ where
/// `parallel_requests` specifies the maximum number of HTTP requests to make in parallel.
///
/// Refer to [crate-level docs](crate) for more.
async fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint> + Send>(
client: &esplora_client::AsyncClient,
async fn fetch_txs_with_outpoints<I, S>(
client: &esplora_client::AsyncClient<S>,
inserted_txs: &mut HashSet<Txid>,
outpoints: I,
parallel_requests: usize,
) -> Result<TxUpdate<ConfirmationBlockTime>, Error>
where
I: IntoIterator<Item = OutPoint> + Send,
I::IntoIter: Send,
S: Sleeper + Clone + Send + Sync,
{
let outpoints = outpoints.into_iter().collect::<Vec<_>>();
let mut update = TxUpdate::<ConfirmationBlockTime>::default();
Expand Down
2 changes: 1 addition & 1 deletion example-crates/example_wallet_esplora_async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"

[dependencies]
bdk_wallet = { path = "../../crates/wallet", features = ["rusqlite"] }
bdk_esplora = { path = "../../crates/esplora", features = ["async-https"] }
bdk_esplora = { path = "../../crates/esplora", features = ["async-https", "tokio"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
anyhow = "1"

0 comments on commit 2a1787b

Please sign in to comment.