Skip to main content

BlockingClient

Struct BlockingClient 

Source
pub struct BlockingClient {
    pub proxy: Option<String>,
    pub timeout: Option<Duration>,
    pub headers: HashMap<String, String>,
    pub max_retries: usize,
    /* private fields */
}
Expand description

A synchronous client for interacting with an Esplora API server.

Use Builder to construct an instance of this client. The client stores the server base URL and request configuration, then exposes convenience methods for the transaction, block, address, scripthash, fee-estimate, and mempool endpoints.

Each method blocks the current thread until the HTTP request completes and the response is parsed into the requested type.

§Retries

Failed requests are automatically retried up to max_retries times (configured via Builder) with exponential backoff, but only for retryable HTTP status codes. See crate::RETRYABLE_ERROR_CODES for the full list.

Fields§

§proxy: Option<String>

The URL of the proxy host.

NOTE: The proxy is ignored when targeting wasm32.

§timeout: Option<Duration>

Per-request socket timeout.

§headers: HashMap<String, String>

HTTP headers to set on every request made to the Esplora server.

§max_retries: usize

Maximum number of retry attempts for retryable responses.

Implementations§

Source§

impl BlockingClient

Source

pub fn from_builder(builder: Builder) -> Self

Build a BlockingClient from a Builder.

This consumes the builder configuration and stores it on the client. No network request is made until a client method is called.

Source

pub fn url(&self) -> &str

Return the base URL of the Esplora server this client connects to.

The returned value is the exact string provided to Builder::new.

Source

pub fn post_request<T: Into<Vec<u8>>>( &self, path: &str, body: T, query_params: Option<HashSet<(&str, String)>>, ) -> Result<Response, Error>

Make an HTTP POST request to path with body.

Configures query parameters, if any, and returns the raw response after checking the HTTP status code.

§Errors

This function will return an error either from the HTTP client, or the response’s serde_json deserialization.

Source

pub fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error>

Get a raw Transaction given its Txid.

Returns None if the transaction is not found.

Source

pub fn get_tx_no_opt(&self, txid: &Txid) -> Result<Transaction, Error>

Get a raw Transaction given its Txid.

Returns an Error::TransactionNotFound if the transaction is not found. Prefer Self::get_tx if you want to handle the not-found case explicitly.

Source

pub fn get_txid_at_block_index( &self, block_hash: &BlockHash, index: usize, ) -> Result<Option<Txid>, Error>

Get the Txid of the transaction at position index within the block identified by block_hash.

Returns None if the block or index is not found.

Source

pub fn get_tx_status(&self, txid: &Txid) -> Result<TxStatus, Error>

Get the confirmation status of a Transaction given its Txid.

Returns a TxStatus containing whether the transaction is confirmed, and if so, the block height, hash, and timestamp it was confirmed in.

Source

pub fn get_tx_info(&self, txid: &Txid) -> Result<Option<EsploraTx>, Error>

Get an EsploraTx given its Txid.

Unlike Self::get_tx, returns the Esplora-specific EsploraTx type, which includes additional metadata such as confirmation status, fee, and weight. Returns None if the transaction is not found.

Source

pub fn get_tx_outspends(&self, txid: &Txid) -> Result<Vec<OutputStatus>, Error>

Get the spend status of all outputs in a Transaction, given its Txid.

Returns a Vec of OutputStatus, one per output, ordered as they appear in the Transaction.

Source

pub fn get_header_by_hash( &self, block_hash: &BlockHash, ) -> Result<BlockHeader, Error>

Get the BlockHeader of a Block given its BlockHash.

Source

pub fn get_block_status( &self, block_hash: &BlockHash, ) -> Result<BlockStatus, Error>

Get the BlockStatus of a Block given its BlockHash.

Returns a BlockStatus indicating whether this Block is part of the best chain, its height, and the BlockHash of the next Block, if any.

Source

pub fn get_block_by_hash( &self, block_hash: &BlockHash, ) -> Result<Option<Block>, Error>

Get the full Block with the given BlockHash.

Returns None if the Block is not found.

Source

pub fn get_merkle_proof( &self, txid: &Txid, ) -> Result<Option<MerkleProof>, Error>

Get a Merkle inclusion proof for a Transaction given its Txid.

Returns a MerkleProof that can be used to verify the transaction’s inclusion in a block. Returns None if the transaction is not found or is unconfirmed.

Source

pub fn get_merkle_block( &self, txid: &Txid, ) -> Result<Option<MerkleBlock>, Error>

Get a MerkleBlock inclusion proof for a Transaction given its Txid.

Returns None if the transaction is not found or is unconfirmed.

Source

pub fn get_output_status( &self, txid: &Txid, index: u64, ) -> Result<Option<OutputStatus>, Error>

Get the spend status of a specific output, identified by its Txid and output index.

Returns an OutputStatus indicating whether the output has been spent, and if so, by which transaction. Returns None if not found.

Source

pub fn broadcast(&self, transaction: &Transaction) -> Result<Txid, Error>

Broadcast a Transaction to the Esplora server.

The transaction is serialized and sent as a hex-encoded string. Returns the Txid of the broadcasted transaction.

§Errors

Returns an Error if the request fails or the server rejects the transaction.

Source

pub fn submit_package( &self, transactions: &[Transaction], maxfeerate: Option<FeeRate>, maxburnamount: Option<Amount>, ) -> Result<SubmitPackageResult, Error>

