From 9f888c17b7f1ede4c9d752f64e96ba024a643167 Mon Sep 17 00:00:00 2001 From: Leonardo Lima Date: Fri, 23 Aug 2024 13:32:38 -0300 Subject: [PATCH 1/4] chore(deps): bump `actions/checkout` from v3 to v4 - rename the workflow from Rust to CI - add name to build-test step of Build & Test --- .github/workflows/cont_integration.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 2ac7e07..2ca23b9 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -1,4 +1,4 @@ -name: Rust +name: CI on: push: @@ -11,7 +11,7 @@ env: jobs: build-test: - + name: Build & Test runs-on: ubuntu-latest strategy: matrix: @@ -32,10 +32,10 @@ jobs: - async-https-rustls - async-https-rustls-manual-roots steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Generate cache key run: echo "${{ matrix.rust.version }} ${{ matrix.features }}" | tee .cache_key - - name: cache + - name: Rust Cache uses: actions/cache@v3 with: path: | @@ -52,7 +52,7 @@ jobs: run: rustup component add clippy - name: Update toolchain run: rustup update - - name: pin dependencies + - name: Pin dependencies for MSRV if: matrix.rust.version == '1.63.0' run: | cargo update -p zstd-sys --precise "2.0.8+zstd.1.5.5" From 3f2ca2fdcb3c31a71a47082e9c9f67a126216be8 Mon Sep 17 00:00:00 2001 From: Leonardo Lima Date: Fri, 23 Aug 2024 13:43:50 -0300 Subject: [PATCH 2/4] refactor(ci)!: add new `fmt` and `clippy` jobs refactor(ci)!: add new `fmt` and `clippy` jobs - adds two new jobs for `fmt` and `clippy`. - use `dtolnay/rust-toolchain@v1` instead of `actions-rs/toolchain@v1` chore(rustfmt): add `.rustfmt.toml` and use `nighly on fmt CI step --- .github/workflows/cont_integration.yml | 55 +++++++++++++++++++++----- .rustfmt.toml | 3 ++ 2 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 2ca23b9..729922e 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -17,7 +17,6 @@ jobs: matrix: rust: - version: stable # STABLE - clippy: true - version: 1.63.0 # MSRV features: - default @@ -32,7 +31,8 @@ jobs: - async-https-rustls - async-https-rustls-manual-roots steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - name: Generate cache key run: echo "${{ matrix.rust.version }} ${{ matrix.features }}" | tee .cache_key - name: Rust Cache @@ -43,13 +43,12 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - - name: Set default toolchain - run: rustup default ${{ matrix.rust.version }} + - name: Install Rust Toolchain + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ matrix.rust.version }} - name: Set profile run: rustup set profile minimal - - name: Add clippy - if: ${{ matrix.rust.clippy }} - run: rustup component add clippy - name: Update toolchain run: rustup update - name: Pin dependencies for MSRV @@ -62,8 +61,44 @@ jobs: cargo update -p tokio --precise "1.38.1" - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features - - name: Clippy - if: ${{ matrix.rust.clippy }} - run: cargo clippy --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings - name: Test run: cargo test --features ${{ matrix.features }} --no-default-features -- --test-threads=1 + + fmt: + name: Rust Formatting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Rust Toolchain + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: nightly + components: rustfmt + - name: Check fmt + run: cargo fmt --all --check + + clippy: + name: Rust Clippy + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Rust Toolchain + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + components: clippy + - name: Rust Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} + - name: Check clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features --all-targets -- -D warnings diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..4f9a262 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,3 @@ +format_code_in_doc_comments=true +wrap_comments=true +comment_width=100 From b7636e8a5328d26c01249c79e03f33921760445b Mon Sep 17 00:00:00 2001 From: Leonardo Lima Date: Fri, 23 Aug 2024 13:45:38 -0300 Subject: [PATCH 3/4] fix(fmt): apply suggested fixes from `rustfmt` --- src/async.rs | 26 ++++++++++++++++---------- src/blocking.rs | 26 ++++++++++++++++---------- src/lib.rs | 26 ++++++++++++++------------ 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/async.rs b/src/async.rs index bf72a48..62b1689 100644 --- a/src/async.rs +++ b/src/async.rs @@ -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, @@ -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, Error> { let resp = self .client @@ -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, Error> { let resp = self .client @@ -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, @@ -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, @@ -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, Error> { let resp = self .client @@ -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) -> Result, Error> { let url = match height { Some(height) => format!("{}/blocks/{}", self.url, height), diff --git a/src/blocking.rs b/src/blocking.rs index 0448572..22c95fd 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -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, @@ -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, 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, 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, @@ -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, 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, @@ -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) -> Result, Error> { let path = match height { Some(height) => format!("/blocks/{}", height), diff --git a/src/lib.rs b/src/lib.rs index 9c2658f..7b7efc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,11 +41,12 @@ //! 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` 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) @@ -62,8 +63,6 @@ //! * `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)] @@ -89,7 +88,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) -> Option { estimates .into_iter() @@ -103,11 +103,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: `://:@host:`. + /// The string should be formatted as: + /// `://:@host:`. /// - /// 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`. @@ -594,8 +596,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. From 1a4d5cf2c5271b722e115492557643dcab22df3f Mon Sep 17 00:00:00 2001 From: Leonardo Lima Date: Fri, 23 Aug 2024 13:51:13 -0300 Subject: [PATCH 4/4] chore(rust+clippy): bump `edition` to 2021, and add `.clippy.toml` - bumps the `edition` on `Cargo.toml` to `2021. - add `.clippy.toml` with `msrv=1.63.0` file. --- .clippy.toml | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..69478ce --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv="1.63.0" diff --git a/Cargo.toml b/Cargo.toml index f26c04c..1d90703 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "esplora-client" version = "0.9.0" -edition = "2018" +edition = "2021" authors = ["Alekos Filini "] license = "MIT" homepage = "https://github.com/bitcoindevkit/rust-esplora-client"