Skip to content

Commit 11d27c8

Browse files
committed
jsonrpc: Depend on bitreq
We just forked `minreq` into this repository to create an HTTP crate that is specifically designed to be used by Bitcoin projects. As such we called it `bitreq`. Depend on the local `bitreq` crate instead of `minreq`.
1 parent e45e36b commit 11d27c8

File tree

5 files changed

+39
-39
lines changed

5 files changed

+39
-39
lines changed

jsonrpc/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ rustdoc-args = ["--cfg", "docsrs"]
2020
default = [ "simple_http", "simple_tcp" ]
2121
# A bare-minimum HTTP transport.
2222
simple_http = [ "base64" ]
23-
# A transport that uses `minreq` as the HTTP client.
24-
minreq_http = [ "base64", "minreq" ]
23+
# A transport that uses `bitreq` as the HTTP client.
24+
bitreq_http = [ "base64", "bitreq" ]
2525
# Basic transport over a raw TcpListener
2626
simple_tcp = []
2727
# Basic transport over a raw UnixStream
@@ -34,7 +34,7 @@ serde = { version = "1", features = ["derive"] }
3434
serde_json = { version = "1", features = [ "raw_value" ] }
3535

3636
base64 = { version = "0.22.1", optional = true }
37-
minreq = { version = "2.7.0", features = ["json-using-serde"], optional = true }
37+
bitreq = { version = "0.1.0", path = "../bitreq", features = ["json-using-serde"], optional = true }
3838
socks = { version = "0.3.4", optional = true}
3939

4040
[lints.rust]

jsonrpc/contrib/test_vars.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
FEATURES_WITH_STD=""
55

66
# So this is the var to use for all tests.
7-
FEATURES_WITHOUT_STD="simple_http minreq_http simple_tcp simple_uds proxy"
7+
FEATURES_WITHOUT_STD="simple_http bitreq_http simple_tcp simple_uds proxy"
88

99
# Run these examples.
1010
EXAMPLES=""

jsonrpc/src/http/minreq_http.rs renamed to jsonrpc/src/http/bitreq_http.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! This module implements the [`crate::client::Transport`] trait using [`minreq`]
1+
//! This module implements the [`crate::client::Transport`] trait using [`bitreq`]
22
//! as the underlying HTTP transport.
33
//!
4-
//! [minreq]: <https://github.com/neonmoe/minreq>
4+
//! [bitreq]: <https://github.com/rust-bitcoin/corepc/bitreq>
55
66
#[cfg(jsonrpc_fuzz)]
77
use std::io::{self, Read, Write};
@@ -23,9 +23,9 @@ const DEFAULT_TIMEOUT_SECONDS: u64 = 15;
2323
#[cfg(jsonrpc_fuzz)]
2424
const DEFAULT_TIMEOUT_SECONDS: u64 = 1;
2525

