Skip to content

Commit 000bf67

Browse files
committed
refactor(client)!: use bitreq for BlockingClient
- update the `BlockingClient` to use `bitreq` instead of `minreq`
1 parent 91e02d8 commit 000bf67

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ serde_json = { version = "1.0", default-features = false }
2525
bitcoin = { version = "0.32", features = ["serde", "std"], default-features = false }
2626
hex = { version = "0.2", package = "hex-conservative" }
2727
log = "^0.4"
28-
minreq = { version = "2.11.0", features = ["json-using-serde"], optional = true }
2928
reqwest = { version = "0.12", features = ["json"], default-features = false, optional = true }
29+
bitreq = { version = "0.3.4", optional = true }
3030

3131
# default async runtime
3232
tokio = { version = "1", features = ["time"], optional = true }
@@ -38,11 +38,11 @@ lazy_static = "1.4.0"
3838

3939
[features]
4040
default = ["blocking", "async", "async-https", "tokio"]
41-
blocking = ["minreq", "minreq/proxy"]
42-
blocking-https = ["blocking", "minreq/https"]
43-
blocking-https-rustls = ["blocking", "minreq/https-rustls"]
44-
blocking-https-native = ["blocking", "minreq/https-native"]
45-
blocking-https-bundled = ["blocking", "minreq/https-bundled"]
41+
blocking = ["bitreq", "bitreq/proxy", "bitreq/json-using-serde"]
42+
blocking-https = ["blocking", "bitreq/https"]
43+
blocking-https-native = ["blocking", "bitreq/https-native-tls"]
44+
blocking-https-rustls = ["blocking", "bitreq/https-rustls"]
45+
blocking-https-rustls-probe = ["blocking", "bitreq/https-rustls-probe"]
4646

4747
tokio = ["dep:tokio"]
4848
async = ["reqwest", "reqwest/socks", "tokio?/time"]

src/blocking.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ use std::str::FromStr;
1717
use std::thread;
1818

1919
use bitcoin::consensus::encode::serialize_hex;
20+
use bitreq::{Proxy, Request, Response};
2021
#[allow(unused_imports)]
2122
use log::{debug, error, info, trace};
2223

23-
use minreq::{Proxy, Request, Response};
24-
2524
use bitcoin::block::Header as BlockHeader;
2625
use bitcoin::consensus::{deserialize, serialize, Decodable};
2726
use bitcoin::hashes::{sha256, Hash};
@@ -68,10 +67,10 @@ impl BlockingClient {
6867

6968
/// Perform a raw HTTP GET request with the given URI `path`.
7069
pub fn get_request(&self, path: &str) -> Result<Request, Error> {
71-
let mut request = minreq::get(format!("{}{}", self.url, path));
70+
let mut request = bitreq::get(format!("{}{}", self.url, path));
7271

7372
if let Some(proxy) = &self.proxy {
74-
let proxy = Proxy::new(proxy.as_str())?;
73+
let proxy = Proxy::new_http(proxy.as_str())?;
7574
request = request.with_proxy(proxy);
7675
}
7776

@@ -92,10 +91,10 @@ impl BlockingClient {
9291
where
9392
T: Into<Vec<u8>>,
9493
{
95-
let mut request = minreq::post(format!("{}{}", self.url, path)).with_body(body);
94+
let mut request = bitreq::post(format!("{}{}", self.url, path)).with_body(body);
9695

9796
if let Some(proxy) = &self.proxy {
98-
let proxy = Proxy::new(proxy.as_str())?;
97+
let proxy = Proxy::new_http(proxy.as_str())?;
9998
request = request.with_proxy(proxy);
10099
}
101100

@@ -128,7 +127,7 @@ impl BlockingClient {
128127
Err(Error::HttpResponse { status, message })
129128
}
130129
Ok(resp) => Ok(Some(
131-
Txid::from_str(resp.as_str().map_err(Error::Minreq)?).map_err(Error::HexToArray)?,
130+
Txid::from_str(resp.as_str().map_err(Error::BitReq)?).map_err(Error::HexToArray)?,
132131
)),
133132
Err(e) => Err(e),
134133
}
@@ -143,7 +142,7 @@ impl BlockingClient {
143142
Err(Error::HttpResponse { status, message })
144143
}
145144
Ok(resp) => {
146-
let hex_str = resp.as_str().map_err(Error::Minreq)?;
145+
let hex_str = resp.as_str().map_err(Error::BitReq)?;
147146
let hex_vec = Vec::from_hex(hex_str)?;
148147
deserialize::<T>(&hex_vec)
149148
.map_err(Error::BitcoinEncoding)
@@ -161,7 +160,7 @@ impl BlockingClient {
161160
Err(Error::HttpResponse { status, message })
162161
}
163162
Ok(resp) => {
164-
let hex_str = resp.as_str().map_err(Error::Minreq)?;
163+
let hex_str = resp.as_str().map_err(Error::BitReq)?;
165164
let hex_vec = Vec::from_hex(hex_str)?;
166165
deserialize::<T>(&hex_vec).map_err(Error::BitcoinEncoding)
167166
}
@@ -180,7 +179,7 @@ impl BlockingClient {
180179
let message = resp.as_str().unwrap_or_default().to_string();
181180
Err(Error::HttpResponse { status, message })
182181
}
183-
Ok(resp) => Ok(resp.json::<T>().map_err(Error::Minreq)?),
182+
Ok(resp) => Ok(resp.json::<T>().map_err(Error::BitReq)?),
184183
Err(e) => Err(e),
185184
}
186185
}
@@ -309,7 +308,7 @@ impl BlockingClient {
309308
let txid = Txid::from_str(resp.as_str()?).map_err(Error::HexToArray)?;
310309
Ok(txid)
311310
}
312-
Err(e) => Err(Error::Minreq(e)),
311+
Err(e) => Err(Error::BitReq(e)),
313312
}
314313
}
315314

