From 073cdd0a89c8688b2cdad73666b71a79d9f81ae1 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 9 Nov 2022 18:21:39 +0100 Subject: [PATCH] commands: add a 'rescan_progress' field to 'getinfo' We make sure to return a value as long as it was not wiped from database, that's useful in functional tests. --- doc/API.md | 15 ++++++++------- src/commands/mod.rs | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/API.md b/doc/API.md index 0ab178fe..3863a463 100644 --- a/doc/API.md +++ b/doc/API.md @@ -43,13 +43,14 @@ This command does not take any parameter for now. #### Response -| Field | Type | Description | -| -------------------- | ------- | -------------------------------------------------------------------------------------------- | -| `version` | string | Version following the [SimVer](http://www.simver.org/) format | -| `network` | string | Answer can be `mainnet`, `testnet`, `regtest` | -| `blockheight` | integer | The block height we are synced at. | -| `sync` | float | The synchronization progress as percentage (`0 < sync < 1`) | -| `descriptors` | object | Object with the name of the descriptor as key and the descriptor string as value | +| Field | Type | Description | +| -------------------- | ------- | -------------------------------------------------------------------------------------------------- | +| `version` | string | Version following the [SimVer](http://www.simver.org/) format | +| `network` | string | Answer can be `mainnet`, `testnet`, `regtest` | +| `blockheight` | integer | The block height we are synced at. | +| `sync` | float | The synchronization progress as percentage (`0 < sync < 1`) | +| `descriptors` | object | Object with the name of the descriptor as key and the descriptor string as value | +| `rescan_progress` | float or null | Progress of an ongoing rescan as a percentage (between 0 and 1) if there is any | ### `getnewaddress` diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 38b93b96..9a1d44c2 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -196,6 +196,9 @@ impl DaemonControl { let mut db_conn = self.db.connection(); let blockheight = db_conn.chain_tip().map(|tip| tip.height).unwrap_or(0); + let rescan_progress = db_conn + .rescan_timestamp() + .map(|_| self.bitcoin.rescan_progress().unwrap_or(1.0)); GetInfoResult { version: VERSION.to_string(), network: self.config.bitcoin_config.network, @@ -204,6 +207,7 @@ impl DaemonControl { descriptors: GetInfoDescriptors { main: self.config.main_descriptor.clone(), }, + rescan_progress, } } @@ -535,6 +539,8 @@ pub struct GetInfoResult { pub blockheight: i32, pub sync: f64, pub descriptors: GetInfoDescriptors, + /// The progress as a percentage (between 0 and 1) of an ongoing rescan if there is any + pub rescan_progress: Option, } #[derive(Debug, Clone, Serialize, Deserialize)]