Skip to content

Commit

Permalink
fix(fmt): apply suggested fixes from rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
oleonardolima committed Aug 23, 2024
1 parent 79a69f6 commit f451a18
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 47 deletions.
26 changes: 16 additions & 10 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ impl AsyncClient {
}
}

/// Get a [`Txid`] of a transaction given its index in a block with a given hash.
/// Get a [`Txid`] of a transaction given its index in a block with a given
/// hash.
pub async fn get_txid_at_block_index(
&self,
block_hash: &BlockHash,
Expand Down Expand Up @@ -222,7 +223,8 @@ impl AsyncClient {
}
}

/// Get a merkle inclusion proof for a [`Transaction`] with the given [`Txid`].
/// Get a merkle inclusion proof for a [`Transaction`] with the given
/// [`Txid`].
pub async fn get_merkle_proof(&self, tx_hash: &Txid) -> Result<Option<MerkleProof>, Error> {
let resp = self
.client
Expand All @@ -244,7 +246,8 @@ impl AsyncClient {
}
}

/// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the given [`Txid`].
/// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the
/// given [`Txid`].
pub async fn get_merkle_block(&self, tx_hash: &Txid) -> Result<Option<MerkleBlock>, Error> {
let resp = self
.client
Expand All @@ -267,7 +270,8 @@ impl AsyncClient {
}
}