26-
/// An HTTP transport that uses [`minreq`] and is useful for running a bitcoind RPC client.
26+
/// An HTTP transport that uses [`bitreq`] and is useful for running a bitcoind RPC client.
2727
#[derive(Clone, Debug)]
28-
pub struct MinreqHttpTransport {
28+
pub struct BitreqHttpTransport {
2929
/// URL of the RPC server.
3030
url: String,
3131
/// Timeout only supports second granularity.
@@ -34,33 +34,33 @@ pub struct MinreqHttpTransport {
3434
basic_auth: Option<String>,
3535
}
3636

37-
impl Default for MinreqHttpTransport {
37+
impl Default for BitreqHttpTransport {
3838
fn default() -> Self {
39-
MinreqHttpTransport {
39+
BitreqHttpTransport {
4040
url: format!("{}:{}", DEFAULT_URL, DEFAULT_PORT),
4141
timeout: Duration::from_secs(DEFAULT_TIMEOUT_SECONDS),
4242
basic_auth: None,
4343
}
4444
}
4545
}
4646

47-
impl MinreqHttpTransport {
48-
/// Constructs a new [`MinreqHttpTransport`] with default parameters.
49-
pub fn new() -> Self { MinreqHttpTransport::default() }
47+
impl BitreqHttpTransport {
48+
/// Constructs a new [`BitreqHttpTransport`] with default parameters.
49+
pub fn new() -> Self { BitreqHttpTransport::default() }
5050

51-
/// Returns a builder for [`MinreqHttpTransport`].
51+
/// Returns a builder for [`BitreqHttpTransport`].
5252
pub fn builder() -> Builder { Builder::new() }
5353

5454
fn request<R>(&self, req: impl serde::Serialize) -> Result<R, Error>
5555
where
5656
R: for<'a> serde::de::Deserialize<'a>,
5757
{
5858
let req = match &self.basic_auth {
59-
Some(auth) => minreq::Request::new(minreq::Method::Post, &self.url)
59+
Some(auth) => bitreq::Request::new(bitreq::Method::Post, &self.url)
6060
.with_timeout(self.timeout.as_secs())
6161
.with_header("Authorization", auth)
6262
.with_json(&req)?,
63-
None => minreq::Request::new(minreq::Method::Post, &self.url)
63+
None => bitreq::Request::new(bitreq::Method::Post, &self.url)
6464
.with_timeout(self.timeout.as_secs())
6565
.with_json(&req)?,
6666
};
@@ -71,20 +71,20 @@ impl MinreqHttpTransport {
7171
let resp = req.send()?;
7272
match resp.json() {
7373
Ok(json) => Ok(json),
74-
Err(minreq_err) =>
74+
Err(bitreq_err) =>
7575
if resp.status_code != 200 {
7676
Err(Error::Http(HttpError {
7777
status_code: resp.status_code,
7878
body: resp.as_str().unwrap_or("").to_string(),
7979
}))
8080
} else {
81-
Err(Error::Minreq(minreq_err))
81+
Err(Error::Bitreq(bitreq_err))
8282
},
8383
}
8484
}
8585
}
8686

87-
impl Transport for MinreqHttpTransport {
87+
impl Transport for BitreqHttpTransport {
8888
fn send_request(&self, req: Request) -> Result<Response, crate::Error> {
8989
Ok(self.request(req)?)
9090
}
@@ -96,15 +96,15 @@ impl Transport for MinreqHttpTransport {
9696
fn fmt_target(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.url) }
9797
}
9898

99-
/// Builder for simple bitcoind [`MinreqHttpTransport`].
99+
/// Builder for simple bitcoind [`BitreqHttpTransport`].
100100
#[derive(Clone, Debug)]
101101
pub struct Builder {
102-
tp: MinreqHttpTransport,
102+
tp: BitreqHttpTransport,
103103
}
104104

105105
impl Builder {
106106
/// Constructs a new [`Builder`] with default configuration and the URL to use.
107-
pub fn new() -> Builder { Builder { tp: MinreqHttpTransport::new() } }
107+
pub fn new() -> Builder { Builder { tp: BitreqHttpTransport::new() } }
108108

109109
/// Sets the timeout after which requests will abort if they aren't finished.
110110
pub fn timeout(mut self, timeout: Duration) -> Self {
@@ -137,22 +137,22 @@ impl Builder {
137137
/// # Examples
138138
///
139139
/// ```no_run
140-
/// # use jsonrpc::minreq_http::MinreqHttpTransport;
140+
/// # use jsonrpc::bitreq_http::BitreqHttpTransport;
141141
/// # use std::fs::{self, File};
142142
/// # use std::path::Path;
143143
/// # let cookie_file = Path::new("~/.bitcoind/.cookie");
144144
/// let mut file = File::open(cookie_file).expect("couldn't open cookie file");
145145
/// let mut cookie = String::new();
146146
/// fs::read_to_string(&mut cookie).expect("couldn't read cookie file");
147-
/// let client = MinreqHttpTransport::builder().cookie_auth(cookie);
147+
/// let client = BitreqHttpTransport::builder().cookie_auth(cookie);
148148
/// ```
149149
pub fn cookie_auth<S: AsRef<str>>(mut self, cookie: S) -> Self {
150150
self.tp.basic_auth = Some(format!("Basic {}", &BASE64.encode(cookie.as_ref().as_bytes())));
151151
self
152152
}
153153

154-
/// Builds the final [`MinreqHttpTransport`].
155-
pub fn build(self) -> MinreqHttpTransport { self.tp }
154+
/// Builds the final [`BitreqHttpTransport`].
155+
pub fn build(self) -> BitreqHttpTransport { self.tp }
156156
}
157157

158158
impl Default for Builder {
@@ -185,8 +185,8 @@ impl error::Error for HttpError {}
185185
pub enum Error {
186186
/// JSON parsing error.
187187
Json(serde_json::Error),
188-
/// Minreq error.
189-
Minreq(minreq::Error),
188+
/// Bitreq error.
189+
Bitreq(bitreq::Error),
190190
/// HTTP error that does not contain valid JSON as body.
191191
Http(HttpError),
192192
}
@@ -195,7 +195,7 @@ impl fmt::Display for Error {
195195
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
196196
match *self {
197197
Error::Json(ref e) => write!(f, "parsing JSON failed: {}", e),
198-
Error::Minreq(ref e) => write!(f, "minreq: {}", e),
198+
Error::Bitreq(ref e) => write!(f, "bitreq: {}", e),
199199
Error::Http(ref e) => write!(f, "http ({})", e),
200200
}
201201
}
@@ -207,7 +207,7 @@ impl error::Error for Error {
207207

208208
match *self {
209209
Json(ref e) => Some(e),
210-
Minreq(ref e) => Some(e),
210+
Bitreq(ref e) => Some(e),
211211
Http(ref e) => Some(e),
212212
}
213213
}
@@ -217,8 +217,8 @@ impl From<serde_json::Error> for Error {
217217
fn from(e: serde_json::Error) -> Self { Error::Json(e) }
218218
}
219219

220-
impl From<minreq::Error> for Error {
221-
fn from(e: minreq::Error) -> Self { Error::Minreq(e) }
220+
impl From<bitreq::Error> for Error {
221+
fn from(e: bitreq::Error) -> Self { Error::Bitreq(e) }
222222
}
223223

224224
impl From<Error> for crate::Error {

jsonrpc/src/http/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#[cfg(feature = "simple_http")]
44
pub mod simple_http;
55

6-
#[cfg(feature = "minreq_http")]
7-
pub mod minreq_http;
6+
#[cfg(feature = "bitreq_http")]
7+
pub mod bitreq_http;
88

99
/// The default TCP port to use for connections.
1010
/// Set to 8332, the default RPC port for bitcoind.

jsonrpc/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ pub extern crate serde_json;
1717
#[cfg(feature = "base64")]
1818
pub extern crate base64;
1919

20-
/// Re-export `minreq` crate if the feature is set.
21-
#[cfg(feature = "minreq")]
22-
pub extern crate minreq;
20+
/// Re-export `bitreq` crate if the feature is set.
21+
#[cfg(feature = "bitreq")]
22+
pub extern crate bitreq;
2323

2424
pub mod client;
2525
pub mod error;
2626
pub mod http;
2727

28-
#[cfg(feature = "minreq_http")]
29-
pub use http::minreq_http;
28+
#[cfg(feature = "bitreq_http")]
29+
pub use http::bitreq_http;
3030
#[cfg(feature = "simple_http")]
3131
pub use http::simple_http;
3232

0 commit comments

Comments
 (0)