Skip to content

Commit 7fb8aae

Browse files
committed
add new Client builder method with an arbitrary timeout value
1 parent 06a6c15 commit 7fb8aae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

client/src/client.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::io::{BufRead, BufReader};
1414
use std::iter::FromIterator;
1515
use std::path::PathBuf;
1616
use std::{fmt, result};
17+
use std::time::Duration;
1718

1819
use crate::bitcoin;
1920
use crate::bitcoin::consensus::encode;
@@ -1293,6 +1294,28 @@ impl Client {
12931294
.map_err(|e| super::error::Error::JsonRpc(e.into()))
12941295
}
12951296

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+
12961319
/// Create a new Client using the given [jsonrpc::Client].
12971320
pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client {
12981321
Client {

0 commit comments

Comments
 (0)