Broadcast a package of Transactions to the Esplora server.

Returns a SubmitPackageResult containing the result for each transaction in the package, keyed by bitcoin::Wtxid.

Optionally, maxfeerate and maxburnamount can be provided to reject transactions that exceed these thresholds.

§Errors

Returns an Error if the request fails or the server rejects the package.

Source

pub fn get_height(&self) -> Result<u32, Error>

Get the block height of the current blockchain tip.

Source

pub fn get_tip_hash(&self) -> Result<BlockHash, Error>

Get the BlockHash of the current blockchain tip.

Source

pub fn get_block_hash(&self, block_height: u32) -> Result<BlockHash, Error>

Get the BlockHash of a Block given its height.

Source

pub fn get_mempool_stats(&self) -> Result<MempoolStats, Error>

Get global statistics about the mempool.

Returns a MempoolStats containing the transaction count, total virtual size, total fees, and fee rate histogram.

Source

pub fn get_mempool_recent_txs(&self) -> Result<Vec<MempoolRecentTx>, Error>

Get the last 10 MempoolRecentTxs to enter the mempool.

Source

pub fn get_mempool_txids(&self) -> Result<Vec<Txid>, Error>

Get the full list of Txids currently in the mempool.

The order of the returned Txids is arbitrary.

Source

pub fn get_fee_estimates(&self) -> Result<HashMap<u16, FeeRate>, Error>

Get fee estimates for a range of confirmation targets.

Returns a HashMap where the key is the confirmation target in blocks and the value is the estimated FeeRate.

Source

pub fn get_address_stats( &self, address: &Address, ) -> Result<AddressStats, Error>

Get statistics about an Address.

Returns an AddressStats containing confirmed and mempool transaction summaries for the given address, including funded and spent output counts and their total values.

Source

pub fn get_scripthash_stats( &self, script: &Script, ) -> Result<ScriptHashStats, Error>

Get statistics about a Script hash’s confirmed and mempool transactions.

Returns a ScriptHashStats containing transaction summaries for the SHA256 hash of the given Script.

Source

pub fn get_address_txs( &self, address: &Address, last_seen: Option<Txid>, ) -> Result<Vec<EsploraTx>, Error>

Get confirmed transaction history for an Address, sorted newest first.

Returns up to 50 mempool transactions plus the first 25 confirmed transactions. To paginate, pass the Txid of the last transaction seen in the previous response as last_seen.

Source

pub fn get_mempool_address_txs( &self, address: &Address, ) -> Result<Vec<EsploraTx>, Error>

Get unconfirmed mempool EsploraTxs for an Address, sorted newest first.

Source

pub fn get_scripthash_txs( &self, script: &Script, last_seen: Option<Txid>, ) -> Result<Vec<EsploraTx>, Error>

Get confirmed transaction history for a Script hash, sorted newest first.

Returns 25 transactions per page. To paginate, pass the Txid of the last transaction seen in the previous response as last_seen.

Source

pub fn get_mempool_scripthash_txs( &self, script: &Script, ) -> Result<Vec<EsploraTx>, Error>

Get unconfirmed mempool EsploraTxs for a Script hash, sorted newest first.

Source

pub fn get_block_info(&self, blockhash: &BlockHash) -> Result<BlockInfo, Error>

Get a BlockInfo summary for the Block with the given BlockHash.

BlockInfo includes metadata such as the height, timestamp, Transaction count, size, and Weight.

This method does not return the full Block.

Source

pub fn get_block_txids(&self, blockhash: &BlockHash) -> Result<Vec<Txid>, Error>

Get all Txids of Transactions included in the Block with the given BlockHash.

Source

pub fn get_block_txs( &self, blockhash: &BlockHash, start_index: Option<u32>, ) -> Result<Vec<EsploraTx>, Error>

Get up to 25 EsploraTxs from the Block with the given BlockHash, starting at start_index.

If start_index is None, starts from the first transaction (index 0).

Note that start_index must be a multiple of 25, otherwise the server will return an error.

Source

pub fn get_blocks( &self, height: Option<u32>, ) -> Result<Vec<BlockSummary>, Error>

👎Deprecated since 0.13.0:

use get_block_infos instead

Get BlockInfo summaries for recent Blocks.

If height is Some(h), returns blocks starting from height h. If height is None, returns blocks starting from the current tip.

The maximum number of summaries returned depends on the backend itself: Esplora returns 10 while mempool.space returns 15.

Source

pub fn get_block_infos( &self, height: Option<u32>, ) -> Result<Vec<BlockInfo>, Error>

Get BlockInfo summaries for recent Blocks.

If height is Some(h), returns blocks starting from height h. If height is None, returns blocks starting from the current tip.

The maximum number of summaries returned depends on the backend itself: Esplora returns 10 while mempool.space returns 15.

§Errors

Returns Error::InvalidResponse if the server returns an empty list.

This method does not return the full Block.

Source

pub fn get_address_utxos(&self, address: &Address) -> Result<Vec<Utxo>, Error>

Get all confirmed Utxos locked to the given Address.

Source

pub fn get_scripthash_utxos(&self, script: &Script) -> Result<Vec<Utxo>, Error>

Get all confirmed Utxos locked to the given Script.

Trait Implementations§

Source§

impl Clone for BlockingClient

Source§

fn clone(&self) -> BlockingClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockingClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.