Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change incorrect command name #171

Merged
merged 4 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 7 additions & 230 deletions lib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,6 @@ impl Command for SyncCommand {
}
}

struct EncryptionStatusCommand {}
impl Command for EncryptionStatusCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Check if the wallet is encrypted and if it is locked");
h.push("Usage:");
h.push("encryptionstatus");
h.push("");

h.join("\n")
}

fn short_help(&self) -> String {
"Check if the wallet is encrypted and if it is locked".to_string()
}

fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
RT.block_on(async move { lightclient.do_encryption_status().await.pretty(2) })
}
}

struct SyncStatusCommand {}
impl Command for SyncStatusCommand {
fn help(&self) -> String {
Expand Down Expand Up @@ -394,30 +373,6 @@ impl Command for InfoCommand {
}
}

struct ZecPriceCommand {}
impl Command for ZecPriceCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Use UpdateCurrentPriceCommand instead.");
h.push("Backwards compatible price fetch");
h.push("Get the latest ZEC price from Gemini exchange's API.");
h.push("Currently using USD.");
h.push("Usage:");
h.push("zecprice");
h.push("");

h.join("\n")
}

fn short_help(&self) -> String {
"Get the latest ZEC price in the wallet's currency (USD)".to_string()
}

fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
RT.block_on(async move { lightclient.do_zec_price().await })
}
}

struct UpdateCurrentPriceCommand {}
impl Command for UpdateCurrentPriceCommand {
fn help(&self) -> String {
Expand All @@ -440,8 +395,8 @@ impl Command for UpdateCurrentPriceCommand {
}
}

struct LastTxIdCommand {}
impl Command for LastTxIdCommand {
struct UnconfirmedRecentTxIdCommand {}
impl Command for UnconfirmedRecentTxIdCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Show the latest TxId in the wallet");
Expand All @@ -457,7 +412,7 @@ impl Command for LastTxIdCommand {

fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
RT.block_on(
async move { format!("{}", lightclient.do_last_transaction_id().await.pretty(2)) },
async move { format!("{}", lightclient.do_maybe_recent_txid().await.pretty(2)) },
)
}
}
Expand Down Expand Up @@ -534,178 +489,6 @@ impl Command for ExportCommand {
}
}

struct EncryptCommand {}
impl Command for EncryptCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Encrypt the wallet with a password");
h.push("Note 1: This will encrypt the seed and the sapling and transparent private keys.");
h.push(" Use 'unlock' to temporarily unlock the wallet for spending or 'decrypt' ");
h.push(" to permanatly remove the encryption");
h.push(
"Note 2: If you forget the password, the only way to recover the wallet is to restore",
);
h.push(" from the seed phrase.");
h.push("Usage:");
h.push("encrypt password");
h.push("");
h.push("Example:");
h.push("encrypt my_strong_password");

h.join("\n")
}

fn short_help(&self) -> String {
"Encrypt the wallet with a password".to_string()
}

fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
if args.len() != 1 {
return self.help();
}

let passwd = args[0].to_string();

RT.block_on(async move {
match lightclient.wallet.encrypt(passwd).await {
Ok(_) => object! { "result" => "success" },
Err(e) => object! {
"result" => "error",
"error" => e.to_string()
},
}
.pretty(2)
})
}
}

struct DecryptCommand {}
impl Command for DecryptCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Completely remove wallet encryption, storing the wallet in plaintext on disk");
h.push(
"Note 1: This will decrypt the seed and the sapling and transparent private keys and store them on disk.",
);
h.push(" Use 'unlock' to temporarily unlock the wallet for spending");
h.push("Note 2: If you've forgotten the password, the only way to recover the wallet is to restore");
h.push(" from the seed phrase.");
h.push("Usage:");
h.push("decrypt password");
h.push("");
h.push("Example:");
h.push("decrypt my_strong_password");

h.join("\n")
}

fn short_help(&self) -> String {
"Completely remove wallet encryption".to_string()
}

fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
if args.len() != 1 {
return self.help();
}

let passwd = args[0].to_string();
RT.block_on(async move {
match lightclient.wallet.remove_encryption(passwd).await {
Ok(_) => object! { "result" => "success" },
Err(e) => object! {
"result" => "error",
"error" => e.to_string()
},
}
.pretty(2)
})
}
}

