Skip to content

Commit

Permalink
Merge pull request #1 from bitcoinppl/remove-async-std-dep
Browse files Browse the repository at this point in the history
Remove async std dep
  • Loading branch information
praveenperera authored Oct 14, 2024
2 parents 1f4acad + fdc7aed commit b58826b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install grcov
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
- name: Test
run: cargo test -- --test-threads=1
run: cargo test --features tokio -- --test-threads=1
- name: Run grcov
run: mkdir coverage; grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '/*' -o ./coverage/lcov.info
- name: Generate HTML coverage report
Expand Down
96 changes: 51 additions & 45 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,74 @@ name: CI

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
build-test:
name: Build & Test
name: Build & Test ${{ matrix.runtime }}
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- version: stable # STABLE
- version: 1.63.0 # MSRV
runtime:
- blocking
- tokio
- async-std
features:
- default
- blocking
- blocking-https
- blocking-https-rustls
- blocking-https-native
- blocking-https-bundled
- async
- async-https
- async-https-native
- async-https-rustls
- async-https-rustls-manual-roots
- blocking
- blocking-https
- blocking-https-rustls
- blocking-https-native
- blocking-https-bundled
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate cache key
run: echo "${{ matrix.rust.version }} ${{ matrix.features }}" | tee .cache_key
- 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: Install Rust Toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.rust.version }}
- name: Set profile
run: rustup set profile minimal
- name: Update toolchain
run: rustup update
- 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"
cargo update -p time --precise "0.3.20"
cargo update -p home --precise 0.5.5
cargo update -p url --precise "2.5.0"
cargo update -p tokio --precise "1.38.1"
cargo update -p tokio-util --precise "0.7.11"
- name: Build
run: cargo build --features ${{ matrix.features }} --no-default-features
- name: Test
run: cargo test --features ${{ matrix.features }} --no-default-features -- --test-threads=1
- name: Checkout
uses: actions/checkout@v4
- name: Generate cache key
run: echo "${{ matrix.rust.version }} ${{ matrix.runtime }} ${{ matrix.features }}" | tee .cache_key
- 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: Install Rust Toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.rust.version }}
- name: Set profile
run: rustup set profile minimal
- name: Update toolchain
run: rustup update
- 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"
cargo update -p time --precise "0.3.20"
cargo update -p home --precise 0.5.5
cargo update -p url --precise "2.5.0"
cargo update -p tokio --precise "1.38.1"
cargo update -p hyper-rustls --precise "0.24.2"
- name: Build
run: cargo build --features ${{ matrix.features }},${{ matrix.runtime != 'blocking' && matrix.runtime || '' }} --no-default-features

- name: Test
run: cargo test --features ${{ matrix.features }},${{ matrix.runtime != 'blocking' && matrix.runtime || '' }} --no-default-features -- --test-threads=1

fmt:
name: Rust Formatting
Expand All @@ -74,8 +80,8 @@ jobs:
- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
components: rustfmt
toolchain: nightly
components: rustfmt
- name: Check fmt
run: cargo fmt --all --check

Expand All @@ -88,8 +94,8 @@ jobs:
- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: clippy
toolchain: stable
components: clippy
- name: Rust Cache
uses: actions/cache@v3
with:
Expand Down
16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,31 @@ bitcoin = { version = "0.32", features = ["serde", "std"], default-features = fa
hex = { version = "0.2", package = "hex-conservative" }
log = "^0.4"
minreq = { version = "2.11.0", features = ["json-using-serde"], optional = true }
reqwest = { version = "0.11", features = ["json"], default-features = false, optional = true }
async-std = { version = "1.13.0", optional = true }
reqwest = { version = "0.12", features = ["json"], default-features = false, optional = true }

# async runtime
async-std = { version = "1.13", optional = true }
tokio = { version = "1.38.1", features = ["time"], optional = true }

[dev-dependencies]

serde_json = "1.0"
tokio = { version = "1.20.1", features = ["full"] }
electrsd = { version = "0.28.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
lazy_static = "1.4.0"

[features]
default = ["blocking", "async", "async-https"]
default = ["blocking", "async", "async-https", "tokio"]
blocking = ["minreq", "minreq/proxy"]
blocking-https = ["blocking", "minreq/https"]
blocking-https-rustls = ["blocking", "minreq/https-rustls"]
blocking-https-native = ["blocking", "minreq/https-native"]
blocking-https-bundled = ["blocking", "minreq/https-bundled"]
async = ["async-std", "reqwest", "reqwest/socks"]

tokio = ["dep:tokio", "async"]
async-std = ["dep:async-std", "async"]

async = ["reqwest", "reqwest/socks"]
async-https = ["async", "reqwest/default-tls"]
async-https-native = ["async", "reqwest/native-tls"]
async-https-rustls = ["async", "reqwest/rustls-tls"]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Bitcoin Esplora API client library. Supports plaintext, TLS and Onion servers. Blocking or async.

If using the async client, you can choose between `tokio` or `async-std` as the runtime. One of these features must be enabled.

<p>
<a href="https://crates.io/crates/esplora-client"><img alt="Crate Info" src="https://img.shields.io/crates/v/esplora-client.svg"/></a>
<a href="https://github.com/bitcoindevkit/rust-esplora-client/blob/master/LICENSE"><img alt="MIT Licensed" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
Expand All @@ -25,4 +27,4 @@ cargo update -p home --precise 0.5.5
cargo update -p url --precise "2.5.0"
cargo update -p tokio --precise "1.38.1"
cargo update -p tokio-util --precise "0.7.11"
```
```
3 changes: 1 addition & 2 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

//! Esplora by way of `reqwest` HTTP client.
use async_std::task;
use std::collections::HashMap;
use std::str::FromStr;

Expand Down Expand Up @@ -434,7 +433,7 @@ impl AsyncClient {
loop {
match self.client.get(url).send().await? {
resp if attempts < self.max_retries && is_status_retryable(resp.status()) => {
task::sleep(delay).await;
crate::runtime::sleep(delay).await;
attempts += 1;
delay *= 2;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub mod api;
pub mod r#async;
#[cfg(feature = "blocking")]
pub mod blocking;
#[cfg(feature = "async")]
pub mod runtime;

pub use api::*;
#[cfg(feature = "blocking")]
Expand Down
8 changes: 8 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(feature = "tokio")]
pub use tokio::time::sleep;

#[cfg(feature = "async-std")]
pub use async_std::task::sleep;

#[cfg(not(any(feature = "tokio", feature = "async-std")))]
compile_error!("Either 'tokio' or 'async-std' feature must be enabled");

0 comments on commit b58826b

Please sign in to comment.