From 7fb8aae2e522a1693c1c65c2a1828d547b7b7977 Mon Sep 17 00:00:00 2001 From: Luis Schwab Date: Thu, 25 Jul 2024 19:57:31 -0300 Subject: [PATCH 1/3] add new Client builder method with an arbitrary timeout value --- client/src/client.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index 2f809a79..fda55dab 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; @@ -1293,6 +1294,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 { From 8e4fb85d75c0d2ae7a4ef94586a61d04b2433853 Mon Sep 17 00:00:00 2001 From: Luis Schwab Date: Tue, 13 Aug 2024 22:31:41 -0300 Subject: [PATCH 2/3] add struct and RPC method to check scantxoutset status --- client/src/client.rs | 16 ++++++++++++++++ json/src/lib.rs | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index fda55dab..0d2eacf6 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1257,6 +1257,22 @@ 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), + } + } + fn scan_tx_out_set_blocking( &self, descriptors: &[json::ScanTxOutRequest], 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). From 8e8790f44d130dac390718ab3beb61b5283e141c Mon Sep 17 00:00:00 2001 From: Luis Schwab Date: Wed, 14 Aug 2024 16:44:51 -0300 Subject: [PATCH 3/3] add RPC method to abort scantxoutset --- client/src/client.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index 0d2eacf6..05428612 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1272,6 +1272,11 @@ pub trait RpcApi: Sized { 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,