diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index fe1af12..5daf9e3 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -27,6 +27,9 @@ jobs: - async-https-native - async-https-rustls - async-https-rustls-manual-roots + - async-arti-hyper + - async-arti-hyper-native + - async-arti-hyper-rustls steps: - uses: actions/checkout@v3 - name: Generate cache key @@ -58,4 +61,4 @@ jobs: 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 + run: cargo test --features ${{ matrix.features }} --no-default-features -- --include-ignored diff --git a/src/async.rs b/src/async.rs index c5caf86..429e5ae 100644 --- a/src/async.rs +++ b/src/async.rs @@ -14,10 +14,6 @@ use std::collections::HashMap; use std::str::FromStr; -use arti_client::{TorClient, TorClientConfig}; - -use arti_hyper::ArtiHttpConnector; - use bitcoin::consensus::{deserialize, serialize}; use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256, Hash}; @@ -26,26 +22,38 @@ use bitcoin::{ }; use bitcoin_internals::hex::display::DisplayHex; -use hyper::{Body, Response, Uri}; #[allow(unused_imports)] use log::{debug, error, info, trace}; -use reqwest::{Client, StatusCode}; -use tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder}; +#[cfg(feature = "async")] +use reqwest::Client; + +#[cfg(feature = "async-arti-hyper")] +use { + arti_client::{TorClient, TorClientConfig}, + arti_hyper::ArtiHttpConnector, + hyper::{Body, Response, Uri}, + tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder}, + tor_rtcompat::PreferredRuntime, +}; + +#[cfg(feature = "async-arti-hyper")] #[cfg(not(target_vendor = "apple"))] use tls_api_native_tls::TlsConnector; +#[cfg(feature = "async-arti-hyper")] #[cfg(target_vendor = "apple")] use tls_api_openssl::TlsConnector; -use tor_rtcompat::PreferredRuntime; use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus}; +#[cfg(feature = "async")] #[derive(Debug, Clone)] pub struct AsyncClient { url: String, client: Client, } +#[cfg(feature = "async")] impl AsyncClient { /// build an async client from a builder pub fn from_builder(builder: Builder) -> Result { @@ -77,7 +85,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -112,7 +120,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -198,7 +206,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -220,7 +228,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -242,7 +250,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -269,7 +277,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -346,7 +354,7 @@ impl AsyncClient { .send() .await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let reqwest::StatusCode::NOT_FOUND = resp.status() { return Err(Error::HeaderHeightNotFound(block_height)); } @@ -441,12 +449,14 @@ impl AsyncClient { } } +#[cfg(feature = "async-arti-hyper")] #[derive(Debug, Clone)] pub struct AsyncAnonymizedClient { url: String, client: hyper::Client>, } +#[cfg(feature = "async-arti-hyper")] impl AsyncAnonymizedClient { /// build an async [`TorClient`] with default Tor configuration async fn create_tor_client() -> Result, arti_client::Error> { @@ -485,7 +495,7 @@ impl AsyncAnonymizedClient { let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -521,7 +531,7 @@ impl AsyncAnonymizedClient { let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -604,7 +614,7 @@ impl AsyncAnonymizedClient { let uri = Uri::from_str(&path).map_err(|_| Error::InvalidUri)?; let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -627,7 +637,7 @@ impl AsyncAnonymizedClient { let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -652,7 +662,7 @@ impl AsyncAnonymizedClient { let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -678,7 +688,7 @@ impl AsyncAnonymizedClient { let uri = Uri::from_str(path).map_err(|_| Error::InvalidUri)?; let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Ok(None); } @@ -697,6 +707,7 @@ impl AsyncAnonymizedClient { } } + // TODO: (@leonardo) // /// Broadcast a [`Transaction`] to Esplora // pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> { // let resp = self @@ -761,7 +772,7 @@ impl AsyncAnonymizedClient { let uri = Uri::from_str(path).map_err(|_| Error::InvalidUri)?; let resp = self.client.get(uri).await?; - if let StatusCode::NOT_FOUND = resp.status() { + if let hyper::StatusCode::NOT_FOUND = resp.status() { return Err(Error::HeaderHeightNotFound(block_height)); } diff --git a/src/lib.rs b/src/lib.rs index e170b9b..885ff54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,7 @@ use bitcoin::consensus; pub mod api; -#[cfg(feature = "async")] +#[cfg(any(feature = "async", feature = "async-arti-hyper"))] pub mod r#async; #[cfg(feature = "blocking")] pub mod blocking;