Skip to main content

AsyncClient

Struct AsyncClient 

Source
pub struct AsyncClient<S = DefaultSleeper> { /* private fields */ }
Expand description

An async 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.

The generic parameter S determines the asynchronous runtime used for sleeping between retries. Defaults to the Tokio-backed DefaultSleeper.

§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.

Implementations§

Source§

impl<S: Sleeper> AsyncClient<S>

Source

pub fn from_builder(builder: Builder) -> Result<Self, Error>

Build an AsyncClient from a Builder.

Configures the underlying bitreq::Client with proxy, timeout, and headers specified in the Builder. No network request is made until a client method is awaited.

§Errors

Returns an Error if the HTTP client fails to build, or if any of the provided header names or values are invalid.

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 client(&self) -> &Client

Return the underlying bitreq::Client.

This can be useful for callers that need access to shared connection state managed by the HTTP client.

Source

pub async 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 async 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 async 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 async 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 async 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 async 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 async fn get_header_by_hash( &self, block_hash: &BlockHash, ) -> Result<BlockHeader, Error>

Get the BlockHeader of a Block given its BlockHash.

Source

pub async 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 async 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 async fn get_merkle_proof( &self, tx_hash: &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 async fn get_merkle_block( &self, tx_hash: &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 async 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 async 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 async 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 async fn get_height(&self) -> Result<u32, Error>

Get the block height of the current blockchain tip.

Source

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

Get the BlockHash of the current blockchain tip.

Source

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

Get the BlockHash of a Block given its height.

Source

pub async 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 async 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 async 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 async fn get_mempool_address_txs( &self, address: &Address, ) -> Result<Vec<EsploraTx>, Error>

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

Source

pub async 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 async 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 async 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 async fn get_mempool_recent_txs( &self, ) -> Result<Vec<MempoolRecentTx>, Error>

Get the last 10 MempoolRecentTxs to enter the mempool.

Source

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

Get the full list of Txids in the mempool.

The order of the Txids is arbitrary.

Source

pub async 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 async 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 async 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 async 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 async 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 async 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 async fn get_address_utxos( &self, address: &Address, ) -> Result<Vec<Utxo>, Error>

Get all confirmed Utxos locked to the given Address.

Source

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

Get all confirmed Utxos locked to the given Script.

Trait Implementations§

Source§

impl<S: Clone> Clone for AsyncClient<S>

Source§

fn clone(&self) -> AsyncClient<S>

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

Auto Trait Implementations§

§

impl<S> Freeze for AsyncClient<S>

§

impl<S> RefUnwindSafe for AsyncClient<S>
where S: RefUnwindSafe,

§

impl<S> Send for AsyncClient<S>
where S: Send,

§

impl<S> Sync for AsyncClient<S>
where S: Sync,

§

impl<S> Unpin for AsyncClient<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for AsyncClient<S>

§

impl<S> UnwindSafe for AsyncClient<S>
where S: UnwindSafe,

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.