migrated ethkey, ethstore, evmbin and parity executables to serde 1.0
This commit is contained in:
parent
a9aaacd88b
commit
286526072f
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -295,12 +295,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "docopt"
|
||||
version = "0.7.0"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -707,9 +708,11 @@ dependencies = [
|
||||
name = "ethkey-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethkey 0.2.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -740,9 +743,11 @@ dependencies = [
|
||||
name = "ethstore-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethstore 0.1.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -775,11 +780,12 @@ dependencies = [
|
||||
name = "evmbin"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore 1.7.0",
|
||||
"ethcore-util 1.7.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1587,7 +1593,7 @@ dependencies = [
|
||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)",
|
||||
"daemonize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore 1.7.0",
|
||||
"ethcore-devtools 1.7.0",
|
||||
@ -1624,13 +1630,14 @@ dependencies = [
|
||||
"rlp 0.2.0",
|
||||
"rpassword 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rpc-cli 1.4.0",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -2373,6 +2380,17 @@ dependencies = [
|
||||
"serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"dtoa 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.4.1"
|
||||
@ -2736,10 +2754,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.2.0"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2955,7 +2973,7 @@ dependencies = [
|
||||
"checksum daemonize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "271ec51b7e0bee92f0d04601422c73eb76ececf197026711c97ad25038a010cf"
|
||||
"checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf"
|
||||
"checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8"
|
||||
"checksum docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab32ea6e284d87987066f21a9e809a73c14720571ef34516f0890b3d355ccfd8"
|
||||
"checksum docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b5b93718f8b3e5544fcc914c43de828ca6c6ace23e0332c6080a2977b49787a"
|
||||
"checksum dtoa 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5edd69c67b2f8e0911629b7e6b8a34cb3956613cd7c6e6414966dee349c2db4f"
|
||||
"checksum either 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3d2b503c86dad62aaf414ecf2b8c527439abedb3f8d812537f0b12bfd6f32a91"
|
||||
"checksum elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258ff6a9a94f648d0379dbd79110e057edbb53eb85cc237e33eadf8e5a30df85"
|
||||
@ -3104,6 +3122,7 @@ dependencies = [
|
||||
"checksum serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd81eef9f0b4ec341b11095335b6a4b28ed85581b12dd27585dee1529df35e0"
|
||||
"checksum serde_derive_internals 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "021c338d22c7e30f957a6ab7e388cb6098499dda9fd4ba1661ee074ca7a180d1"
|
||||
"checksum serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cf37ce931677e98b4fa5e6469aaa3ab4b6228309ea33b1b22d3ec055adfc4515"
|
||||
"checksum serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48b04779552e92037212c3615370f6bd57a40ebba7f20e554ff9f55e41a69a7b"
|
||||
"checksum serde_urlencoded 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a81f15da4b9780e1524697f73b09076b6e42298ef673bead9ca8f848b334ef84"
|
||||
"checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c"
|
||||
"checksum shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72f20b8f3c060374edb8046591ba28f62448c369ccbdc7b02075103fb3a9e38d"
|
||||
@ -3143,7 +3162,7 @@ dependencies = [
|
||||
"checksum tokio-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86f33def658c14724fc13ec6289b3875a8152ee8ae767a5b1ccbded363b03db8"
|
||||
"checksum tokio-uds 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bd209039933255ea77c6d7a1d18abc20b997d161acb900acca6eb74cdd049f31"
|
||||
"checksum toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "fcd27a04ca509aff336ba5eb2abc58d456f52c4ff64d9724d88acb85ead560b6"
|
||||
"checksum toml 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a442dfc13508e603c3f763274361db7f79d7469a0e95c411cde53662ab30fc72"
|
||||
"checksum toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b0601da6c97135c8d330c7a13a013ca6cd4143221b01de2f8d4edc50a9e551c7"
|
||||
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
|
||||
"checksum transient-hashmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "715254c8f0811be1a79ad3ea5e6fa3c8eddec2b03d7f5ba78cf093e56d79c24f"
|
||||
"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887"
|
||||
|
11
Cargo.toml
11
Cargo.toml
@ -9,8 +9,8 @@ build = "build.rs"
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
env_logger = "0.4"
|
||||
rustc-serialize = "0.3"
|
||||
docopt = "0.7"
|
||||
rustc-hex = "1.0"
|
||||
docopt = "0.8"
|
||||
time = "0.1"
|
||||
num_cpus = "1.2"
|
||||
number_prefix = "0.2"
|
||||
@ -19,9 +19,10 @@ semver = "0.6"
|
||||
ansi_term = "0.9"
|
||||
regex = "0.2"
|
||||
isatty = "0.1"
|
||||
toml = "0.2"
|
||||
serde = "0.9"
|
||||
serde_json = "0.9"
|
||||
toml = "0.4"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
app_dirs = "1.1.1"
|
||||
futures = "0.1"
|
||||
fdlimit = "0.1"
|
||||
|
@ -5,8 +5,10 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
ethkey = { path = "../" }
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
rustc-hex = "1.0"
|
||||
docopt = "0.7"
|
||||
docopt = "0.8"
|
||||
|
||||
[[bin]]
|
||||
name = "ethkey"
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
extern crate docopt;
|
||||
extern crate rustc_hex;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate ethkey;
|
||||
|
||||
use std::{env, fmt, process};
|
||||
@ -54,7 +57,7 @@ Commands:
|
||||
verify Verify signer of the signature.
|
||||
"#;
|
||||
|
||||
#[derive(Debug, RustcDecodable)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Args {
|
||||
cmd_info: bool,
|
||||
cmd_generate: bool,
|
||||
@ -83,6 +86,7 @@ enum Error {
|
||||
Ethkey(EthkeyError),
|
||||
FromHex(FromHexError),
|
||||
ParseInt(ParseIntError),
|
||||
Docopt(docopt::Error),
|
||||
}
|
||||
|
||||
impl From<EthkeyError> for Error {
|
||||
@ -103,12 +107,19 @@ impl From<ParseIntError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<docopt::Error> for Error {
|
||||
fn from(err: docopt::Error) -> Self {
|
||||
Error::Docopt(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
Error::Ethkey(ref e) => write!(f, "{}", e),
|
||||
Error::FromHex(ref e) => write!(f, "{}", e),
|
||||
Error::ParseInt(ref e) => write!(f, "{}", e),
|
||||
Error::Docopt(ref e) => write!(f, "{}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,8 +166,7 @@ fn display(keypair: KeyPair, mode: DisplayMode) -> String {
|
||||
|
||||
fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item=S>, S: AsRef<str> {
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
.and_then(|d| d.argv(command).decode())
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
.and_then(|d| d.argv(command).deserialize())?;
|
||||
|
||||
return if args.cmd_info {
|
||||
let display_mode = DisplayMode::new(&args);
|
||||
|
@ -5,7 +5,9 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
rustc-hex = "1.0"
|
||||
docopt = "0.7"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
docopt = "0.8"
|
||||
ethstore = { path = "../" }
|
||||
|
||||
[[bin]]
|
||||
|
@ -16,14 +16,17 @@
|
||||
|
||||
extern crate rustc_hex;
|
||||
extern crate docopt;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate ethstore;
|
||||
|
||||
use std::{env, process, fs};
|
||||
use std::{env, process, fs, fmt};
|
||||
use std::io::Read;
|
||||
use docopt::Docopt;
|
||||
use ethstore::ethkey::Address;
|
||||
use ethstore::dir::{paths, KeyDirectory, RootDiskDirectory};
|
||||
use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, Error, PresaleWallet,
|
||||
use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, PresaleWallet,
|
||||
SecretVaultRef, StoreAccountRef};
|
||||
|
||||
pub const USAGE: &'static str = r#"
|
||||
@ -75,7 +78,7 @@ Commands:
|
||||
move-from-vault Move account to root directory from given vault.
|
||||
"#;
|
||||
|
||||
#[derive(Debug, RustcDecodable)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Args {
|
||||
cmd_insert: bool,
|
||||
cmd_change_pwd: bool,
|
||||
@ -104,6 +107,32 @@ struct Args {
|
||||
flag_vault_pwd: String,
|
||||
}
|
||||
|
||||
enum Error {
|
||||
Ethstore(ethstore::Error),
|
||||
Docopt(docopt::Error),
|
||||
}
|
||||
|
||||
impl From<ethstore::Error> for Error {
|
||||
fn from(err: ethstore::Error) -> Self {
|
||||
Error::Ethstore(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<docopt::Error> for Error {
|
||||
fn from(err: docopt::Error) -> Self {
|
||||
Error::Docopt(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::Ethstore(ref err) => fmt::Display::fmt(err, f),
|
||||
Error::Docopt(ref err) => fmt::Display::fmt(err, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match execute(env::args()) {
|
||||
Ok(result) => println!("{}", result),
|
||||
@ -159,9 +188,9 @@ fn format_vaults(vaults: &[String]) -> String {
|
||||
}
|
||||
|
||||
fn load_password(path: &str) -> Result<String, Error> {
|
||||
let mut file = fs::File::open(path).map_err(|e| Error::Custom(format!("Error opening password file {}: {}", path, e)))?;
|
||||
let mut file = fs::File::open(path).map_err(|e| ethstore::Error::Custom(format!("Error opening password file {}: {}", path, e)))?;
|
||||
let mut password = String::new();
|
||||
file.read_to_string(&mut password).map_err(|e| Error::Custom(format!("Error reading password file {}: {}", path, e)))?;
|
||||
file.read_to_string(&mut password).map_err(|e| ethstore::Error::Custom(format!("Error reading password file {}: {}", path, e)))?;
|
||||
// drop EOF
|
||||
let _ = password.pop();
|
||||
Ok(password)
|
||||
@ -169,19 +198,18 @@ fn load_password(path: &str) -> Result<String, Error> {
|
||||
|
||||
fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item=S>, S: AsRef<str> {
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
.and_then(|d| d.argv(command).decode())
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
.and_then(|d| d.argv(command).deserialize())?;
|
||||
|
||||
let store = EthStore::open(key_dir(&args.flag_dir)?)?;
|
||||
|
||||
return if args.cmd_insert {
|
||||
let secret = args.arg_secret.parse().map_err(|_| Error::InvalidSecret)?;
|
||||
let secret = args.arg_secret.parse().map_err(|_| ethstore::Error::InvalidSecret)?;
|
||||
let password = load_password(&args.arg_password)?;
|
||||
let vault_ref = open_args_vault(&store, &args)?;
|
||||
let address = store.insert_account(vault_ref, secret, &password)?;
|
||||
Ok(format!("0x{:?}", address))
|
||||
} else if args.cmd_change_pwd {
|
||||
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
|
||||
let address = args.arg_address.parse().map_err(|_| ethstore::Error::InvalidAccount)?;
|
||||
let old_pwd = load_password(&args.arg_old_pwd)?;
|
||||
let new_pwd = load_password(&args.arg_new_pwd)?;
|
||||
let account_ref = open_args_vault_account(&store, address, &args)?;
|
||||
@ -209,20 +237,20 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
let address = store.insert_account(vault_ref, kp.secret().clone(), &password)?;
|
||||
Ok(format!("0x{:?}", address))
|
||||
} else if args.cmd_remove {
|
||||
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
|
||||
let address = args.arg_address.parse().map_err(|_| ethstore::Error::InvalidAccount)?;
|
||||
let password = load_password(&args.arg_password)?;
|
||||
let account_ref = open_args_vault_account(&store, address, &args)?;
|
||||
let ok = store.remove_account(&account_ref, &password).is_ok();
|
||||
Ok(format!("{}", ok))
|
||||
} else if args.cmd_sign {
|
||||
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
|
||||
let message = args.arg_message.parse().map_err(|_| Error::InvalidMessage)?;
|
||||
let address = args.arg_address.parse().map_err(|_| ethstore::Error::InvalidAccount)?;
|
||||
let message = args.arg_message.parse().map_err(|_| ethstore::Error::InvalidMessage)?;
|
||||
let password = load_password(&args.arg_password)?;
|
||||
let account_ref = open_args_vault_account(&store, address, &args)?;
|
||||
let signature = store.sign(&account_ref, &password, &message)?;
|
||||
Ok(format!("0x{:?}", signature))
|
||||
} else if args.cmd_public {
|
||||
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
|
||||
let address = args.arg_address.parse().map_err(|_| ethstore::Error::InvalidAccount)?;
|
||||
let password = load_password(&args.arg_password)?;
|
||||
let account_ref = open_args_vault_account(&store, address, &args)?;
|
||||
let public = store.public(&account_ref, &password)?;
|
||||
@ -241,14 +269,14 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
store.change_vault_password(&args.arg_vault, &new_pwd)?;
|
||||
Ok("OK".to_owned())
|
||||
} else if args.cmd_move_to_vault {
|
||||
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
|
||||
let address = args.arg_address.parse().map_err(|_| ethstore::Error::InvalidAccount)?;
|
||||
let password = load_password(&args.arg_password)?;
|
||||
let account_ref = open_args_vault_account(&store, address, &args)?;
|
||||
store.open_vault(&args.arg_vault, &password)?;
|
||||
store.change_account_vault(SecretVaultRef::Vault(args.arg_vault), account_ref)?;
|
||||
Ok("OK".to_owned())
|
||||
} else if args.cmd_move_from_vault {
|
||||
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
|
||||
let address = args.arg_address.parse().map_err(|_| ethstore::Error::InvalidAccount)?;
|
||||
let password = load_password(&args.arg_password)?;
|
||||
store.open_vault(&args.arg_vault, &password)?;
|
||||
store.change_account_vault(SecretVaultRef::Root, StoreAccountRef::vault(&args.arg_vault, address))?;
|
||||
|
@ -10,8 +10,9 @@ path = "./src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
rustc-hex = "1.0"
|
||||
rustc-serialize = "0.3"
|
||||
docopt = { version = "0.7" }
|
||||
docopt = "0.8"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
ethcore = { path = "../ethcore" }
|
||||
ethcore-util = { path = "../util" }
|
||||
|
||||
|
@ -20,7 +20,9 @@
|
||||
#![allow(dead_code)]
|
||||
extern crate ethcore;
|
||||
extern crate rustc_hex;
|
||||
extern crate rustc_serialize;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate docopt;
|
||||
extern crate ethcore_util as util;
|
||||
|
||||
@ -60,7 +62,7 @@ General options:
|
||||
|
||||
|
||||
fn main() {
|
||||
let args: Args = Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit());
|
||||
let args: Args = Docopt::new(USAGE).and_then(|d| d.deserialize()).unwrap_or_else(|e| e.exit());
|
||||
|
||||
if args.flag_json {
|
||||
run(args, display::json::Informant::default())
|
||||
@ -88,7 +90,7 @@ fn run<T: Informant>(args: Args, mut informant: T) {
|
||||
informant.finish(result);
|
||||
}
|
||||
|
||||
#[derive(Debug, RustcDecodable)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Args {
|
||||
cmd_stats: bool,
|
||||
flag_from: Option<String>,
|
||||
|
@ -20,7 +20,7 @@ use std::io::{BufReader, BufRead};
|
||||
use std::time::{Instant, Duration};
|
||||
use std::thread::sleep;
|
||||
use std::sync::Arc;
|
||||
use rustc_serialize::hex::FromHex;
|
||||
use rustc_hex::FromHex;
|
||||
use util::{ToPretty, U256, H256, Address, Hashable};
|
||||
use rlp::PayloadInfo;
|
||||
use ethcore::service::ClientService;
|
||||
|
@ -381,7 +381,7 @@ usage! {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Config {
|
||||
parity: Option<Operating>,
|
||||
account: Option<Account>,
|
||||
@ -401,7 +401,7 @@ struct Config {
|
||||
stratum: Option<Stratum>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Operating {
|
||||
mode: Option<String>,
|
||||
mode_timeout: Option<u64>,
|
||||
@ -420,7 +420,7 @@ struct Operating {
|
||||
no_persistent_txqueue: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Account {
|
||||
unlock: Option<Vec<String>>,
|
||||
password: Option<Vec<String>>,
|
||||
@ -429,7 +429,7 @@ struct Account {
|
||||
fast_unlock: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Ui {
|
||||
force: Option<bool>,
|
||||
disable: Option<bool>,
|
||||
@ -439,7 +439,7 @@ struct Ui {
|
||||
path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Network {
|
||||
warp: Option<bool>,
|
||||
port: Option<u16>,
|
||||
@ -458,7 +458,7 @@ struct Network {
|
||||
no_serve_light: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Rpc {
|
||||
disable: Option<bool>,
|
||||
port: Option<u16>,
|
||||
@ -469,7 +469,7 @@ struct Rpc {
|
||||
threads: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Ws {
|
||||
disable: Option<bool>,
|
||||
port: Option<u16>,
|
||||
@ -479,14 +479,14 @@ struct Ws {
|
||||
hosts: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Ipc {
|
||||
disable: Option<bool>,
|
||||
path: Option<String>,
|
||||
apis: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Dapps {
|
||||
disable: Option<bool>,
|
||||
port: Option<u16>,
|
||||
@ -498,7 +498,7 @@ struct Dapps {
|
||||
pass: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct SecretStore {
|
||||
disable: Option<bool>,
|
||||
self_secret: Option<String>,
|
||||
@ -510,7 +510,7 @@ struct SecretStore {
|
||||
path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Ipfs {
|
||||
enable: Option<bool>,
|
||||
port: Option<u16>,
|
||||
@ -519,7 +519,7 @@ struct Ipfs {
|
||||
hosts: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Mining {
|
||||
author: Option<String>,
|
||||
engine_signer: Option<String>,
|
||||
@ -547,14 +547,14 @@ struct Mining {
|
||||
refuse_service_transactions: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Stratum {
|
||||
interface: Option<String>,
|
||||
port: Option<u16>,
|
||||
secret: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Footprint {
|
||||
tracing: Option<String>,
|
||||
pruning: Option<String>,
|
||||
@ -572,17 +572,17 @@ struct Footprint {
|
||||
num_verifiers: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Snapshots {
|
||||
disable_periodic: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct VM {
|
||||
jit: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Misc {
|
||||
logging: Option<String>,
|
||||
log_file: Option<String>,
|
||||
|
@ -55,28 +55,18 @@ macro_rules! usage {
|
||||
use util::version;
|
||||
use docopt::{Docopt, Error as DocoptError};
|
||||
use helpers::replace_home;
|
||||
use rustc_serialize;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ArgsError {
|
||||
Docopt(DocoptError),
|
||||
Parsing(Vec<toml::ParserError>),
|
||||
Decode(toml::DecodeError),
|
||||
Decode(toml::de::Error),
|
||||
Config(String, io::Error),
|
||||
UnknownFields(String),
|
||||
}
|
||||
|
||||
impl ArgsError {
|
||||
pub fn exit(self) -> ! {
|
||||
match self {
|
||||
ArgsError::Docopt(e) => e.exit(),
|
||||
ArgsError::Parsing(errors) => {
|
||||
println_stderr!("There is an error in config file.");
|
||||
for e in &errors {
|
||||
println_stderr!("{}", e);
|
||||
}
|
||||
process::exit(2)
|
||||
},
|
||||
ArgsError::Decode(e) => {
|
||||
println_stderr!("You might have supplied invalid parameters in config file.");
|
||||
println_stderr!("{}", e);
|
||||
@ -87,21 +77,20 @@ macro_rules! usage {
|
||||
println_stderr!("{}", e);
|
||||
process::exit(2)
|
||||
},
|
||||
ArgsError::UnknownFields(fields) => {
|
||||
println_stderr!("You have some extra fields in your config file:");
|
||||
println_stderr!("{}", fields);
|
||||
process::exit(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DocoptError> for ArgsError {
|
||||
fn from(e: DocoptError) -> Self { ArgsError::Docopt(e) }
|
||||
fn from(e: DocoptError) -> Self {
|
||||
ArgsError::Docopt(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<toml::DecodeError> for ArgsError {
|
||||
fn from(e: toml::DecodeError) -> Self { ArgsError::Decode(e) }
|
||||
impl From<toml::de::Error> for ArgsError {
|
||||
fn from(e: toml::de::Error) -> Self {
|
||||
ArgsError::Decode(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -137,7 +126,7 @@ macro_rules! usage {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Clone, RustcDecodable)]
|
||||
#[derive(Default, Debug, PartialEq, Clone, Deserialize)]
|
||||
struct RawArgs {
|
||||
$(
|
||||
$field_a: $typ_a,
|
||||
@ -192,20 +181,7 @@ macro_rules! usage {
|
||||
}
|
||||
|
||||
fn parse_config(config: &str) -> Result<Config, ArgsError> {
|
||||
let mut value_parser = toml::Parser::new(&config);
|
||||
match value_parser.parse() {
|
||||
Some(value) => {
|
||||
let mut decoder = toml::Decoder::new(toml::Value::Table(value));
|
||||
let result = rustc_serialize::Decodable::decode(&mut decoder);
|
||||
|
||||
match (result, decoder.toml) {
|
||||
(Err(e), _) => Err(e.into()),
|
||||
(_, Some(toml)) => Err(ArgsError::UnknownFields(toml::encode_str(&toml))),
|
||||
(Ok(config), None) => Ok(config),
|
||||
}
|
||||
},
|
||||
None => Err(ArgsError::Parsing(value_parser.errors)),
|
||||
}
|
||||
Ok(toml::from_str(config)?)
|
||||
}
|
||||
|
||||
pub fn print_version() -> String {
|
||||
@ -229,7 +205,7 @@ macro_rules! usage {
|
||||
}
|
||||
|
||||
pub fn parse<S: AsRef<str>>(command: &[S]) -> Result<Self, DocoptError> {
|
||||
Docopt::new(Self::usage()).and_then(|d| d.argv(command).decode())
|
||||
Docopt::new(Self::usage()).and_then(|d| d.argv(command).deserialize())
|
||||
}
|
||||
|
||||
fn usage() -> String {
|
||||
|
@ -36,10 +36,12 @@ extern crate number_prefix;
|
||||
extern crate regex;
|
||||
extern crate rlp;
|
||||
extern crate rpassword;
|
||||
extern crate rustc_serialize;
|
||||
extern crate rustc_hex;
|
||||
extern crate semver;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate time;
|
||||
extern crate toml;
|
||||
|
||||
|
@ -21,8 +21,8 @@ use std::path::Path;
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::Duration;
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
use serde::de::{Error, Visitor, MapVisitor};
|
||||
use serde::de::impls::BTreeMapVisitor;
|
||||
use serde::de::{Error, Visitor, MapAccess};
|
||||
use serde::de::value::MapAccessDeserializer;
|
||||
use serde_json::Value;
|
||||
use serde_json::de::from_reader;
|
||||
use serde_json::ser::to_string;
|
||||
@ -65,22 +65,22 @@ impl Serialize for UserDefaults {
|
||||
|
||||
struct UserDefaultsVisitor;
|
||||
|
||||
impl Deserialize for UserDefaults {
|
||||
impl<'a> Deserialize<'a> for UserDefaults {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(UserDefaultsVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(UserDefaultsVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl Visitor for UserDefaultsVisitor {
|
||||
impl<'a> Visitor<'a> for UserDefaultsVisitor {
|
||||
type Value = UserDefaults;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a valid UserDefaults object")
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error> where V: MapVisitor {
|
||||
let mut map: BTreeMap<String, Value> = BTreeMapVisitor::new().visit_map(visitor)?;
|
||||
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error> where V: MapAccess<'a> {
|
||||
let mut map: BTreeMap<String, Value> = Deserialize::deserialize(MapAccessDeserializer::new(visitor))?;
|
||||
let pruning: Value = map.remove("pruning").ok_or_else(|| Error::custom("missing pruning"))?;
|
||||
let pruning = pruning.as_str().ok_or_else(|| Error::custom("invalid pruning value"))?;
|
||||
let pruning = pruning.parse().map_err(|_| Error::custom("invalid pruning method"))?;
|
||||
|
Loading…
Reference in New Issue
Block a user