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"] }blockingenablesbitreq, the blocking client with proxy.blocking-httpsenablesbitreq, the blocking client with proxy and TLS (SSL) capabilities using the defaultbitreqbackend.blocking-https-rustlsenablesbitreq, the blocking client with proxy and TLS (SSL) capabilities using therustlsbackend.blocking-https-nativeenablesbitreq, the blocking client with proxy and TLS (SSL) capabilities using the platform’s native TLS backend (likely OpenSSL).blocking-https-rustls-probeenablesbitreq, the blocking client with proxy and TLS (SSL) capabilities usingrustlsand probed system roots.asyncenablesbitreq, the async client with proxy capabilities.async-httpsenablesbitreq, the async client with support for proxying and TLS (SSL) using the defaultbitreqTLS backend.async-https-nativeenablesbitreq, the async client with support for proxying and TLS (SSL) using the platform’s native TLS backend (likely OpenSSL).async-https-rustlsenablesbitreq, the async client with support for proxying and TLS (SSL) using therustlsTLS backend.async-https-rustls-probeenablesbitreq, the async client with support for proxying and TLS (SSL) usingrustlsand probed system roots.tokioenables the default async sleeper used byBuilder::build_async.
Re-exports§
pub use async::Sleeper;pub use blocking::BlockingClient;pub use async::AsyncClient;pub use api::*;
Modules§
Structs§
- Builder
- Shared configuration for
BlockingClientandAsyncClient.
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
FeeRatefor the given confirmation target in blocks. - sat_
per_ vbyte_ to_ feerate - Convert a
HashMapof fee estimates expressed as sat/vB (f64) intoFeeRates.