Skip to content

Commit b60083f

Browse files
committed
Add account remove command
1 parent d357547 commit b60083f

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

codechain/account_command.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::str::FromStr;
2020
use rpassword;
2121

2222
use ccore::AccountProvider;
23-
use ckey::Private;
23+
use ckey::{Address, Private};
2424
use ckeystore::accounts_dir::RootDiskDirectory;
2525
use ckeystore::KeyStore;
2626
use clap::ArgMatches;
@@ -70,11 +70,7 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
7070
("import-raw", Some(matches)) => {
7171
let key = {
7272
let val = matches.value_of("RAW_KEY").expect("RAW_KEY arg is required and its index is 1");
73-
if val.starts_with("0x") {
74-
&val[2..]
75-
} else {
76-
&val[..]
77-
}
73+
read_raw_key(val)
7874
};
7975
match Private::from_str(key) {
8076
Ok(private) => {
@@ -98,6 +94,23 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
9894
}
9995
Ok(())
10096
}
97+
("remove", Some(matches)) => {
98+
let key = {
99+
let val = matches.value_of("ADDRESS").expect("ADDRESS arg is required and its index is 1");
100+
read_raw_key(val)
101+
};
102+
match Address::from_str(key) {
103+
Ok(address) => {
104+
let password = rpassword::prompt_password_stdout("Password: ").unwrap();
105+
match ap.remove_account(address, password.as_ref()) {
106+
Ok(_) => println!("{:?} is deleted", address),
107+
Err(e) => return Err(format!("{:?}", e)),
108+
}
109+
}
110+
Err(e) => return Err(format!("{:?}", e)),
111+
}
112+
Ok(())
113+
}
101114
_ => Err("Invalid subcommand".to_string()),
102115
}
103116
}
@@ -111,3 +124,11 @@ fn read_password_and_confirm() -> Option<String> {
111124
None
112125
}
113126
}
127+
128+
fn read_raw_key(val: &str) -> &str {
129+
if val.starts_with("0x") {
130+
&val[2..]
131+
} else {
132+
&val[..]
133+
}
134+
}

codechain/codechain.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,10 @@ subcommands:
216216
args:
217217
- address:
218218
help: address to unlock
219+
- remove:
220+
about: remove a account
221+
args:
222+
- ADDRESS:
223+
help: Address to remove
224+
required: true
225+
index: 1

0 commit comments

Comments
 (0)