Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5996 from paritytech/serdeup
Browse files Browse the repository at this point in the history
migration to serde 1.0
  • Loading branch information
rphmeier authored Jul 6, 2017
2 parents 6334893 + 5f2cb5e commit 104367c
Show file tree
Hide file tree
Showing 55 changed files with 422 additions and 434 deletions.
276 changes: 120 additions & 156 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions dapps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ mime = "0.2"
mime_guess = "1.6.1"
rand = "0.3"
rustc-hex = "1.0"
serde = "0.9"
serde_derive = "0.9"
serde_json = "0.9"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
time = "0.1.35"
unicase = "1.3"
url = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ byteorder = "1.0"
clippy = { version = "0.0.103", optional = true}
crossbeam = "0.2.9"
env_logger = "0.4"
ethabi = "1.0"
ethabi = "2.0"
ethash = { path = "../ethash" }
ethcore-bloom-journal = { path = "../util/bloom" }
ethcore-devtools = { path = "../devtools" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/native_contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
build = "build.rs"

[dependencies]
ethabi = "1.0"
ethabi = "2.0"
futures = "0.1"
byteorder = "1.0"
ethcore-util = { path = "../../util" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/native_contracts/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
ethabi = "1.0"
ethabi = "2.0"
heck = "0.2"
2 changes: 1 addition & 1 deletion ethcore/native_contracts/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn {snake_name}<F, U>(&self, call: F, {params}) -> BoxFuture<{output_type},
U: IntoFuture<Item=Vec<u8>, Error=String>,
U::Future: Send + 'static
{{
let function = self.contract.function(r#"{abi_name}"#.to_string())
let function = self.contract.function(r#"{abi_name}"#)
.expect("function existence checked at compile-time; qed");
let call_addr = self.address;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/validator_set/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl ValidatorSafeContract {

// decode log manually until the native contract generator is
// good enough to do it for us.
let &(_, _, ref validators_token) = &matched_event.params[1];
let validators_token = &matched_event[1].value;

let validators = validators_token.clone().to_array()
.and_then(|a| a.into_iter()
Expand Down
4 changes: 3 additions & 1 deletion ethkey/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 13 additions & 3 deletions ethkey/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -83,6 +86,7 @@ enum Error {
Ethkey(EthkeyError),
FromHex(FromHexError),
ParseInt(ParseIntError),
Docopt(docopt::Error),
}

impl From<EthkeyError> for Error {
Expand All @@ -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),
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ log = "0.3"
libc = "0.2"
rand = "0.3"
ethkey = { path = "../ethkey" }
serde = "0.9"
serde_json = "0.9"
serde_derive = "0.9"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
rustc-hex = "1.0"
rust-crypto = "0.2.36"
tiny-keccak = "1.0"
Expand Down
4 changes: 3 additions & 1 deletion ethstore/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
58 changes: 43 additions & 15 deletions ethstore/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -159,29 +188,28 @@ 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)
}

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)?;
Expand Down Expand Up @@ -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)?;
Expand All @@ -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))?;
Expand Down
4 changes: 2 additions & 2 deletions ethstore/src/json/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ impl ops::Deref for Bytes {
}
}

impl Deserialize for Bytes {
impl<'a> Deserialize<'a> for Bytes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer
where D: Deserializer<'a>
{
let s = String::deserialize(deserializer)?;
let data = s.from_hex().map_err(|e| Error::custom(format!("Invalid hex value {}", e)))?;
Expand Down
12 changes: 6 additions & 6 deletions ethstore/src/json/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ impl Serialize for CipherSer {
}
}

impl Deserialize for CipherSer {
impl<'a> Deserialize<'a> for CipherSer {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer {
deserializer.deserialize(CipherSerVisitor)
where D: Deserializer<'a> {
deserializer.deserialize_any(CipherSerVisitor)
}
}

struct CipherSerVisitor;

impl Visitor for CipherSerVisitor {
impl<'a> Visitor<'a> for CipherSerVisitor {
type Value = CipherSer;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -80,9 +80,9 @@ impl Serialize for CipherSerParams {
}
}

impl Deserialize for CipherSerParams {
impl<'a> Deserialize<'a> for CipherSerParams {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer {
where D: Deserializer<'a> {
Aes128Ctr::deserialize(deserializer)
.map(CipherSerParams::Aes128Ctr)
.map_err(|_| Error::InvalidCipherParams)
Expand Down
Loading

0 comments on commit 104367c

Please sign in to comment.