Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade and bump some CI dependencies #95

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv="1.63.0"
63 changes: 49 additions & 14 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: CI

on:
push:
Expand All @@ -11,13 +11,12 @@ env:

jobs:
build-test:

name: Build & Test
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- version: stable # STABLE
clippy: true
- version: 1.63.0 # MSRV
features:
- default
Expand All @@ -32,27 +31,27 @@ jobs:
- async-https-rustls
- async-https-rustls-manual-roots
steps:
- uses: actions/checkout@v3
- name: Checkout
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: |
~/.cargo/registry
~/.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
- 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"
Expand All @@ -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
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
format_code_in_doc_comments=true
wrap_comments=true
comment_width=100
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "esplora-client"
version = "0.9.0"
edition = "2018"
edition = "2021"
authors = ["Alekos Filini <[email protected]>"]
license = "MIT"
homepage = "https://github.com/bitcoindevkit/rust-esplora-client"
Expand Down
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
26 changes: 14 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)]

Expand All @@ -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<u16, f64>) -> Option<f32> {
estimates
.into_iter()
Expand All @@ -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: `<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 +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.
Expand Down
Loading