mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-10-23 16:52:38 +00:00
Add clear command
This commit is contained in:
@@ -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 {}
|
||||
impl Command for HelpCommand {
|
||||
fn help(&self) -> String {
|
||||
@@ -614,10 +640,11 @@ struct HeightCommand {}
|
||||
impl Command for HeightCommand {
|
||||
fn help(&self) -> String {
|
||||
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("height");
|
||||
h.push("height [do_sync = true | false]");
|
||||
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")
|
||||
}
|
||||
@@ -626,10 +653,18 @@ impl Command for HeightCommand {
|
||||
"Get the latest block height that the wallet is at".to_string()
|
||||
}
|
||||
|
||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||
match lightclient.do_sync(true) {
|
||||
Ok(_) => format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2)),
|
||||
Err(e) => e
|
||||
fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
|
||||
if args.len() > 1 {
|
||||
return format!("Didn't understand arguments\n{}", self.help());
|
||||
}
|
||||
|
||||
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("encryptionstatus".to_string(), Box::new(EncryptionStatusCommand{}));
|
||||
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("balance".to_string(), Box::new(BalanceCommand{}));
|
||||
map.insert("addresses".to_string(), Box::new(AddressCommand{}));
|
||||
|
||||
Reference in New Issue
Block a user