basic commands

This commit is contained in:
Nikolay Volf 2016-03-09 17:11:15 +04:00
parent 3655354980
commit 6ad0ba8fe2
4 changed files with 56 additions and 0 deletions

20
Cargo.lock generated
View File

@ -15,6 +15,7 @@ dependencies = [
"fdlimit 0.1.0",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"number_prefix 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -680,6 +681,17 @@ dependencies = [
"librocksdb-sys 0.2.1 (git+https://github.com/arkpar/rust-rocksdb.git)",
]
[[package]]
name = "rpassword"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rust-crypto"
version = "0.2.34"
@ -813,6 +825,14 @@ dependencies = [
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termios"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.34"

View File

@ -21,6 +21,7 @@ fdlimit = { path = "util/fdlimit" }
daemonize = "0.2"
ethcore-devtools = { path = "devtools" }
number_prefix = "0.2"
rpassword = "0.1"
[features]
default = ["rpc"]

View File

@ -32,6 +32,7 @@ extern crate fdlimit;
extern crate daemonize;
extern crate time;
extern crate number_prefix;
extern crate rpassword;
#[cfg(feature = "rpc")]
extern crate ethcore_rpc as rpc;
@ -70,6 +71,7 @@ Parity. Ethereum Client.
Usage:
parity daemon <pid-file> [options] [ --no-bootstrap | <enode>... ]
parity account <command>
parity [options] [ --no-bootstrap | <enode>... ]
Protocol Options:
@ -126,8 +128,10 @@ Miscellaneous Options:
#[derive(Debug, RustcDecodable)]
struct Args {
cmd_daemon: bool,
cmd_account: bool,
arg_pid_file: String,
arg_enode: Vec<String>,
arg_command: String,
flag_chain: String,
flag_testnet: bool,
flag_datadir: String,
@ -337,9 +341,39 @@ impl Configuration {
.start()
.unwrap_or_else(|e| die!("Couldn't daemonize; {}", e));
}
if self.args.cmd_account {
self.execute_account_cli(&self.args.arg_command);
return;
}
self.execute_client();
}
fn execute_account_cli(&self, command: &str) {
use util::keys::store::SecretStore;
use rpassword::read_password;
let mut secret_store = SecretStore::new();
if command == "new" {
println!("Please note that password is NOT RECOVERABLE.");
println!("Type password: ");
let password = read_password().unwrap();
println!("Repeat password: ");
let password_repeat = read_password().unwrap();
if password != password_repeat {
println!("Passwords do not match!");
return;
}
println!("New account address:");
let new_address = secret_store.new_account(&password).unwrap();
println!("{:?}", new_address);
}
if command == "list" {
println!("Known addresses:");
for &(addr, _) in secret_store.accounts().unwrap().iter() {
println!("{:?}", addr);
}
}
}
fn execute_client(&self) {
// Setup logging
setup_log(&self.args.flag_logging);

View File

@ -84,6 +84,7 @@ impl SecretStore {
let mut path = ::std::env::home_dir().expect("Failed to get home dir");
path.push(".parity");
path.push("keys");
::std::fs::create_dir_all(&path).expect("Should panic since it is critical to be able to access home dir");
Self::new_in(&path)
}