From 6a178c8d08d9c1c153fb22759a68177cdb787be7 Mon Sep 17 00:00:00 2001 From: DanS Date: Sun, 22 Mar 2026 11:23:40 -0500 Subject: [PATCH] add optional height param to clear command for rescan-from-height --- lib/src/commands.rs | 12 ++++++++++-- lib/src/lightclient.rs | 8 ++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/src/commands.rs b/lib/src/commands.rs index 6972e72..14f2773 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -132,8 +132,16 @@ impl Command for ClearCommand { "Clear the wallet state, rolling back the wallet to an empty state.".to_string() } - fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { - lightclient.clear_state(); + fn exec(&self, args: &[&str], lightclient: &LightClient) -> String { + if !args.is_empty() { + if let Ok(height) = args[0].parse::() { + lightclient.clear_state_from(height); + } else { + return format!("Error: invalid height '{}'", args[0]); + } + } else { + lightclient.clear_state(); + } let result = object!{ "result" => "success" }; diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index ab73d98..da90c33 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -1274,12 +1274,16 @@ pub fn start_mempool_monitor(lc: Arc) -> Result<(), String> { } pub fn clear_state(&self) { + self.clear_state_from(self.wallet.read().unwrap().get_birthday()); + } + + pub fn clear_state_from(&self, height: u64) { // First, clear the state from the wallet self.wallet.read().unwrap().clear_blocks(); // Then set the initial block - self.set_wallet_initial_state(self.wallet.read().unwrap().get_birthday()); - info!("Cleared wallet state"); + self.set_wallet_initial_state(height); + info!("Cleared wallet state to height {}", height); } pub fn do_rescan(&self) -> Result {