updated serde to version 1.0

This commit is contained in:
debris
2017-07-06 11:36:15 +02:00
parent cc718bb108
commit 61d8f90530
116 changed files with 553 additions and 662 deletions

View File

@@ -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;

View File

@@ -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>,

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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"))?;