migrated ethjson to serde 1.0
This commit is contained in:
parent
286526072f
commit
9c911c7a28
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -685,9 +685,9 @@ dependencies = [
|
|||||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethcore-util 1.7.0",
|
"ethcore-util 1.7.0",
|
||||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 0.9.6 (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 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6,8 +6,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
rustc-hex = "1.0"
|
rustc-hex = "1.0"
|
||||||
serde = "0.9"
|
serde = "1.0"
|
||||||
serde_json = "0.9"
|
serde_json = "1.0"
|
||||||
serde_derive = "0.9"
|
serde_derive = "1.0"
|
||||||
clippy = { version = "0.0.103", optional = true}
|
clippy = { version = "0.0.103", optional = true}
|
||||||
|
|
||||||
|
@ -67,16 +67,16 @@ impl FromStr for Bytes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserialize for Bytes {
|
impl<'a> Deserialize<'a> for Bytes {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer {
|
where D: Deserializer<'a> {
|
||||||
deserializer.deserialize(BytesVisitor)
|
deserializer.deserialize_any(BytesVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BytesVisitor;
|
struct BytesVisitor;
|
||||||
|
|
||||||
impl Visitor for BytesVisitor {
|
impl<'a> Visitor<'a> for BytesVisitor {
|
||||||
type Value = Bytes;
|
type Value = Bytes;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
@ -42,13 +42,13 @@ macro_rules! impl_hash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserialize for $name {
|
impl<'a> Deserialize<'a> for $name {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer {
|
where D: Deserializer<'a> {
|
||||||
|
|
||||||
struct HashVisitor;
|
struct HashVisitor;
|
||||||
|
|
||||||
impl Visitor for HashVisitor {
|
impl<'b> Visitor<'b> for HashVisitor {
|
||||||
type Value = $name;
|
type Value = $name;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
@ -75,7 +75,7 @@ macro_rules! impl_hash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializer.deserialize(HashVisitor)
|
deserializer.deserialize_any(HashVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
use serde::de::{Error, Visitor};
|
use serde::de::{Error, Visitor, IntoDeserializer};
|
||||||
use serde::de::value::ValueDeserializer;
|
|
||||||
|
|
||||||
/// Deserializer of empty string values into optionals.
|
/// Deserializer of empty string values into optionals.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -16,10 +15,10 @@ pub enum MaybeEmpty<T> {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Deserialize for MaybeEmpty<T> where T: Deserialize {
|
impl<'a, T> Deserialize<'a> for MaybeEmpty<T> where T: Deserialize<'a> {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer {
|
where D: Deserializer<'a> {
|
||||||
deserializer.deserialize(MaybeEmptyVisitor::new())
|
deserializer.deserialize_any(MaybeEmptyVisitor::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ impl<T> MaybeEmptyVisitor<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Visitor for MaybeEmptyVisitor<T> where T: Deserialize {
|
impl<'a, T> Visitor<'a> for MaybeEmptyVisitor<T> where T: Deserialize<'a> {
|
||||||
type Value = MaybeEmpty<T>;
|
type Value = MaybeEmpty<T>;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
@ -236,6 +236,7 @@ mod tests {
|
|||||||
eip161d_transition: Some(Uint(U256::from(0x47))),
|
eip161d_transition: Some(Uint(U256::from(0x47))),
|
||||||
ecip1010_pause_transition: None,
|
ecip1010_pause_transition: None,
|
||||||
ecip1010_continue_transition: None,
|
ecip1010_continue_transition: None,
|
||||||
|
ecip1017_era_rounds: None,
|
||||||
max_code_size: None,
|
max_code_size: None,
|
||||||
max_gas_limit_transition: None,
|
max_gas_limit_transition: None,
|
||||||
max_gas_limit: None,
|
max_gas_limit: None,
|
||||||
@ -282,6 +283,7 @@ mod tests {
|
|||||||
eip161d_transition: None,
|
eip161d_transition: None,
|
||||||
ecip1010_pause_transition: None,
|
ecip1010_pause_transition: None,
|
||||||
ecip1010_continue_transition: None,
|
ecip1010_continue_transition: None,
|
||||||
|
ecip1017_era_rounds: None,
|
||||||
max_code_size: None,
|
max_code_size: None,
|
||||||
max_gas_limit_transition: None,
|
max_gas_limit_transition: None,
|
||||||
max_gas_limit: None,
|
max_gas_limit: None,
|
||||||
|
@ -21,7 +21,7 @@ use std::collections::BTreeMap;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
use serde::de::{Error as ErrorTrait, Visitor, MapVisitor, SeqVisitor};
|
use serde::de::{Error as ErrorTrait, Visitor, MapAccess, SeqAccess};
|
||||||
|
|
||||||
/// Trie test input.
|
/// Trie test input.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -30,35 +30,35 @@ pub struct Input {
|
|||||||
pub data: BTreeMap<Bytes, Option<Bytes>>,
|
pub data: BTreeMap<Bytes, Option<Bytes>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserialize for Input {
|
impl<'a> Deserialize<'a> for Input {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer
|
where D: Deserializer<'a>
|
||||||
{
|
{
|
||||||
deserializer.deserialize(InputVisitor)
|
deserializer.deserialize_any(InputVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InputVisitor;
|
struct InputVisitor;
|
||||||
|
|
||||||
impl Visitor for InputVisitor {
|
impl<'a> Visitor<'a> for InputVisitor {
|
||||||
type Value = Input;
|
type Value = Input;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(formatter, "a map of bytes into bytes")
|
write!(formatter, "a map of bytes into bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: MapVisitor {
|
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: MapAccess<'a> {
|
||||||
let mut result = BTreeMap::new();
|
let mut result = BTreeMap::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let key_str: Option<String> = visitor.visit_key()?;
|
let key_str: Option<String> = visitor.next_key()?;
|
||||||
let key = match key_str {
|
let key = match key_str {
|
||||||
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(V::Error::custom)?,
|
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(V::Error::custom)?,
|
||||||
Some(k) => Bytes::new(k.into_bytes()),
|
Some(k) => Bytes::new(k.into_bytes()),
|
||||||
None => { break; }
|
None => { break; }
|
||||||
};
|
};
|
||||||
|
|
||||||
let val_str: Option<String> = visitor.visit_value()?;
|
let val_str: Option<String> = visitor.next_value()?;
|
||||||
let val = match val_str {
|
let val = match val_str {
|
||||||
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(V::Error::custom)?),
|
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(V::Error::custom)?),
|
||||||
Some(v) => Some(Bytes::new(v.into_bytes())),
|
Some(v) => Some(Bytes::new(v.into_bytes())),
|
||||||
@ -75,11 +75,11 @@ impl Visitor for InputVisitor {
|
|||||||
Ok(input)
|
Ok(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: SeqVisitor {
|
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: SeqAccess<'a> {
|
||||||
let mut result = BTreeMap::new();
|
let mut result = BTreeMap::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let keyval: Option<Vec<Option<String>>> = visitor.visit()?;
|
let keyval: Option<Vec<Option<String>>> = visitor.next_element()?;
|
||||||
let keyval = match keyval {
|
let keyval = match keyval {
|
||||||
Some(k) => k,
|
Some(k) => k,
|
||||||
_ => { break; },
|
_ => { break; },
|
||||||
|
@ -50,16 +50,16 @@ impl Into<u8> for Uint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserialize for Uint {
|
impl<'a> Deserialize<'a> for Uint {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer {
|
where D: Deserializer<'a> {
|
||||||
deserializer.deserialize(UintVisitor)
|
deserializer.deserialize_any(UintVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UintVisitor;
|
struct UintVisitor;
|
||||||
|
|
||||||
impl Visitor for UintVisitor {
|
impl<'a> Visitor<'a> for UintVisitor {
|
||||||
type Value = Uint;
|
type Value = Uint;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
Loading…
Reference in New Issue
Block a user