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>
impl<S: Sleeper> AsyncClient<S>
Sourcepub fn from_builder(builder: Builder) -> Result<Self, Error>
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.
Sourcepub fn url(&self) -> &str
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.
Sourcepub fn client(&self) -> &Client
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.
Sourcepub async fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error>
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.
Sourcepub async fn get_tx_no_opt(&self, txid: &Txid) -> Result<Transaction, Error>
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.
Sourcepub async fn get_txid_at_block_index(
&self,
block_hash: &BlockHash,
index: usize,
) -> Result<Option<Txid>, Error>
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.
Sourcepub async fn get_tx_status(&self, txid: &Txid) -> Result<TxStatus, Error>
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.
Sourcepub async fn get_tx_info(&self, txid: &Txid) -> Result<Option<EsploraTx>, Error>
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.
Sourcepub async fn get_tx_outspends(
&self,
txid: &Txid,
) -> Result<Vec<OutputStatus>, Error>
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.
Sourcepub async fn get_header_by_hash(
&self,
block_hash: &BlockHash,
) -> Result<BlockHeader, Error>
pub async fn get_header_by_hash( &self, block_hash: &BlockHash, ) -> Result<BlockHeader, Error>
Get the BlockHeader of a Block given its BlockHash.
Sourcepub async fn get_block_status(
&self,
block_hash: &BlockHash,
) -> Result<BlockStatus, Error>
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.
Sourcepub async fn get_block_by_hash(
&self,
block_hash: &BlockHash,
) -> Result<Option<Block>, Error>
pub async fn get_block_by_hash( &self, block_hash: &BlockHash, ) -> Result<Option<Block>, Error>
Sourcepub async fn get_merkle_proof(
&self,
tx_hash: &Txid,
) -> Result<Option<MerkleProof>, Error>
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.
Sourcepub async fn get_merkle_block(
&self,
tx_hash: &Txid,
) -> Result<Option<MerkleBlock>, Error>
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.
Sourcepub async fn get_output_status(
&self,
txid: &Txid,
index: u64,
) -> Result<Option<OutputStatus>, Error>
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.
Sourcepub async fn broadcast(&self, transaction: &Transaction) -> Result<Txid, Error>
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.
Sourcepub async fn submit_package(
&self,
transactions: &[Transaction],
maxfeerate: Option<FeeRate>,
maxburnamount: Option<Amount>,
) -> Result<SubmitPackageResult, Error>
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.
Sourcepub async fn get_height(&self) -> Result<u32, Error>
pub async fn get_height(&self) -> Result<u32, Error>
Get the block height of the current blockchain tip.
Sourcepub async fn get_tip_hash(&self) -> Result<BlockHash, Error>
pub async fn get_tip_hash(&self) -> Result<BlockHash, Error>
Get the BlockHash of the current blockchain tip.
Sourcepub async fn get_address_stats(
&self,
address: &Address,
) -> Result<AddressStats, Error>
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.
Sourcepub async fn get_scripthash_stats(
&self,
script: &Script,
) -> Result<ScriptHashStats, Error>
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.
Sourcepub async fn get_address_txs(
&self,
address: &Address,
last_seen: Option<Txid>,
) -> Result<Vec<EsploraTx>, Error>
pub async fn get_address_txs( &self, address: &Address, last_seen: Option<Txid>, ) -> Result<Vec<EsploraTx>, Error>
Sourcepub async fn get_mempool_address_txs(
&self,
address: &Address,
) -> Result<Vec<EsploraTx>, Error>
pub async fn get_mempool_address_txs( &self, address: &Address, ) -> Result<Vec<EsploraTx>, Error>
Sourcepub async fn get_scripthash_txs(
&self,
script: &Script,
last_seen: Option<Txid>,
) -> Result<Vec<EsploraTx>, Error>
pub async fn get_scripthash_txs( &self, script: &Script, last_seen: Option<Txid>, ) -> Result<Vec<EsploraTx>, Error>
Sourcepub async fn get_mempool_scripthash_txs(
&self,
script: &Script,
) -> Result<Vec<EsploraTx>, Error>
pub async fn get_mempool_scripthash_txs( &self, script: &Script, ) -> Result<Vec<EsploraTx>, Error>
Sourcepub async fn get_mempool_stats(&self) -> Result<MempoolStats, Error>
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.
Sourcepub async fn get_mempool_recent_txs(
&self,
) -> Result<Vec<MempoolRecentTx>, Error>
pub async fn get_mempool_recent_txs( &self, ) -> Result<Vec<MempoolRecentTx>, Error>
Get the last 10 MempoolRecentTxs to enter the mempool.
Sourcepub async fn get_block_txids(
&self,
blockhash: &BlockHash,
) -> Result<Vec<Txid>, Error>
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.
Sourcepub async fn get_block_txs(
&self,
blockhash: &BlockHash,
start_index: Option<u32>,
) -> Result<Vec<EsploraTx>, Error>
pub async fn get_block_txs( &self, blockhash: &BlockHash, start_index: Option<u32>, ) -> Result<Vec<EsploraTx>, Error>
Sourcepub async fn get_blocks(
&self,
height: Option<u32>,
) -> Result<Vec<BlockSummary>, Error>
👎Deprecated since 0.13.0: use get_block_infos instead
pub async fn get_blocks( &self, height: Option<u32>, ) -> Result<Vec<BlockSummary>, Error>
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.
Sourcepub async fn get_block_infos(
&self,
height: Option<u32>,
) -> Result<Vec<BlockInfo>, Error>
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.
Trait Implementations§
Source§impl<S: Clone> Clone for AsyncClient<S>
impl<S: Clone> Clone for AsyncClient<S>
Source§fn clone(&self) -> AsyncClient<S>
fn clone(&self) -> AsyncClient<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more