Skip to content

Commit 7392d9f

Browse files
committed
Add account remove command
1 parent 618ae3d commit 7392d9f

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

codechain/account_command.rs

Lines changed: 28 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(key)
7874
};
7975
match Private::from_str(key) {
8076
Ok(private) => {
@@ -98,7 +94,25 @@ 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()),
115+
102116
}
103117
}
104118

@@ -111,3 +125,11 @@ fn read_password_and_confirm() -> Option<String> {
111125
None
112126
}
113127
}
128+
129+
fn read_raw_key(val: &str) -> &str {
130+
if val.starts_with("0x") {
131+
&val[2..]
132+
} else {
133+
&val[..]
134+
}
135+
}

codechain/codechain.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,10 @@ subcommands:
206206
index: 1
207207
- list:
208208
about: list managed accounts
209+
- remove:
210+
about: remove a account
211+
args:
212+
- ADDRESS:
213+
help: Address to remove
214+
required: true
215+
index: 1

0 commit comments

Comments
 (0)