diff --git a/client/src/client.rs b/client/src/client.rs index 2f809a79..05428612 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -14,6 +14,7 @@ use std::io::{BufRead, BufReader}; use std::iter::FromIterator; use std::path::PathBuf; use std::{fmt, result}; +use std::time::Duration; use crate::bitcoin; use crate::bitcoin::consensus::encode; @@ -1256,6 +1257,27 @@ pub trait RpcApi: Sized { } } + // Return the status of a UTXO set scan + fn scan_tx_out_set_status(&self) -> Result> { + match self.call("scantxoutset", &["status".into()]) { + Ok(response) => { + let response: serde_json::Value = response; + if response.is_null() { + Ok(None) + } else { + let result: json::ScanTxOutStatusResult = serde_json::from_value(response)?; + Ok(Some(result)) + } + } + Err(e) => Err(e), + } + } + + // Abort a UTXO set scan + fn scan_tx_out_set_abort(&self) -> Result { + self.call("scantxoutset", &["abort".into()]) + } + fn scan_tx_out_set_blocking( &self, descriptors: &[json::ScanTxOutRequest], @@ -1293,6 +1315,28 @@ impl Client { .map_err(|e| super::error::Error::JsonRpc(e.into())) } + /// Creates a client to a bitcoind JSON-RPC server with a custom timeout value, in seconds. + /// Useful when making an RPC that can take a long time e.g. scantxoutset + pub fn new_with_custom_timeout(url: &str, auth: Auth, timeout: u64) -> result::Result { + let (user, pass) = auth.get_user_pass()?; + + let user = user.unwrap(); + let pass = pass.unwrap(); + + let transport = + jsonrpc::simple_http::Builder::new() + .timeout(Duration::from_secs(timeout)) + .url(url) + .unwrap() + .auth(user, Some(pass)) + .build(); + + let client = jsonrpc::client::Client::with_transport(transport); + + Ok(Client{ client }) + + } + /// Create a new Client using the given [jsonrpc::Client]. pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client { Client { diff --git a/json/src/lib.rs b/json/src/lib.rs index 25f3508e..70386df4 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2097,6 +2097,12 @@ pub enum PubKeyOrAddress<'a> { PubKey(&'a PublicKey), } +/// Used to represent the status of a UTXO set scan. +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] +pub struct ScanTxOutStatusResult { + pub progress: u8, +} + #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] #[serde(untagged)] /// Start a scan of the UTXO set for an [output descriptor](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md).