@@ -353,8 +352,8 @@ impl BlockingClient {
353352
let message = resp.as_str().unwrap_or_default().to_string();
354353
Err(Error::HttpResponse { status, message })
355354
}
356-
Ok(resp) => Ok(resp.json::<SubmitPackageResult>().map_err(Error::Minreq)?),
357-
Err(e) => Err(Error::Minreq(e)),
355+
Ok(resp) => Ok(resp.json::<SubmitPackageResult>().map_err(Error::BitReq)?),
356+
Err(e) => Err(Error::BitReq(e)),
358357
}
359358
}
360359

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! async Esplora client to query Esplora's backend.
55
//!
66
//! The library provides the possibility to build a blocking
7-
//! client using [`minreq`] and an async client using [`reqwest`].
7+
//! client using [`bitreq`] and an async client using [`reqwest`].
88
//! The library supports communicating to Esplora via a proxy
99
//! and also using TLS (SSL) for secure communication.
1010
//!
@@ -44,14 +44,14 @@
4444
//! `esplora-client = { version = "*", default-features = false, features =
4545
//! ["blocking"] }`
4646
//!
47-
//! * `blocking` enables [`minreq`], the blocking client with proxy.
48-
//! * `blocking-https` enables [`minreq`], the blocking client with proxy and TLS (SSL) capabilities
49-
//! using the default [`minreq`] backend.
50-
//! * `blocking-https-rustls` enables [`minreq`], the blocking client with proxy and TLS (SSL)
47+
//! * `blocking` enables [`bitreq`], the blocking client with proxy.
48+
//! * `blocking-https` enables [`bitreq`], the blocking client with proxy and TLS (SSL) capabilities
49+
//! using the default [`bitreq`] backend.
50+
//! * `blocking-https-rustls` enables [`bitreq`], the blocking client with proxy and TLS (SSL)
5151
//! capabilities using the `rustls` backend.
52-
//! * `blocking-https-native` enables [`minreq`], the blocking client with proxy and TLS (SSL)
52+
//! * `blocking-https-native` enables [`bitreq`], the blocking client with proxy and TLS (SSL)
5353
//! capabilities using the platform's native TLS backend (likely OpenSSL).
54-
//! * `blocking-https-bundled` enables [`minreq`], the blocking client with proxy and TLS (SSL)
54+
//! * `blocking-https-bundled` enables [`bitreq`], the blocking client with proxy and TLS (SSL)
5555
//! capabilities using a bundled OpenSSL library backend.
5656
//! * `async` enables [`reqwest`], the async client with proxy capabilities.
5757
//! * `async-https` enables [`reqwest`], the async client with support for proxying and TLS (SSL)
@@ -65,7 +65,7 @@
6565
//! certificates.
6666
//!
6767
//! [`dont remove this line or cargo doc will break`]: https://example.com
68-
#![cfg_attr(not(feature = "minreq"), doc = "[`minreq`]: https://docs.rs/minreq")]
68+
#![cfg_attr(not(feature = "bitreq"), doc = "[`bitreq`]: https://docs.rs/bitreq")]
6969
#![cfg_attr(not(feature = "reqwest"), doc = "[`reqwest`]: https://docs.rs/reqwest")]
7070
#![allow(clippy::result_large_err)]
7171
#![warn(missing_docs)]
@@ -202,9 +202,9 @@ impl Builder {
202202
/// Errors that can happen during a request to `Esplora` servers.
203203
#[derive(Debug)]
204204
pub enum Error {
205-
/// Error during `minreq` HTTP request
205+
/// Error during `bitreq` HTTP request
206206
#[cfg(feature = "blocking")]
207-
Minreq(minreq::Error),
207+
BitReq(bitreq::Error),
208208
/// Error during `reqwest` HTTP request
209209
#[cfg(feature = "async")]
210210
Reqwest(reqwest::Error),
@@ -262,7 +262,7 @@ macro_rules! impl_error {
262262

263263
impl std::error::Error for Error {}
264264
#[cfg(feature = "blocking")]
265-
impl_error!(::minreq::Error, Minreq, Error);
265+
impl_error!(::bitreq::Error, BitReq, Error);
266266
#[cfg(feature = "async")]
267267
impl_error!(::reqwest::Error, Reqwest, Error);
268268
impl_error!(serde_json::Error, SerdeJson, Error);

0 commit comments

Comments
 (0)