Skip to main content

Crate esplora_client

Crate esplora_client 

Source
Expand description

§Esplora Client

A client library for querying Esplora HTTP APIs from Rust.

The crate exposes a shared set of Esplora response types in api, plus optional blocking and async clients built on bitreq. Both clients use the same Builder configuration for the base URL, proxy, timeout, custom headers, and retry policy.

§Client Modes

Enable the blocking feature to use BlockingClient, whose methods block the current thread until each request completes. Enable the async feature to use AsyncClient, whose methods return futures and require an async runtime. The default async sleeper is backed by Tokio when the tokio feature is enabled; custom runtimes can supply their own Sleeper.

§Examples

Create a blocking client:

use esplora_client::Builder;

fn main() -> Result<(), esplora_client::Error> {
    let builder = Builder::new("https://blockstream.info/testnet/api");
    let blocking_client = builder.build_blocking();
    let height = blocking_client.get_height()?;

    Ok(())
}

Create an async client:

use esplora_client::Builder;

#[tokio::main]
async fn main() -> Result<(), esplora_client::Error> {
let builder = Builder::new("https://blockstream.info/testnet/api");
let async_client = builder.build_async()?;
let height = async_client.get_height().await?;

Ok(())
}

§Retries

Both clients retry responses with status codes listed in RETRYABLE_ERROR_CODES. Retry attempts use exponential backoff starting at 256 milliseconds and are controlled by Builder::max_retries.

§Features

By default the crate enables all features. To select only the pieces you need, set default-features = false in Cargo.toml and list the desired features explicitly:

esplora-client = { version = "*", default-features = false, features = ["blocking"] }
  • blocking enables bitreq, the blocking client with proxy.
  • blocking-https enables bitreq, the blocking client with proxy and TLS (SSL) capabilities using the default bitreq backend.
  • blocking-https-rustls enables bitreq, the blocking client with proxy and TLS (SSL) capabilities using the rustls backend.
  • blocking-https-native enables bitreq, the blocking client with proxy and TLS (SSL) capabilities using the platform’s native TLS backend (likely OpenSSL).
  • blocking-https-rustls-probe enables bitreq, the blocking client with proxy and TLS (SSL) capabilities using rustls and probed system roots.
  • async enables bitreq, the async client with proxy capabilities.
  • async-https enables bitreq, the async client with support for proxying and TLS (SSL) using the default bitreq TLS backend.
  • async-https-native enables bitreq, the async client with support for proxying and TLS (SSL) using the platform’s native TLS backend (likely OpenSSL).
  • async-https-rustls enables bitreq, the async client with support for proxying and TLS (SSL) using the rustls TLS backend.
  • async-https-rustls-probe enables bitreq, the async client with support for proxying and TLS (SSL) using rustls and probed system roots.
  • tokio enables the default async sleeper used by Builder::build_async.

Re-exports§

pub use async::Sleeper;
pub use blocking::BlockingClient;
pub use async::AsyncClient;
pub use api::*;

Modules§

api
Esplora API
async
Asynchronous Esplora Client
blocking
Blocking Esplora Client

Structs§

Builder
Shared configuration for BlockingClient and AsyncClient.

Enums§

Error
Errors that can occur while building clients, sending requests, or decoding responses.

Constants§

RETRYABLE_ERROR_CODES
HTTP response status codes for which a request may be retried.

Functions§

convert_fee_rate
Return the FeeRate for the given confirmation target in blocks.
sat_per_vbyte_to_feerate
Convert a HashMap of fee estimates expressed as sat/vB (f64) into FeeRates.