struct UnlockCommand {}
impl Command for UnlockCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Unlock the wallet's encryption in memory, allowing spending from this wallet.");
h.push("Note 1: This will decrypt spending keys in memory only. The wallet remains encrypted on disk");
h.push(" Use 'decrypt' to remove the encryption permanatly.");
h.push("Note 2: If you've forgotten the password, the only way to recover the wallet is to restore");
h.push(" from the seed phrase.");
h.push("Usage:");
h.push("unlock password");
h.push("");
h.push("Example:");
h.push("unlock my_strong_password");

h.join("\n")
}

fn short_help(&self) -> String {
"Unlock wallet encryption for spending".to_string()
}

fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
if args.len() != 1 {
return self.help();
}

let passwd = args[0].to_string();
RT.block_on(async move {
match lightclient.wallet.unlock(passwd).await {
Ok(_) => object! { "result" => "success" },
Err(e) => object! {
"result" => "error",
"error" => e.to_string()
},
}
.pretty(2)
})
}
}

struct LockCommand {}
impl Command for LockCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Lock a wallet that's been temporarily unlocked. You should already have encryption enabled.");
h.push("Note 1: This will remove all spending keys from memory. The wallet remains encrypted on disk");
h.push("Note 2: If you've forgotten the password, the only way to recover the wallet is to restore");
h.push(" from the seed phrase.");
h.push("Usage:");
h.push("lock");
h.push("");
h.push("Example:");
h.push("lock");

h.join("\n")
}

fn short_help(&self) -> String {
"Lock a wallet that's been temporarily unlocked".to_string()
}

fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
if args.len() != 0 {
let mut h = vec![];
h.push("Extra arguments to lock. Did you mean 'encrypt'?");
h.push("");

return format!("{}\n{}", h.join("\n"), self.help());
}

RT.block_on(async move {
match lightclient.wallet.lock().await {
Ok(_) => object! { "result" => "success" },
Err(e) => object! {
"result" => "error",
"error" => e.to_string()
},
}
.pretty(2)
})
}
}

struct ShieldCommand {}
impl Command for ShieldCommand {
fn help(&self) -> String {
Expand Down Expand Up @@ -1483,10 +1266,6 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {

map.insert("sync".to_string(), Box::new(SyncCommand {}));
map.insert("syncstatus".to_string(), Box::new(SyncStatusCommand {}));
map.insert(
"encryptionstatus".to_string(),
Box::new(EncryptionStatusCommand {}),
);
map.insert(
"encryptmessage".to_string(),
Box::new(EncryptMessageCommand {}),
Expand All @@ -1500,7 +1279,10 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
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("lasttxid".to_string(), Box::new(LastTxIdCommand {}));
map.insert(
"unconfirmedrecenttxid".to_string(),
Box::new(UnconfirmedRecentTxIdCommand {}),
);
map.insert("balance".to_string(), Box::new(BalanceCommand {}));
map.insert("addresses".to_string(), Box::new(AddressCommand {}));
map.insert("height".to_string(), Box::new(HeightCommand {}));
Expand All @@ -1510,7 +1292,6 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
map.insert("import".to_string(), Box::new(ImportCommand {}));
map.insert("export".to_string(), Box::new(ExportCommand {}));
map.insert("info".to_string(), Box::new(InfoCommand {}));
map.insert("zecprice".to_string(), Box::new(ZecPriceCommand {}));
map.insert(
"updatecurrentprice".to_string(),
Box::new(UpdateCurrentPriceCommand {}),
Expand All @@ -1524,10 +1305,6 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
map.insert("new".to_string(), Box::new(NewAddressCommand {}));
map.insert("defaultfee".to_string(), Box::new(DefaultFeeCommand {}));
map.insert("seed".to_string(), Box::new(SeedCommand {}));
map.insert("encrypt".to_string(), Box::new(EncryptCommand {}));
map.insert("decrypt".to_string(), Box::new(DecryptCommand {}));
map.insert("unlock".to_string(), Box::new(UnlockCommand {}));
map.insert("lock".to_string(), Box::new(LockCommand {}));

Box::new(map)
}
Expand Down
Loading