mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-11 17:55:47 +00:00
Add clear command
This commit is contained in:
parent
96997c5a46
commit
165c22e39e
@ -147,7 +147,7 @@ pub fn start_interactive(command_tx: Sender<(String, Vec<String>)>, resp_rx: Rec
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Read the height first
|
// Read the height first
|
||||||
let height = json::parse(&send_command("height".to_string(), vec![])).unwrap()["height"].as_i64().unwrap();
|
let height = json::parse(&send_command("height".to_string(), vec!["false".to_string()])).unwrap()["height"].as_i64().unwrap();
|
||||||
|
|
||||||
let readline = rl.readline(&format!("({}) Block:{} (type 'help') >> ",
|
let readline = rl.readline(&format!("({}) Block:{} (type 'help') >> ",
|
||||||
chain_name, height));
|
chain_name, height));
|
||||||
|
@ -111,6 +111,32 @@ impl Command for RescanCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct ClearCommand {}
|
||||||
|
impl Command for ClearCommand {
|
||||||
|
fn help(&self) -> String {
|
||||||
|
let mut h = vec![];
|
||||||
|
h.push("Clear the wallet state, rolling back the wallet to an empty state.");
|
||||||
|
h.push("Usage:");
|
||||||
|
h.push("clear");
|
||||||
|
h.push("");
|
||||||
|
h.push("This command will clear all notes, utxos and transactions from the wallet, setting up the wallet to be synced from scratch.");
|
||||||
|
|
||||||
|
h.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn short_help(&self) -> String {
|
||||||
|
"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();
|
||||||
|
|
||||||
|
let result = object!{ "result" => "success" };
|
||||||
|
|
||||||
|
result.pretty(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct HelpCommand {}
|
struct HelpCommand {}
|
||||||
impl Command for HelpCommand {
|
impl Command for HelpCommand {
|
||||||
fn help(&self) -> String {
|
fn help(&self) -> String {
|
||||||
@ -614,10 +640,11 @@ struct HeightCommand {}
|
|||||||
impl Command for HeightCommand {
|
impl Command for HeightCommand {
|
||||||
fn help(&self) -> String {
|
fn help(&self) -> String {
|
||||||
let mut h = vec![];
|
let mut h = vec![];
|
||||||
h.push("Get the latest block height that the wallet is at");
|
h.push("Get the latest block height that the wallet is at.");
|
||||||
h.push("Usage:");
|
h.push("Usage:");
|
||||||
h.push("height");
|
h.push("height [do_sync = true | false]");
|
||||||
h.push("");
|
h.push("");
|
||||||
|
h.push("Pass 'true' (default) to sync to the server to get the latest block height. Pass 'false' to get the latest height in the wallet without checking with the server.");
|
||||||
|
|
||||||
h.join("\n")
|
h.join("\n")
|
||||||
}
|
}
|
||||||
@ -626,10 +653,18 @@ impl Command for HeightCommand {
|
|||||||
"Get the latest block height that the wallet is at".to_string()
|
"Get the latest block height that the wallet is at".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
|
||||||
match lightclient.do_sync(true) {
|
if args.len() > 1 {
|
||||||
Ok(_) => format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2)),
|
return format!("Didn't understand arguments\n{}", self.help());
|
||||||
Err(e) => e
|
}
|
||||||
|
|
||||||
|
if args.len() == 1 && args[0].trim() == "true" {
|
||||||
|
match lightclient.do_sync(true) {
|
||||||
|
Ok(_) => format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2)),
|
||||||
|
Err(e) => e
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -761,6 +796,7 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
|
|||||||
map.insert("syncstatus".to_string(), Box::new(SyncStatusCommand{}));
|
map.insert("syncstatus".to_string(), Box::new(SyncStatusCommand{}));
|
||||||
map.insert("encryptionstatus".to_string(), Box::new(EncryptionStatusCommand{}));
|
map.insert("encryptionstatus".to_string(), Box::new(EncryptionStatusCommand{}));
|
||||||
map.insert("rescan".to_string(), Box::new(RescanCommand{}));
|
map.insert("rescan".to_string(), Box::new(RescanCommand{}));
|
||||||
|
map.insert("clear".to_string(), Box::new(ClearCommand{}));
|
||||||
map.insert("help".to_string(), Box::new(HelpCommand{}));
|
map.insert("help".to_string(), Box::new(HelpCommand{}));
|
||||||
map.insert("balance".to_string(), Box::new(BalanceCommand{}));
|
map.insert("balance".to_string(), Box::new(BalanceCommand{}));
|
||||||
map.insert("addresses".to_string(), Box::new(AddressCommand{}));
|
map.insert("addresses".to_string(), Box::new(AddressCommand{}));
|
||||||
|
@ -842,14 +842,20 @@ impl LightClient {
|
|||||||
Ok(array![new_address])
|
Ok(array![new_address])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_rescan(&self) -> Result<JsonValue, String> {
|
pub fn clear_state(&self) {
|
||||||
info!("Rescan starting");
|
|
||||||
// First, clear the state from the wallet
|
// First, clear the state from the wallet
|
||||||
self.wallet.read().unwrap().clear_blocks();
|
self.wallet.read().unwrap().clear_blocks();
|
||||||
|
|
||||||
// Then set the initial block
|
// Then set the initial block
|
||||||
self.set_wallet_initial_state(self.wallet.read().unwrap().get_birthday());
|
self.set_wallet_initial_state(self.wallet.read().unwrap().get_birthday());
|
||||||
|
info!("Cleared wallet state");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn do_rescan(&self) -> Result<JsonValue, String> {
|
||||||
|
info!("Rescan starting");
|
||||||
|
|
||||||
|
self.clear_state();
|
||||||
|
|
||||||
// Then, do a sync, which will force a full rescan from the initial state
|
// Then, do a sync, which will force a full rescan from the initial state
|
||||||
let response = self.do_sync(true);
|
let response = self.do_sync(true);
|
||||||
info!("Rescan finished");
|
info!("Rescan finished");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user