/// Get the spending status of an output given a [`Txid`] and the output index.
/// Get the spending status of an output given a [`Txid`] and the output
/// index.
pub async fn get_output_status(
&self,
txid: &Txid,
Expand Down Expand Up @@ -372,7 +376,8 @@ impl AsyncClient {

/// Get confirmed transaction history for the specified address/scripthash,
/// sorted with newest first. Returns 25 transactions per page.
/// More can be requested by specifying the last txid seen by the previous query.
/// More can be requested by specifying the last txid seen by the previous
/// query.
pub async fn scripthash_txs(
&self,
script: &Script,
Expand All @@ -399,8 +404,8 @@ impl AsyncClient {
}
}

/// Get an map where the key is the confirmation target (in number of blocks)
/// and the value is the estimated feerate (in sat/vB).
/// Get an map where the key is the confirmation target (in number of
/// blocks) and the value is the estimated feerate (in sat/vB).
pub async fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, Error> {
let resp = self
.client
Expand All @@ -418,10 +423,11 @@ impl AsyncClient {
}
}

/// Gets some recent block summaries starting at the tip or at `height` if provided.
/// Gets some recent block summaries starting at the tip or at `height` if
/// provided.
///
/// The maximum number of summaries returned depends on the backend itself: esplora returns `10`
/// while [mempool.space](https://mempool.space/docs/api) returns `15`.
/// The maximum number of summaries returned depends on the backend itself:
/// esplora returns `10` while [mempool.space](https://mempool.space/docs/api) returns `15`.
pub async fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockSummary>, Error> {
let url = match height {
Some(height) => format!("{}/blocks/{}", self.url, height),
Expand Down
26 changes: 16 additions & 10 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ impl BlockingClient {
}
}

/// Get a [`Txid`] of a transaction given its index in a block with a given hash.
/// Get a [`Txid`] of a transaction given its index in a block with a given
/// hash.
pub fn get_txid_at_block_index(
&self,
block_hash: &BlockHash,
Expand Down Expand Up @@ -233,17 +234,20 @@ impl BlockingClient {
self.get_opt_response(&format!("/block/{}/raw", block_hash))
}

/// Get a merkle inclusion proof for a [`Transaction`] with the given [`Txid`].
/// Get a merkle inclusion proof for a [`Transaction`] with the given
/// [`Txid`].
pub fn get_merkle_proof(&self, txid: &Txid) -> Result<Option<MerkleProof>, Error> {
self.get_opt_response_json(&format!("/tx/{}/merkle-proof", txid))
}

/// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the given [`Txid`].
/// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the
/// given [`Txid`].
pub fn get_merkle_block(&self, txid: &Txid) -> Result<Option<MerkleBlock>, Error> {
self.get_opt_response_hex(&format!("/tx/{}/merkleblock-proof", txid))
}

/// Get the spending status of an output given a [`Txid`] and the output index.
/// Get the spending status of an output given a [`Txid`] and the output
/// index.
pub fn get_output_status(
&self,
txid: &Txid,
Expand Down Expand Up @@ -299,15 +303,16 @@ impl BlockingClient {
.map(|s| BlockHash::from_str(s.as_str()).map_err(Error::HexToArray))?
}

/// Get an map where the key is the confirmation target (in number of blocks)
/// and the value is the estimated feerate (in sat/vB).
/// Get an map where the key is the confirmation target (in number of
/// blocks) and the value is the estimated feerate (in sat/vB).
pub fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, Error> {
self.get_response_json("/fee-estimates")
}

/// Get confirmed transaction history for the specified address/scripthash,
/// sorted with newest first. Returns 25 transactions per page.
/// More can be requested by specifying the last txid seen by the previous query.
/// More can be requested by specifying the last txid seen by the previous
/// query.
pub fn scripthash_txs(
&self,
script: &Script,
Expand All @@ -321,10 +326,11 @@ impl BlockingClient {
self.get_response_json(&path)
}

/// Gets some recent block summaries starting at the tip or at `height` if provided.
/// Gets some recent block summaries starting at the tip or at `height` if
/// provided.
///
/// The maximum number of summaries returned depends on the backend itself: esplora returns `10`
/// while [mempool.space](https://mempool.space/docs/api) returns `15`.
/// The maximum number of summaries returned depends on the backend itself:
/// esplora returns `10` while [mempool.space](https://mempool.space/docs/api) returns `15`.
pub fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockSummary>, Error> {
let path = match height {
Some(height) => format!("/blocks/{}", height),
Expand Down
58 changes: 31 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,30 @@
//! specific features, set `default-features` to `false` in your `Cargo.toml`
//! and specify the features you want. This will look like this:
//!
//! `esplora-client = { version = "*", default-features = false, features = ["blocking"] }`
//! `esplora-client = { version = "*", default-features = false, features =
//! ["blocking"] }`
//!
//! * `blocking` enables [`minreq`], the blocking client with proxy.
//! * `blocking-https` enables [`minreq`], the blocking client with proxy and TLS (SSL)
//! capabilities using the default [`minreq`] backend.
//! * `blocking-https-rustls` enables [`minreq`], the blocking client with proxy and TLS (SSL)
//! capabilities using the `rustls` backend.
//! * `blocking-https-native` enables [`minreq`], the blocking client with proxy and TLS (SSL)
//! capabilities using the platform's native TLS backend (likely OpenSSL).
//! * `blocking-https-bundled` enables [`minreq`], the blocking client with proxy and TLS (SSL)
//! capabilities using a bundled OpenSSL library backend.
//! * `blocking-https` enables [`minreq`], the blocking client with proxy and
//! TLS (SSL) capabilities using the default [`minreq`] backend.
//! * `blocking-https-rustls` enables [`minreq`], the blocking client with proxy
//! and TLS (SSL) capabilities using the `rustls` backend.
//! * `blocking-https-native` enables [`minreq`], the blocking client with proxy
//! and TLS (SSL) capabilities using the platform's native TLS backend (likely
//! OpenSSL).
//! * `blocking-https-bundled` enables [`minreq`], the blocking client with
//! proxy and TLS (SSL) capabilities using a bundled OpenSSL library backend.
//! * `async` enables [`reqwest`], the async client with proxy capabilities.
//! * `async-https` enables [`reqwest`], the async client with support for proxying and TLS (SSL)
//! using the default [`reqwest`] TLS backend.
//! * `async-https-native` enables [`reqwest`], the async client with support for proxying and TLS
//! (SSL) using the platform's native TLS backend (likely OpenSSL).
//! * `async-https-rustls` enables [`reqwest`], the async client with support for proxying and TLS
//! (SSL) using the `rustls` TLS backend.
//! * `async-https-rustls-manual-roots` enables [`reqwest`], the async client with support for
//! proxying and TLS (SSL) using the `rustls` TLS backend without using its the default root
//! certificates.
//!
//!
//! * `async-https` enables [`reqwest`], the async client with support for
//! proxying and TLS (SSL) using the default [`reqwest`] TLS backend.
//! * `async-https-native` enables [`reqwest`], the async client with support
//! for proxying and TLS (SSL) using the platform's native TLS backend (likely
//! OpenSSL).
//! * `async-https-rustls` enables [`reqwest`], the async client with support
//! for proxying and TLS (SSL) using the `rustls` TLS backend.
//! * `async-https-rustls-manual-roots` enables [`reqwest`], the async client
//! with support for proxying and TLS (SSL) using the `rustls` TLS backend
//! without using its the default root certificates.
#![allow(clippy::result_large_err)]

Expand All @@ -89,7 +90,8 @@ pub use r#async::AsyncClient;
/// Get a fee value in sats/vbytes from the estimates
/// that matches the confirmation target set as parameter.
///
/// Returns `None` if no feerate estimate is found at or below `target` confirmations.
/// Returns `None` if no feerate estimate is found at or below `target`
/// confirmations.
pub fn convert_fee_rate(target: usize, estimates: HashMap<u16, f64>) -> Option<f32> {
estimates
.into_iter()
Expand All @@ -103,11 +105,13 @@ pub struct Builder {
pub base_url: String,
/// Optional URL of the proxy to use to make requests to the Esplora server
///
/// The string should be formatted as: `<protocol>://<user>:<password>@host:<port>`.
/// The string should be formatted as:
/// `<protocol>://<user>:<password>@host:<port>`.
///
/// Note that the format of this value and the supported protocols change slightly between the
/// blocking version of the client (using `minreq`) and the async version (using `reqwest`). For more
/// details check with the documentation of the two crates. Both of them are compiled with
/// Note that the format of this value and the supported protocols change
/// slightly between the blocking version of the client (using `minreq`)
/// and the async version (using `reqwest`). For more details check with
/// the documentation of the two crates. Both of them are compiled with
/// the `socks` feature enabled.
///
/// The proxy is ignored when targeting `wasm32`.
Expand Down Expand Up @@ -594,8 +598,8 @@ mod test {
#[cfg(all(feature = "blocking", feature = "async"))]
#[tokio::test]
async fn test_get_non_existing_block_status() {
// Esplora returns the same status for orphaned blocks as for non-existing blocks:
// non-existing: https://blockstream.info/api/block/0000000000000000000000000000000000000000000000000000000000000000/status
// Esplora returns the same status for orphaned blocks as for non-existing
// blocks: non-existing: https://blockstream.info/api/block/0000000000000000000000000000000000000000000000000000000000000000/status
// orphaned: https://blockstream.info/api/block/000000000000000000181b1a2354620f66868a723c0c4d5b24e4be8bdfc35a7f/status
// (Here the block is cited as orphaned: https://bitcoinchain.com/block_explorer/block/000000000000000000181b1a2354620f66868a723c0c4d5b24e4be8bdfc35a7f/ )
// For this reason, we only test for the non-existing case here.
Expand Down

0 comments on commit f451a18

Please sign in to comment.