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

feat: add new AsyncAnonymizedClient using arti-hyper #67

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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: stable
components: rustfmt
- name: Check fmt
run: cargo fmt --all -- --config format_code_in_doc_comments=true,wrap_comments=true --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
48 changes: 43 additions & 5 deletions 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 All @@ -19,26 +19,64 @@ path = "src/lib.rs"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
bitcoin = { version = "0.32", features = ["serde", "std"], default-features = false }
hex = { package = "hex-conservative", version = "0.2" }
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", optional = true, default-features = false, features = ["json"] }
reqwest = { version = "0.11", features = ["json"], default-features = false, optional = true }

arti-client = { version = "0.21.0", default-features = false, optional = true }
tor-rtcompat = { version = "0.21.0", default-features = false, optional = true }
hyper = { version = "1.4.1", features = ["client", "http1"], default-features = false, optional = true }
hyper-util = { version = "0.1.7", features = ["tokio"], default-features = false, optional = true }
tokio = { version = "1.38.1", optional = true }
http-body-util = { version = "0.1.2", optional = true}
http = { version = "1.1.0", optional = true }
serde_json = { version = "1.0.127", optional = true }
tokio-rustls = { version = "0.26.0", default-features = false, features = [
"logging",
"tls12",
"ring",
], optional = true }
webpki-roots = { version = "0.26.3", optional = true }
rustls-pki-types = { version = "1.8.0", 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", "async-tor"]
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 = ["reqwest", "reqwest/socks"]
async-https = ["async", "reqwest/default-tls"]
async-https-native = ["async", "reqwest/native-tls"]
async-https-rustls = ["async", "reqwest/rustls-tls"]
async-https-rustls-manual-roots = ["async", "reqwest/rustls-tls-manual-roots"]

async-tor = [
"dep:arti-client",
"arti-client/tokio",
"arti-client/onion-service-client",
"arti-client/native-tls",

"dep:tor-rtcompat",
"tor-rtcompat/tokio",

"dep:hyper",
"dep:hyper-util",
"dep:tokio",
"dep:http-body-util",
"dep:http",
"dep:serde_json",
"dep:tokio-rustls",
"dep:webpki-roots",
"dep:rustls-pki-types"
]
async-tor-https-native = ["async-tor", "arti-client/native-tls"]
async-tor-https-rustls = ["async-tor", "arti-client/rustls"]
28 changes: 28 additions & 0 deletions examples/tor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use bitcoin::{consensus::encode::deserialize_hex, Transaction};
use esplora_client::{r#async_tor::AsyncTorClient, Builder};

extern crate esplora_client;

// const MEMPOOL_SPACE_API: &str = "https://mempool.space/api";
const MEMPOOL_SPACE_API: &str = "https://blockstream.info/api";

#[tokio::main]
async fn main() {
let builder = Builder::new(MEMPOOL_SPACE_API);
let esplora_client = AsyncTorClient::from_builder(builder).await.unwrap();

let raw_tx = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000";
let tx: Transaction = deserialize_hex(raw_tx).unwrap();
esplora_client.broadcast(&tx).await.unwrap();

print!(
"successfully broadcasted transaction, with txid: {:?}",
tx.compute_txid()
);

// let tx_id =
// Txid::from_str("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b").unwrap();
// let tx = esplora_client.get_tx(&tx_id).await.unwrap().unwrap();

// println!("successfully fetched the transaction {:?}", tx);
}
4 changes: 2 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! structs from the esplora API
//! Structs from the Esplora API
//!
//! see: <https://github.com/Blockstream/esplora/blob/master/API.md>
//! See: <https://github.com/Blockstream/esplora/blob/master/API.md>

pub use bitcoin::consensus::{deserialize, serialize};
pub use bitcoin::hex::FromHex;
Expand Down
Loading