merge upstream updates
This commit is contained in:
@@ -2,6 +2,7 @@ use std::collections::HashMap;
|
||||
use json::{object};
|
||||
|
||||
use crate::lightclient::LightClient;
|
||||
use crate::lightwallet::LightWallet;
|
||||
|
||||
pub trait Command {
|
||||
fn help(&self) -> String;
|
||||
@@ -110,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 {
|
||||
@@ -487,6 +514,8 @@ impl Command for SendCommand {
|
||||
Err(s) => { return format!("Error: {}\n{}", s, self.help()); }
|
||||
}
|
||||
} else if args.len() == 2 || args.len() == 3 {
|
||||
let address = args[0].to_string();
|
||||
|
||||
// Make sure we can parse the amount
|
||||
let value = match args[1].parse::<u64>() {
|
||||
Ok(amt) => amt,
|
||||
@@ -495,7 +524,12 @@ impl Command for SendCommand {
|
||||
}
|
||||
};
|
||||
|
||||
let memo = if args.len() == 3 { Some(args[2].to_string()) } else {None};
|
||||
let memo = if args.len() == 3 { Some(args[2].to_string()) } else { None };
|
||||
|
||||
// Memo has to be None if not sending to a shileded address
|
||||
if memo.is_some() && !LightWallet::is_shielded_address(&address, &lightclient.config) {
|
||||
return format!("Can't send a memo to the non-shielded address {}", address);
|
||||
}
|
||||
|
||||
vec![(args[0].to_string(), value, memo)]
|
||||
} else {
|
||||
@@ -606,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")
|
||||
}
|
||||
@@ -618,11 +653,19 @@ impl Command for HeightCommand {
|
||||
"Get the latest block height that the wallet is at".to_string()
|
||||
}
|
||||
|
||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||
format!("{}",
|
||||
object! {
|
||||
"height" => lightclient.last_scanned_height()
|
||||
}.pretty(2))
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -753,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