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) ]
77use std:: io:: { self , Read , Write } ;
@@ -23,9 +23,9 @@ const DEFAULT_TIMEOUT_SECONDS: u64 = 15;
2323#[ cfg( jsonrpc_fuzz) ]
2424const 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 ) ]
101101pub struct Builder {
102- tp : MinreqHttpTransport ,
102+ tp : BitreqHttpTransport ,
103103}
104104
105105impl 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
158158impl Default for Builder {
@@ -185,8 +185,8 @@ impl error::Error for HttpError {}
185185pub 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
224224impl From < Error > for crate :: Error {
0 commit comments