File tree 1 file changed +23
-0
lines changed 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ use std::io::{BufRead, BufReader};
14
14
use std:: iter:: FromIterator ;
15
15
use std:: path:: PathBuf ;
16
16
use std:: { fmt, result} ;
17
+ use std:: time:: Duration ;
17
18
18
19
use crate :: bitcoin;
19
20
use crate :: bitcoin:: consensus:: encode;
@@ -1293,6 +1294,28 @@ impl Client {
1293
1294
. map_err ( |e| super :: error:: Error :: JsonRpc ( e. into ( ) ) )
1294
1295
}
1295
1296
1297
+ /// Creates a client to a bitcoind JSON-RPC server with a custom timeout value, in seconds.
1298
+ /// Useful when making an RPC that can take a long time e.g. scantxoutset
1299
+ pub fn new_with_custom_timeout ( url : & str , auth : Auth , timeout : u64 ) -> result:: Result < Self , Error > {
1300
+ let ( user, pass) = auth. get_user_pass ( ) ?;
1301
+
1302
+ let user = user. unwrap ( ) ;
1303
+ let pass = pass. unwrap ( ) ;
1304
+
1305
+ let transport =
1306
+ jsonrpc:: simple_http:: Builder :: new ( )
1307
+ . timeout ( Duration :: from_secs ( timeout) )
1308
+ . url ( url)
1309
+ . unwrap ( )
1310
+ . auth ( user, Some ( pass) )
1311
+ . build ( ) ;
1312
+
1313
+ let client = jsonrpc:: client:: Client :: with_transport ( transport) ;
1314
+
1315
+ Ok ( Client { client } )
1316
+
1317
+ }
1318
+
1296
1319
/// Create a new Client using the given [jsonrpc::Client].
1297
1320
pub fn from_jsonrpc ( client : jsonrpc:: client:: Client ) -> Client {
1298
1321
Client {
You can’t perform that action at this time.
0 commit comments