From 286526072fa5dfc3f355773b623af89fe3b20760 Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 4 Jul 2017 14:31:16 +0200 Subject: [PATCH] migrated ethkey, ethstore, evmbin and parity executables to serde 1.0 --- Cargo.lock | 49 ++++++++++++++++++++++----------- Cargo.toml | 11 ++++---- ethkey/cli/Cargo.toml | 4 ++- ethkey/cli/src/main.rs | 16 ++++++++--- ethstore/cli/Cargo.toml | 4 ++- ethstore/cli/src/main.rs | 58 +++++++++++++++++++++++++++++----------- evmbin/Cargo.toml | 5 ++-- evmbin/src/main.rs | 8 +++--- parity/blockchain.rs | 2 +- parity/cli/mod.rs | 34 +++++++++++------------ parity/cli/usage.rs | 46 ++++++++----------------------- parity/main.rs | 4 ++- parity/user_defaults.rs | 16 +++++------ 13 files changed, 150 insertions(+), 107 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17a28933b..ec2d1ec88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index d9b3734ec..429ea0dd4 100644 --- a/Cargo.toml +++ b/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" diff --git a/ethkey/cli/Cargo.toml b/ethkey/cli/Cargo.toml index b8da13908..3ea931e25 100644 --- a/ethkey/cli/Cargo.toml +++ b/ethkey/cli/Cargo.toml @@ -5,8 +5,10 @@ authors = ["Parity Technologies "] [dependencies] ethkey = { path = "../" } +serde = "1.0" +serde_derive = "1.0" rustc-hex = "1.0" -docopt = "0.7" +docopt = "0.8" [[bin]] name = "ethkey" diff --git a/ethkey/cli/src/main.rs b/ethkey/cli/src/main.rs index 53a6adb4d..0d96c2a89 100644 --- a/ethkey/cli/src/main.rs +++ b/ethkey/cli/src/main.rs @@ -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 for Error { @@ -103,12 +107,19 @@ impl From for Error { } } +impl From 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(command: I) -> Result where I: IntoIterator, S: AsRef { 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); diff --git a/ethstore/cli/Cargo.toml b/ethstore/cli/Cargo.toml index 09ec9d13f..80d20f792 100644 --- a/ethstore/cli/Cargo.toml +++ b/ethstore/cli/Cargo.toml @@ -5,7 +5,9 @@ authors = ["Parity Technologies "] [dependencies] rustc-hex = "1.0" -docopt = "0.7" +serde = "1.0" +serde_derive = "1.0" +docopt = "0.8" ethstore = { path = "../" } [[bin]] diff --git a/ethstore/cli/src/main.rs b/ethstore/cli/src/main.rs index b73f06711..06ebfcd20 100644 --- a/ethstore/cli/src/main.rs +++ b/ethstore/cli/src/main.rs @@ -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 for Error { + fn from(err: ethstore::Error) -> Self { + Error::Ethstore(err) + } +} + +impl From 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 { - 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 { fn execute(command: I) -> Result where I: IntoIterator, S: AsRef { 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(command: I) -> Result where I: IntoIterator(command: I) -> Result where I: IntoIterator(args: Args, mut informant: T) { informant.finish(result); } -#[derive(Debug, RustcDecodable)] +#[derive(Debug, Deserialize)] struct Args { cmd_stats: bool, flag_from: Option, diff --git a/parity/blockchain.rs b/parity/blockchain.rs index 17e486b5b..26de04f95 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -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; diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 5aea26000..2b678659c 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -381,7 +381,7 @@ usage! { } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Config { parity: Option, account: Option, @@ -401,7 +401,7 @@ struct Config { stratum: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Operating { mode: Option, mode_timeout: Option, @@ -420,7 +420,7 @@ struct Operating { no_persistent_txqueue: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Account { unlock: Option>, password: Option>, @@ -429,7 +429,7 @@ struct Account { fast_unlock: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Ui { force: Option, disable: Option, @@ -439,7 +439,7 @@ struct Ui { path: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Network { warp: Option, port: Option, @@ -458,7 +458,7 @@ struct Network { no_serve_light: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Rpc { disable: Option, port: Option, @@ -469,7 +469,7 @@ struct Rpc { threads: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Ws { disable: Option, port: Option, @@ -479,14 +479,14 @@ struct Ws { hosts: Option>, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Ipc { disable: Option, path: Option, apis: Option>, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Dapps { disable: Option, port: Option, @@ -498,7 +498,7 @@ struct Dapps { pass: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct SecretStore { disable: Option, self_secret: Option, @@ -510,7 +510,7 @@ struct SecretStore { path: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Ipfs { enable: Option, port: Option, @@ -519,7 +519,7 @@ struct Ipfs { hosts: Option>, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Mining { author: Option, engine_signer: Option, @@ -547,14 +547,14 @@ struct Mining { refuse_service_transactions: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Stratum { interface: Option, port: Option, secret: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Footprint { tracing: Option, pruning: Option, @@ -572,17 +572,17 @@ struct Footprint { num_verifiers: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Snapshots { disable_periodic: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct VM { jit: Option, } -#[derive(Default, Debug, PartialEq, RustcDecodable)] +#[derive(Default, Debug, PartialEq, Deserialize)] struct Misc { logging: Option, log_file: Option, diff --git a/parity/cli/usage.rs b/parity/cli/usage.rs index 949106ae7..26f697ed8 100644 --- a/parity/cli/usage.rs +++ b/parity/cli/usage.rs @@ -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), - 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 for ArgsError { - fn from(e: DocoptError) -> Self { ArgsError::Docopt(e) } + fn from(e: DocoptError) -> Self { + ArgsError::Docopt(e) + } } - impl From for ArgsError { - fn from(e: toml::DecodeError) -> Self { ArgsError::Decode(e) } + impl From 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 { - 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>(command: &[S]) -> Result { - 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 { diff --git a/parity/main.rs b/parity/main.rs index 65a621adf..dc009ff62 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -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; diff --git a/parity/user_defaults.rs b/parity/user_defaults.rs index cc1d8197b..12bb9937f 100644 --- a/parity/user_defaults.rs +++ b/parity/user_defaults.rs @@ -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(deserializer: D) -> Result - 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(self, visitor: V) -> Result where V: MapVisitor { - let mut map: BTreeMap = BTreeMapVisitor::new().visit_map(visitor)?; + fn visit_map(self, visitor: V) -> Result where V: MapAccess<'a> { + let mut map: BTreeMap = 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"))?;