Skip to content
Draft
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
6 changes: 3 additions & 3 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
28 changes: 19 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,38 @@ 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 }

[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"]
Expand Down
20 changes: 10 additions & 10 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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<Request, Error> {
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())?;
Expand Down Expand Up @@ -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),
}
Expand All @@ -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::<T>(&hex_vec)
.map_err(Error::BitcoinEncoding)
Expand All @@ -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::<T>(&hex_vec).map_err(Error::BitcoinEncoding)
}
Expand All @@ -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::<T>().map_err(Error::Minreq)?),
Ok(resp) => Ok(resp.json()?),
Err(e) => Err(e),
}
}
Expand All @@ -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::<T>()?)),
Ok(resp) => Ok(Some(resp.json()?)),
Err(e) => Err(e),
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -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)),
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [(
Expand Down
Loading