updated serde to version 1.0
This commit is contained in:
@@ -8,10 +8,10 @@ log = "0.3"
|
||||
libc = "0.2"
|
||||
rand = "0.3"
|
||||
ethkey = { path = "../ethkey" }
|
||||
serde = "0.9"
|
||||
serde_json = "0.9"
|
||||
serde_derive = "0.9"
|
||||
rustc-serialize = "0.3"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
rustc-hex = "1.0"
|
||||
rust-crypto = "0.2.36"
|
||||
tiny-keccak = "1.0"
|
||||
time = "0.1.34"
|
||||
|
||||
@@ -4,8 +4,10 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
rustc-serialize = "0.3"
|
||||
docopt = "0.7"
|
||||
rustc-hex = "1.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
docopt = "0.8"
|
||||
ethstore = { path = "../" }
|
||||
|
||||
[[bin]]
|
||||
|
||||
@@ -14,16 +14,19 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate rustc_serialize;
|
||||
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))?;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use std::{ops, str};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::de::Error;
|
||||
use rustc_serialize::hex::{ToHex, FromHex, FromHexError};
|
||||
use rustc_hex::{ToHex, FromHex, FromHexError};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Bytes(Vec<u8>);
|
||||
@@ -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)))?;
|
||||
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use std::{fmt, str};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::de::{Visitor, MapVisitor, Error};
|
||||
use serde::de::{Visitor, MapAccess, Error};
|
||||
use serde_json;
|
||||
use super::{Cipher, CipherSer, CipherSerParams, Kdf, KdfSer, KdfSerParams, H256, Bytes};
|
||||
|
||||
@@ -54,17 +54,17 @@ enum CryptoField {
|
||||
Mac,
|
||||
}
|
||||
|
||||
impl Deserialize for CryptoField {
|
||||
impl<'a> Deserialize<'a> for CryptoField {
|
||||
fn deserialize<D>(deserializer: D) -> Result<CryptoField, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'a>
|
||||
{
|
||||
deserializer.deserialize(CryptoFieldVisitor)
|
||||
deserializer.deserialize_any(CryptoFieldVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct CryptoFieldVisitor;
|
||||
|
||||
impl Visitor for CryptoFieldVisitor {
|
||||
impl<'a> Visitor<'a> for CryptoFieldVisitor {
|
||||
type Value = CryptoField;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -86,9 +86,9 @@ impl Visitor for CryptoFieldVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Crypto {
|
||||
impl<'a> Deserialize<'a> for Crypto {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Crypto, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'a>
|
||||
{
|
||||
static FIELDS: &'static [&'static str] = &["id", "version", "crypto", "Crypto", "address"];
|
||||
deserializer.deserialize_struct("Crypto", FIELDS, CryptoVisitor)
|
||||
@@ -97,7 +97,7 @@ impl Deserialize for Crypto {
|
||||
|
||||
struct CryptoVisitor;
|
||||
|
||||
impl Visitor for CryptoVisitor {
|
||||
impl<'a> Visitor<'a> for CryptoVisitor {
|
||||
type Value = Crypto;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -105,7 +105,7 @@ impl Visitor for CryptoVisitor {
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapAccess<'a>
|
||||
{
|
||||
let mut cipher = None;
|
||||
let mut cipherparams = None;
|
||||
@@ -115,13 +115,13 @@ impl Visitor for CryptoVisitor {
|
||||
let mut mac = None;
|
||||
|
||||
loop {
|
||||
match visitor.visit_key()? {
|
||||
Some(CryptoField::Cipher) => { cipher = Some(visitor.visit_value()?); }
|
||||
Some(CryptoField::CipherParams) => { cipherparams = Some(visitor.visit_value()?); }
|
||||
Some(CryptoField::CipherText) => { ciphertext = Some(visitor.visit_value()?); }
|
||||
Some(CryptoField::Kdf) => { kdf = Some(visitor.visit_value()?); }
|
||||
Some(CryptoField::KdfParams) => { kdfparams = Some(visitor.visit_value()?); }
|
||||
Some(CryptoField::Mac) => { mac = Some(visitor.visit_value()?); }
|
||||
match visitor.next_key()? {
|
||||
Some(CryptoField::Cipher) => { cipher = Some(visitor.next_value()?); }
|
||||
Some(CryptoField::CipherParams) => { cipherparams = Some(visitor.next_value()?); }
|
||||
Some(CryptoField::CipherText) => { ciphertext = Some(visitor.next_value()?); }
|
||||
Some(CryptoField::Kdf) => { kdf = Some(visitor.next_value()?); }
|
||||
Some(CryptoField::KdfParams) => { kdfparams = Some(visitor.next_value()?); }
|
||||
Some(CryptoField::Mac) => { mac = Some(visitor.next_value()?); }
|
||||
None => { break; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{ops, fmt, str};
|
||||
use rustc_serialize::hex::{FromHex, ToHex};
|
||||
use rustc_hex::{FromHex, ToHex};
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
use serde::de::{Visitor, Error as SerdeError};
|
||||
use super::Error;
|
||||
@@ -54,12 +54,12 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for $name {
|
||||
impl<'a> Deserialize<'a> for $name {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
where D: Deserializer<'a> {
|
||||
struct HashVisitor;
|
||||
|
||||
impl Visitor for HashVisitor {
|
||||
impl<'b> Visitor<'b> for HashVisitor {
|
||||
type Value = $name;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -75,7 +75,7 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize(HashVisitor)
|
||||
deserializer.deserialize_any(HashVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Universaly unique identifier.
|
||||
use std::{fmt, str};
|
||||
use rustc_serialize::hex::{ToHex, FromHex};
|
||||
use rustc_hex::{ToHex, FromHex};
|
||||
use serde::{Deserialize, Serialize, Deserializer, Serializer};
|
||||
use serde::de::{Visitor, Error as SerdeError};
|
||||
use super::Error;
|
||||
@@ -108,16 +108,16 @@ impl Serialize for Uuid {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Uuid {
|
||||
impl<'a> Deserialize<'a> for Uuid {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(UuidVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(UuidVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct UuidVisitor;
|
||||
|
||||
impl Visitor for UuidVisitor {
|
||||
impl<'a> Visitor<'a> for UuidVisitor {
|
||||
type Value = Uuid;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
||||
@@ -35,16 +35,16 @@ impl Serialize for KdfSer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for KdfSer {
|
||||
impl<'a> Deserialize<'a> for KdfSer {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(KdfSerVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(KdfSerVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct KdfSerVisitor;
|
||||
|
||||
impl Visitor for KdfSerVisitor {
|
||||
impl<'a> Visitor<'a> for KdfSerVisitor {
|
||||
type Value = KdfSer;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -78,16 +78,16 @@ impl Serialize for Prf {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Prf {
|
||||
impl<'a> Deserialize<'a> for Prf {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(PrfVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(PrfVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct PrfVisitor;
|
||||
|
||||
impl Visitor for PrfVisitor {
|
||||
impl<'a> Visitor<'a> for PrfVisitor {
|
||||
type Value = Prf;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -139,9 +139,9 @@ impl Serialize for KdfSerParams {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for KdfSerParams {
|
||||
impl<'a> Deserialize<'a> for KdfSerParams {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
where D: Deserializer<'a> {
|
||||
use serde_json::{Value, from_value};
|
||||
|
||||
let v: Value = Deserialize::deserialize(deserializer)?;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use std::fmt;
|
||||
use std::io::{Read, Write};
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
use serde::de::{Error, Visitor, MapVisitor};
|
||||
use serde::de::{Error, Visitor, MapAccess, DeserializeOwned};
|
||||
use serde_json;
|
||||
use super::{Uuid, Version, Crypto, H160};
|
||||
|
||||
@@ -60,17 +60,17 @@ enum KeyFileField {
|
||||
Meta,
|
||||
}
|
||||
|
||||
impl Deserialize for KeyFileField {
|
||||
impl<'a> Deserialize<'a> for KeyFileField {
|
||||
fn deserialize<D>(deserializer: D) -> Result<KeyFileField, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'a>
|
||||
{
|
||||
deserializer.deserialize(KeyFileFieldVisitor)
|
||||
deserializer.deserialize_any(KeyFileFieldVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct KeyFileFieldVisitor;
|
||||
|
||||
impl Visitor for KeyFileFieldVisitor {
|
||||
impl<'a> Visitor<'a> for KeyFileFieldVisitor {
|
||||
type Value = KeyFileField;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -93,9 +93,9 @@ impl Visitor for KeyFileFieldVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for KeyFile {
|
||||
impl<'a> Deserialize<'a> for KeyFile {
|
||||
fn deserialize<D>(deserializer: D) -> Result<KeyFile, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'a>
|
||||
{
|
||||
static FIELDS: &'static [&'static str] = &["id", "version", "crypto", "Crypto", "address"];
|
||||
deserializer.deserialize_struct("KeyFile", FIELDS, KeyFileVisitor)
|
||||
@@ -103,8 +103,8 @@ impl Deserialize for KeyFile {
|
||||
}
|
||||
|
||||
|
||||
fn none_if_empty<T>(v: Option<serde_json::Value>) -> Option<T> where
|
||||
T: Deserialize,
|
||||
fn none_if_empty<'a, T>(v: Option<serde_json::Value>) -> Option<T> where
|
||||
T: DeserializeOwned
|
||||
{
|
||||
v.and_then(|v| if v.is_null() {
|
||||
None
|
||||
@@ -115,7 +115,7 @@ fn none_if_empty<T>(v: Option<serde_json::Value>) -> Option<T> where
|
||||
}
|
||||
|
||||
struct KeyFileVisitor;
|
||||
impl Visitor for KeyFileVisitor {
|
||||
impl<'a> Visitor<'a> for KeyFileVisitor {
|
||||
type Value = KeyFile;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -123,7 +123,7 @@ impl Visitor for KeyFileVisitor {
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapAccess<'a>
|
||||
{
|
||||
let mut id = None;
|
||||
let mut version = None;
|
||||
@@ -133,13 +133,13 @@ impl Visitor for KeyFileVisitor {
|
||||
let mut meta = None;
|
||||
|
||||
loop {
|
||||
match visitor.visit_key()? {
|
||||
Some(KeyFileField::Id) => { id = Some(visitor.visit_value()?); }
|
||||
Some(KeyFileField::Version) => { version = Some(visitor.visit_value()?); }
|
||||
Some(KeyFileField::Crypto) => { crypto = Some(visitor.visit_value()?); }
|
||||
Some(KeyFileField::Address) => { address = Some(visitor.visit_value()?); }
|
||||
Some(KeyFileField::Name) => { name = none_if_empty(visitor.visit_value().ok()) }
|
||||
Some(KeyFileField::Meta) => { meta = none_if_empty(visitor.visit_value().ok()) }
|
||||
match visitor.next_key()? {
|
||||
Some(KeyFileField::Id) => { id = Some(visitor.next_value()?); }
|
||||
Some(KeyFileField::Version) => { version = Some(visitor.next_value()?); }
|
||||
Some(KeyFileField::Crypto) => { crypto = Some(visitor.next_value()?); }
|
||||
Some(KeyFileField::Address) => { address = Some(visitor.next_value()?); }
|
||||
Some(KeyFileField::Name) => { name = none_if_empty(visitor.next_value().ok()) }
|
||||
Some(KeyFileField::Meta) => { meta = none_if_empty(visitor.next_value().ok()) }
|
||||
None => { break; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,16 @@ impl Serialize for Version {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Version {
|
||||
impl<'a> Deserialize<'a> for Version {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Version, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(VersionVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(VersionVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct VersionVisitor;
|
||||
|
||||
impl Visitor for VersionVisitor {
|
||||
impl<'a> Visitor<'a> for VersionVisitor {
|
||||
type Value = Version;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
||||
@@ -23,7 +23,7 @@ extern crate itertools;
|
||||
extern crate libc;
|
||||
extern crate parking_lot;
|
||||
extern crate rand;
|
||||
extern crate rustc_serialize;
|
||||
extern crate rustc_hex;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate smallvec;
|
||||
|
||||
Reference in New Issue
Block a user