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