diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 28bb0816..aed27c07 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -23,8 +23,8 @@ jobs: - blocking - blocking-https - blocking-https-rustls - - blocking-https-native - - blocking-https-bundled + # - blocking-https-native + # - blocking-https-bundled - async - async-https - async-https-native @@ -55,7 +55,7 @@ jobs: if: matrix.rust.version == '1.63.0' run: | cargo update -p reqwest --precise "0.12.4" - cargo update -p minreq --precise "2.13.2" + # cargo update -p minreq --precise "2.13.2" cargo update -p home --precise "0.5.5" cargo update -p url --precise "2.5.0" cargo update -p tokio --precise "1.38.1" diff --git a/Cargo.toml b/Cargo.toml index 8438b5ce..c4a2d193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,11 +18,16 @@ path = "src/lib.rs" [dependencies] serde = { version = "1.0", features = ["derive"] } -bitcoin = { version = "0.32", features = ["serde", "std"], default-features = false } +bitcoin = { version = "0.32", features = [ + "serde", + "std", +], default-features = false } hex = { version = "0.2", package = "hex-conservative" } log = "^0.4" -minreq = { version = "2.11.0", features = ["json-using-serde"], optional = true } -reqwest = { version = "0.12", features = ["json"], default-features = false, optional = true } +reqwest = { version = "0.12", features = [ + "json", +], default-features = false, optional = true } +bitreq = { git = "https://github.com/tcharding/corepc.git", package = "bitreq", branch = "push-rvqmqwwmqtvm", optional = true } # default async runtime tokio = { version = "1", features = ["time"], optional = true } @@ -30,16 +35,21 @@ tokio = { version = "1", features = ["time"], optional = true } [dev-dependencies] serde_json = "1.0" tokio = { version = "1.20.1", features = ["full"] } -electrsd = { version = "0.33.0", features = ["legacy", "esplora_a33e97e1", "corepc-node_28_0"] } +electrsd = { version = "0.33.0", features = [ + "legacy", + "esplora_a33e97e1", + "corepc-node_28_0", +] } lazy_static = "1.4.0" [features] 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"] +blocking = ["bitreq", "bitreq/proxy", "bitreq/json-using-serde"] +blocking-https = ["blocking", "bitreq/https"] +blocking-https-rustls = ["blocking", "bitreq/https-rustls"] +# TODO: (@oleonardolima) do we still need these features/support ? are they being used for wasm ? +# blocking-https-native = ["blocking", "minreq/https-native"] +# blocking-https-bundled = ["blocking", "minreq/https-bundled"] tokio = ["dep:tokio"] async = ["reqwest", "reqwest/socks", "tokio?/time"] diff --git a/src/blocking.rs b/src/blocking.rs index b959c858..63937a56 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -9,7 +9,7 @@ // You may not use this file except in accordance with one or both of these // licenses. -//! Esplora by way of `minreq` HTTP client. +//! Esplora by way of `bitreq` HTTP client. use std::collections::HashMap; use std::convert::TryFrom; @@ -19,7 +19,7 @@ use std::thread; #[allow(unused_imports)] use log::{debug, error, info, trace}; -use minreq::{Proxy, Request, Response}; +use bitreq::{Proxy, Request, Response}; use bitcoin::consensus::{deserialize, serialize, Decodable}; use bitcoin::hashes::{sha256, Hash}; @@ -68,7 +68,7 @@ impl BlockingClient { /// Perform a raw HTTP GET request with the given URI `path`. pub fn get_request(&self, path: &str) -> Result { - let mut request = minreq::get(format!("{}{}", self.url, path)); + let mut request = bitreq::get(format!("{}{}", self.url, path)); if let Some(proxy) = &self.proxy { let proxy = Proxy::new(proxy.as_str())?; @@ -110,7 +110,7 @@ impl BlockingClient { Err(Error::HttpResponse { status, message }) } Ok(resp) => Ok(Some( - Txid::from_str(resp.as_str().map_err(Error::Minreq)?).map_err(Error::HexToArray)?, + Txid::from_str(resp.as_str().map_err(Error::BitReq)?).map_err(Error::HexToArray)?, )), Err(e) => Err(e), } @@ -125,7 +125,7 @@ impl BlockingClient { Err(Error::HttpResponse { status, message }) } Ok(resp) => { - let hex_str = resp.as_str().map_err(Error::Minreq)?; + let hex_str = resp.as_str().map_err(Error::BitReq)?; let hex_vec = Vec::from_hex(hex_str).unwrap(); deserialize::(&hex_vec) .map_err(Error::BitcoinEncoding) @@ -143,7 +143,7 @@ impl BlockingClient { Err(Error::HttpResponse { status, message }) } Ok(resp) => { - let hex_str = resp.as_str().map_err(Error::Minreq)?; + let hex_str = resp.as_str().map_err(Error::BitReq)?; let hex_vec = Vec::from_hex(hex_str).unwrap(); deserialize::(&hex_vec).map_err(Error::BitcoinEncoding) } @@ -162,7 +162,7 @@ impl BlockingClient { let message = resp.as_str().unwrap_or_default().to_string(); Err(Error::HttpResponse { status, message }) } - Ok(resp) => Ok(resp.json::().map_err(Error::Minreq)?), + Ok(resp) => Ok(resp.json()?), Err(e) => Err(e), } } @@ -178,7 +178,7 @@ impl BlockingClient { let message = resp.as_str().unwrap_or_default().to_string(); Err(Error::HttpResponse { status, message }) } - Ok(resp) => Ok(Some(resp.json::()?)), + Ok(resp) => Ok(Some(resp.json()?)), Err(e) => Err(e), } } @@ -268,7 +268,7 @@ impl BlockingClient { /// Broadcast a [`Transaction`] to Esplora pub fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> { - let mut request = minreq::post(format!("{}/tx", self.url)).with_body( + let mut request = bitreq::post(format!("{}/tx", self.url)).with_body( serialize(transaction) .to_lower_hex_string() .as_bytes() @@ -291,7 +291,7 @@ impl BlockingClient { Err(Error::HttpResponse { status, message }) } Ok(_resp) => Ok(()), - Err(e) => Err(Error::Minreq(e)), + Err(e) => Err(Error::BitReq(e)), } } diff --git a/src/lib.rs b/src/lib.rs index 51bc6869..4a786372 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,14 +65,14 @@ //! certificates. //! //! [`dont remove this line or cargo doc will break`]: https://example.com -#![cfg_attr(not(feature = "minreq"), doc = "[`minreq`]: https://docs.rs/minreq")] +#![cfg_attr(not(feature = "bitreq"), doc = "[`bitreq`]: https://docs.rs/bitreq")] #![cfg_attr(not(feature = "reqwest"), doc = "[`reqwest`]: https://docs.rs/reqwest")] #![allow(clippy::result_large_err)] use std::collections::HashMap; -use std::fmt; use std::num::TryFromIntError; use std::time::Duration; +use std::{fmt, str}; #[cfg(feature = "async")] pub use r#async::Sleeper; @@ -89,6 +89,9 @@ pub use blocking::BlockingClient; #[cfg(feature = "async")] pub use r#async::AsyncClient; +// #[cfg(feature = "bitreq")] +// use crate::bitreq::; + /// Response status codes for which the request may be retried. pub const RETRYABLE_ERROR_CODES: [u16; 3] = [ 429, // TOO_MANY_REQUESTS @@ -200,9 +203,9 @@ impl Builder { /// Errors that can happen during a request to `Esplora` servers. #[derive(Debug)] pub enum Error { - /// Error during `minreq` HTTP request + /// Error during `bitreq` HTTP request #[cfg(feature = "blocking")] - Minreq(::minreq::Error), + BitReq(::bitreq::Error), /// Error during reqwest HTTP request #[cfg(feature = "async")] Reqwest(::reqwest::Error), @@ -253,7 +256,7 @@ macro_rules! impl_error { impl std::error::Error for Error {} #[cfg(feature = "blocking")] -impl_error!(::minreq::Error, Minreq, Error); +impl_error!(::bitreq::Error, BitReq, Error); #[cfg(feature = "async")] impl_error!(::reqwest::Error, Reqwest, Error); impl_error!(std::num::ParseIntError, Parsing, Error); @@ -325,7 +328,7 @@ mod test { let mut builder = Builder::new(&format!("http://{esplora_url}")); if !headers.is_empty() { - builder.headers = headers; + builder.headers = headers.clone(); } let blocking_client = builder.build_blocking(); @@ -951,7 +954,7 @@ mod test { assert_eq!(blocks_genesis, blocks_genesis_async); } - #[cfg(all(feature = "blocking", feature = "async"))] + #[cfg(all(feature = "blocking", feature = "async", feature = "bitreq"))] #[tokio::test] async fn test_get_tx_with_http_header() { let headers = [(