Skip to content

Add account remove command #426

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

Merged
merged 1 commit into from
Jul 18, 2018
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
33 changes: 27 additions & 6 deletions codechain/account_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::str::FromStr;
use rpassword;

use ccore::AccountProvider;
use ckey::Private;
use ckey::{Address, Private};
use ckeystore::accounts_dir::RootDiskDirectory;
use ckeystore::KeyStore;
use clap::ArgMatches;
Expand Down Expand Up @@ -70,11 +70,7 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
("import-raw", Some(matches)) => {
let key = {
let val = matches.value_of("RAW_KEY").expect("RAW_KEY arg is required and its index is 1");
if val.starts_with("0x") {
&val[2..]
} else {
&val[..]
}
read_raw_key(val)
};
match Private::from_str(key) {
Ok(private) => {
Expand All @@ -98,6 +94,23 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
}
Ok(())
}
("remove", Some(matches)) => {
let key = {
let val = matches.value_of("ADDRESS").expect("ADDRESS arg is required and its index is 1");
read_raw_key(val)
};
match Address::from_str(key) {
Ok(address) => {
let password = rpassword::prompt_password_stdout("Password: ").unwrap();
match ap.remove_account(address, password.as_ref()) {
Ok(_) => println!("{:?} is deleted", address),
Err(e) => return Err(format!("{:?}", e)),
}
}
Err(e) => return Err(format!("{:?}", e)),
}
Ok(())
}
_ => Err("Invalid subcommand".to_string()),
}
}
Expand All @@ -111,3 +124,11 @@ fn read_password_and_confirm() -> Option<String> {
None
}
}

fn read_raw_key(val: &str) -> &str {
if val.starts_with("0x") {
&val[2..]
} else {
&val[..]
}
}
7 changes: 7 additions & 0 deletions codechain/codechain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,10 @@ subcommands:
index: 1
- list:
about: list managed accounts
- remove:
about: remove a account
args:
- ADDRESS:
help: Address to remove
required: true
index: 1