@@ -14,14 +14,14 @@ use crate::{Request, Response};
1414
1515const DEFAULT_URL : & str = "http://localhost" ;
1616const DEFAULT_PORT : u16 = 8332 ; // the default RPC port for bitcoind.
17- const DEFAULT_TIMEOUT_SECONDS : u64 = 15 ;
17+ const DEFAULT_TIMEOUT : Duration = Duration :: from_secs ( 15 ) ;
1818
1919/// An HTTP transport that uses [`bitreq`] and is useful for running a bitcoind RPC client.
2020#[ derive( Clone , Debug ) ]
2121pub struct BitreqHttpTransport {
2222 /// URL of the RPC server.
2323 url : String ,
24- /// Timeout only supports second granularity .
24+ /// Timeout to use for HTTP requests .
2525 timeout : Duration ,
2626 /// The value of the `Authorization` HTTP header, i.e., a base64 encoding of 'user:password'.
2727 basic_auth : Option < String > ,
@@ -31,7 +31,7 @@ impl Default for BitreqHttpTransport {
3131 fn default ( ) -> Self {
3232 BitreqHttpTransport {
3333 url : format ! ( "{}:{}" , DEFAULT_URL , DEFAULT_PORT ) ,
34- timeout : Duration :: from_secs ( DEFAULT_TIMEOUT_SECONDS ) ,
34+ timeout : DEFAULT_TIMEOUT ,
3535 basic_auth : None ,
3636 }
3737 }
@@ -44,16 +44,6 @@ impl BitreqHttpTransport {
4444 /// Returns a builder for [`BitreqHttpTransport`].
4545 pub fn builder ( ) -> Builder { Builder :: new ( ) }
4646
47- /// Returns the timeout in whole seconds, rounding positive sub-second values up to one.
48- fn timeout_secs ( & self ) -> u64 {
49- let secs = self . timeout . as_secs ( ) ;
50- if secs == 0 && self . timeout > Duration :: from_secs ( 0 ) {
51- 1
52- } else {
53- secs
54- }
55- }
56-
5747 async fn request < R > ( & self , req : impl serde:: Serialize ) -> Result < R , crate :: Error >
5848 where
5949 R : for < ' a > serde:: de:: Deserialize < ' a > ,
@@ -65,15 +55,13 @@ impl BitreqHttpTransport {
6555 where
6656 R : for < ' a > serde:: de:: Deserialize < ' a > ,
6757 {
68- let timeout_secs = self . timeout_secs ( ) ;
69-
7058 let req = match & self . basic_auth {
7159 Some ( auth) => bitreq:: Request :: new ( bitreq:: Method :: Post , & self . url )
72- . with_timeout ( timeout_secs )
60+ . with_timeout ( self . timeout )
7361 . with_header ( "Authorization" , auth)
7462 . with_json ( & req) ?,
7563 None => bitreq:: Request :: new ( bitreq:: Method :: Post , & self . url )
76- . with_timeout ( timeout_secs )
64+ . with_timeout ( self . timeout )
7765 . with_json ( & req) ?,
7866 } ;
7967
0 commit comments