Serde 0.9 (#4508)
* Porting json * Dapps * Rpc & Ethstore * New ethabi * Last bunch of fixes * Fixing last test * Removing build script * Adding ethcore-ipc-tests back * Fixing grumbles * Fixing blockchain tests (inference regression?)
This commit is contained in:
committed by
Nikolay Volf
parent
a2c6cd8f7b
commit
f1e99ea2e4
@@ -16,8 +16,8 @@
|
||||
|
||||
//! Ethcore rpc.
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(feature="nightly", feature(custom_derive, custom_attribute, plugin))]
|
||||
#![cfg_attr(feature="nightly", plugin(serde_macros, clippy))]
|
||||
#![cfg_attr(feature="nightly", feature(plugin))]
|
||||
#![cfg_attr(feature="nightly", plugin(clippy))]
|
||||
|
||||
extern crate semver;
|
||||
extern crate rustc_serialize;
|
||||
@@ -51,6 +51,8 @@ extern crate log;
|
||||
extern crate ethcore_util as util;
|
||||
#[macro_use]
|
||||
extern crate jsonrpc_macros;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate ethjson;
|
||||
|
||||
@@ -388,7 +388,7 @@ fn should_decrypt_message_if_account_is_unlocked() {
|
||||
let encrypted: Success = serde_json::from_str(&tester.io.handle_request_sync(&request).unwrap()).unwrap();
|
||||
|
||||
// then call decrypt
|
||||
let request = format!("{}{:?}{}{:?}{}",
|
||||
let request = format!("{}{:?}{}{}{}",
|
||||
r#"{"jsonrpc": "2.0", "method": "parity_decryptMessage", "params":["0x"#,
|
||||
address,
|
||||
r#"","#,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use std::ops::Deref;
|
||||
use std::collections::BTreeMap;
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::ser::Error;
|
||||
use v1::types::{Bytes, Transaction, H160, H256, H2048, U256};
|
||||
|
||||
/// Block Transactions
|
||||
@@ -29,7 +30,7 @@ pub enum BlockTransactions {
|
||||
}
|
||||
|
||||
impl Serialize for BlockTransactions {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer {
|
||||
match *self {
|
||||
BlockTransactions::Hashes(ref hashes) => hashes.serialize(serializer),
|
||||
@@ -102,7 +103,7 @@ pub struct RichBlock {
|
||||
pub block: Block,
|
||||
/// Engine-specific fields with additional description.
|
||||
/// Should be included directly to serialized block object.
|
||||
#[serde(skip_serializing)]
|
||||
// TODO [ToDr] #[serde(skip_serializing)]
|
||||
pub extra_info: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
@@ -114,17 +115,18 @@ impl Deref for RichBlock {
|
||||
}
|
||||
|
||||
impl Serialize for RichBlock {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
use serde_json::{to_value, Value};
|
||||
|
||||
let serialized = (to_value(&self.block), to_value(&self.extra_info));
|
||||
if let (Value::Object(mut block), Value::Object(extras)) = serialized {
|
||||
if let (Ok(Value::Object(mut block)), Ok(Value::Object(extras))) = serialized {
|
||||
// join two objects
|
||||
block.extend(extras);
|
||||
// and serialize
|
||||
block.serialize(serializer)?;
|
||||
block.serialize(serializer)
|
||||
} else {
|
||||
Err(S::Error::custom("Unserializable structures."))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::{Deserialize, Deserializer, Error, Serialize, Serializer};
|
||||
use serde::de::Visitor;
|
||||
use std::fmt;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::de::{Error, Visitor};
|
||||
use ethcore::client::BlockId;
|
||||
|
||||
/// Represents rpc api block number param.
|
||||
@@ -38,8 +39,7 @@ impl Default for BlockNumber {
|
||||
}
|
||||
|
||||
impl Deserialize for BlockNumber {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<BlockNumber, D::Error>
|
||||
where D: Deserializer {
|
||||
fn deserialize<D>(deserializer: D) -> Result<BlockNumber, D::Error> where D: Deserializer {
|
||||
deserializer.deserialize(BlockNumberVisitor)
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ impl BlockNumber {
|
||||
}
|
||||
|
||||
impl Serialize for BlockNumber {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
match *self {
|
||||
BlockNumber::Num(ref x) => serializer.serialize_str(&format!("0x{:x}", x)),
|
||||
BlockNumber::Latest => serializer.serialize_str("latest"),
|
||||
@@ -70,7 +70,11 @@ struct BlockNumberVisitor;
|
||||
impl Visitor for BlockNumberVisitor {
|
||||
type Value = BlockNumber;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a block number or 'latest', 'earliest' or 'pending'")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
match value {
|
||||
"latest" => Ok(BlockNumber::Latest),
|
||||
"earliest" => Ok(BlockNumber::Earliest),
|
||||
@@ -80,7 +84,7 @@ impl Visitor for BlockNumberVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
fn visit_string<E>(self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
self.visit_str(value.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
//! Serializable wrapper around vector of bytes
|
||||
|
||||
use std::fmt;
|
||||
use rustc_serialize::hex::ToHex;
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer, Error};
|
||||
use serde::de::Visitor;
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
use serde::de::{Error, Visitor};
|
||||
use util::common::FromHex;
|
||||
|
||||
/// Wrapper structure around vector of bytes.
|
||||
@@ -49,7 +50,7 @@ impl Into<Vec<u8>> for Bytes {
|
||||
}
|
||||
|
||||
impl Serialize for Bytes {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer {
|
||||
let mut serialized = "0x".to_owned();
|
||||
serialized.push_str(self.0.to_hex().as_ref());
|
||||
@@ -58,7 +59,7 @@ impl Serialize for Bytes {
|
||||
}
|
||||
|
||||
impl Deserialize for Bytes {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<Bytes, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<Bytes, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(BytesVisitor)
|
||||
}
|
||||
@@ -69,7 +70,11 @@ struct BytesVisitor;
|
||||
impl Visitor for BytesVisitor {
|
||||
type Value = Bytes;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a 0x-prefixed, hex-encoded vector of bytes")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
if value.is_empty() {
|
||||
warn!(
|
||||
target: "deprecated",
|
||||
@@ -83,7 +88,7 @@ impl Visitor for BytesVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
fn visit_string<E>(self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
self.visit_str(value.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ pub enum ConfirmationResponse {
|
||||
}
|
||||
|
||||
impl Serialize for ConfirmationResponse {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
match *self {
|
||||
@@ -225,7 +225,7 @@ impl<A, B> Serialize for Either<A, B> where
|
||||
A: Serialize + fmt::Debug + Clone,
|
||||
B: Serialize + fmt::Debug + Clone,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
match *self {
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer, Error};
|
||||
use serde_json::value;
|
||||
use jsonrpc_core::Value;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::de::Error;
|
||||
use serde_json::{Value, from_value};
|
||||
use ethcore::filter::Filter as EthFilter;
|
||||
use ethcore::client::BlockId;
|
||||
use v1::types::{BlockNumber, H160, H256, Log};
|
||||
@@ -33,17 +33,17 @@ pub enum VariadicValue<T> where T: Deserialize {
|
||||
}
|
||||
|
||||
impl<T> Deserialize for VariadicValue<T> where T: Deserialize {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<VariadicValue<T>, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<VariadicValue<T>, D::Error>
|
||||
where D: Deserializer {
|
||||
let v = Value::deserialize(deserializer)?;
|
||||
let v: Value = Deserialize::deserialize(deserializer)?;
|
||||
|
||||
if v.is_null() {
|
||||
return Ok(VariadicValue::Null);
|
||||
}
|
||||
|
||||
Deserialize::deserialize(&mut value::Deserializer::new(v.clone())).map(VariadicValue::Single)
|
||||
.or_else(|_| Deserialize::deserialize(&mut value::Deserializer::new(v.clone())).map(VariadicValue::Multiple))
|
||||
.map_err(|_| Error::custom("")) // unreachable, but types must match
|
||||
from_value(v.clone()).map(VariadicValue::Single)
|
||||
.or_else(|_| from_value(v).map(VariadicValue::Multiple))
|
||||
.map_err(|_| D::Error::custom("Invalid type."))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ pub enum FilterChanges {
|
||||
}
|
||||
|
||||
impl Serialize for FilterChanges {
|
||||
fn serialize<S>(&self, s: &mut S) -> Result<(), S::Error> where S: Serializer {
|
||||
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
match *self {
|
||||
FilterChanges::Logs(ref logs) => logs.serialize(s),
|
||||
FilterChanges::Hashes(ref hashes) => hashes.serialize(s),
|
||||
|
||||
@@ -101,7 +101,7 @@ macro_rules! impl_hash {
|
||||
}
|
||||
|
||||
impl serde::Serialize for $name {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: serde::Serializer {
|
||||
let mut hex = "0x".to_owned();
|
||||
hex.push_str(&self.0.to_hex());
|
||||
@@ -110,16 +110,20 @@ macro_rules! impl_hash {
|
||||
}
|
||||
|
||||
impl serde::Deserialize for $name {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<$name, D::Error> where D: serde::Deserializer {
|
||||
fn deserialize<D>(deserializer: D) -> Result<$name, D::Error> where D: serde::Deserializer {
|
||||
struct HashVisitor;
|
||||
|
||||
impl serde::de::Visitor for HashVisitor {
|
||||
type Value = $name;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a 0x-prefixed, padded, hex-encoded hash of type {}", stringify!($name))
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> where E: serde::de::Error {
|
||||
|
||||
if value.len() != 2 + $size * 2 {
|
||||
return Err(serde::Error::custom("Invalid length."));
|
||||
return Err(E::custom("Invalid length."));
|
||||
}
|
||||
|
||||
match value[2..].from_hex() {
|
||||
@@ -128,11 +132,11 @@ macro_rules! impl_hash {
|
||||
result.copy_from_slice(v);
|
||||
Ok($name(result))
|
||||
},
|
||||
_ => Err(serde::Error::custom("Invalid hex value."))
|
||||
_ => Err(E::custom("Invalid hex value."))
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
|
||||
fn visit_string<E>(self, value: String) -> Result<Self::Value, E> where E: serde::de::Error {
|
||||
self.visit_str(value.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::{Deserialize, Deserializer, Error};
|
||||
use serde::de::Visitor;
|
||||
use std::fmt;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde::de::{Error, Visitor};
|
||||
|
||||
/// Represents usize.
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -29,7 +30,7 @@ impl Index {
|
||||
}
|
||||
|
||||
impl Deserialize for Index {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<Index, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<Index, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(IndexVisitor)
|
||||
}
|
||||
@@ -40,14 +41,18 @@ struct IndexVisitor;
|
||||
impl Visitor for IndexVisitor {
|
||||
type Value = Index;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a hex-encoded or decimal index")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
match value {
|
||||
_ if value.starts_with("0x") => usize::from_str_radix(&value[2..], 16).map(Index).map_err(|_| Error::custom("invalid index")),
|
||||
_ => value.parse::<usize>().map(Index).map_err(|_| Error::custom("invalid index"))
|
||||
_ => value.parse::<usize>().map(Index).map_err(|_| Error::custom("invalid index")),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
fn visit_string<E>(self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
self.visit_str(value.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,59 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Structures used in RPC communication
|
||||
|
||||
#[cfg(feature = "serde_macros")]
|
||||
include!("mod.rs.in");
|
||||
//! RPC types
|
||||
|
||||
#[cfg(not(feature = "serde_macros"))]
|
||||
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
|
||||
mod account_info;
|
||||
mod bytes;
|
||||
mod block;
|
||||
mod block_number;
|
||||
mod call_request;
|
||||
mod confirmations;
|
||||
mod dapp_id;
|
||||
mod filter;
|
||||
mod hash;
|
||||
mod index;
|
||||
mod log;
|
||||
mod sync;
|
||||
mod transaction;
|
||||
mod transaction_request;
|
||||
mod transaction_condition;
|
||||
mod receipt;
|
||||
mod rpc_settings;
|
||||
mod trace;
|
||||
mod trace_filter;
|
||||
mod uint;
|
||||
mod work;
|
||||
mod histogram;
|
||||
mod consensus_status;
|
||||
|
||||
pub use self::bytes::Bytes;
|
||||
pub use self::block::{RichBlock, Block, BlockTransactions};
|
||||
pub use self::block_number::BlockNumber;
|
||||
pub use self::call_request::CallRequest;
|
||||
pub use self::confirmations::{
|
||||
ConfirmationPayload, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken,
|
||||
TransactionModification, SignRequest, DecryptRequest, Either
|
||||
};
|
||||
pub use self::dapp_id::DappId;
|
||||
pub use self::filter::{Filter, FilterChanges};
|
||||
pub use self::hash::{H64, H160, H256, H512, H520, H2048};
|
||||
pub use self::index::Index;
|
||||
pub use self::log::Log;
|
||||
pub use self::sync::{
|
||||
SyncStatus, SyncInfo, Peers, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo,
|
||||
TransactionStats, ChainStatus, EthProtocolInfo, LesProtocolInfo,
|
||||
};
|
||||
pub use self::transaction::{Transaction, RichRawTransaction, LocalTransactionStatus};
|
||||
pub use self::transaction_request::TransactionRequest;
|
||||
pub use self::transaction_condition::TransactionCondition;
|
||||
pub use self::receipt::Receipt;
|
||||
pub use self::rpc_settings::RpcSettings;
|
||||
pub use self::trace::{LocalizedTrace, TraceResults};
|
||||
pub use self::trace_filter::TraceFilter;
|
||||
pub use self::uint::{U128, U256};
|
||||
pub use self::work::Work;
|
||||
pub use self::histogram::Histogram;
|
||||
pub use self::consensus_status::*;
|
||||
pub use self::account_info::{AccountInfo, HwAccountInfo};
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
mod account_info;
|
||||
mod bytes;
|
||||
mod block;
|
||||
mod block_number;
|
||||
mod call_request;
|
||||
mod confirmations;
|
||||
mod dapp_id;
|
||||
mod filter;
|
||||
mod hash;
|
||||
mod index;
|
||||
mod log;
|
||||
mod sync;
|
||||
mod transaction;
|
||||
mod transaction_request;
|
||||
mod transaction_condition;
|
||||
mod receipt;
|
||||
mod rpc_settings;
|
||||
mod trace;
|
||||
mod trace_filter;
|
||||
mod uint;
|
||||
mod work;
|
||||
mod histogram;
|
||||
mod consensus_status;
|
||||
|
||||
pub use self::bytes::Bytes;
|
||||
pub use self::block::{RichBlock, Block, BlockTransactions};
|
||||
pub use self::block_number::BlockNumber;
|
||||
pub use self::call_request::CallRequest;
|
||||
pub use self::confirmations::{
|
||||
ConfirmationPayload, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken,
|
||||
TransactionModification, SignRequest, DecryptRequest, Either
|
||||
};
|
||||
pub use self::dapp_id::DappId;
|
||||
pub use self::filter::{Filter, FilterChanges};
|
||||
pub use self::hash::{H64, H160, H256, H512, H520, H2048};
|
||||
pub use self::index::Index;
|
||||
pub use self::log::Log;
|
||||
pub use self::sync::{
|
||||
SyncStatus, SyncInfo, Peers, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo,
|
||||
TransactionStats, ChainStatus, EthProtocolInfo, LesProtocolInfo,
|
||||
};
|
||||
pub use self::transaction::{Transaction, RichRawTransaction, LocalTransactionStatus};
|
||||
pub use self::transaction_request::TransactionRequest;
|
||||
pub use self::transaction_condition::TransactionCondition;
|
||||
pub use self::receipt::Receipt;
|
||||
pub use self::rpc_settings::RpcSettings;
|
||||
pub use self::trace::{LocalizedTrace, TraceResults};
|
||||
pub use self::trace_filter::TraceFilter;
|
||||
pub use self::uint::{U128, U256};
|
||||
pub use self::work::Work;
|
||||
pub use self::histogram::Histogram;
|
||||
pub use self::consensus_status::*;
|
||||
pub use self::account_info::{AccountInfo, HwAccountInfo};
|
||||
@@ -139,7 +139,7 @@ pub enum SyncStatus {
|
||||
}
|
||||
|
||||
impl Serialize for SyncStatus {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer {
|
||||
match *self {
|
||||
SyncStatus::Info(ref info) => info.serialize(serializer),
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::ser::SerializeStruct;
|
||||
use ethcore::trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, trace, TraceError};
|
||||
use ethcore::trace as et;
|
||||
use ethcore::state_diff;
|
||||
@@ -200,7 +201,7 @@ impl From<account_diff::AccountDiff> for AccountDiff {
|
||||
pub struct StateDiff(BTreeMap<H160, AccountDiff>);
|
||||
|
||||
impl Serialize for StateDiff {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer {
|
||||
Serialize::serialize(&self.0, serializer)
|
||||
}
|
||||
@@ -428,41 +429,41 @@ pub struct LocalizedTrace {
|
||||
}
|
||||
|
||||
impl Serialize for LocalizedTrace {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
let mut state = serializer.serialize_struct("LocalizedTrace", 9)?;
|
||||
let mut struc = serializer.serialize_struct("LocalizedTrace", 9)?;
|
||||
match self.action {
|
||||
Action::Call(ref call) => {
|
||||
serializer.serialize_struct_elt(&mut state, "type", "call")?;
|
||||
serializer.serialize_struct_elt(&mut state, "action", call)?;
|
||||
struc.serialize_field("type", "call")?;
|
||||
struc.serialize_field("action", call)?;
|
||||
},
|
||||
Action::Create(ref create) => {
|
||||
serializer.serialize_struct_elt(&mut state, "type", "create")?;
|
||||
serializer.serialize_struct_elt(&mut state, "action", create)?;
|
||||
struc.serialize_field("type", "create")?;
|
||||
struc.serialize_field("action", create)?;
|
||||
},
|
||||
Action::Suicide(ref suicide) => {
|
||||
serializer.serialize_struct_elt(&mut state, "type", "suicide")?;
|
||||
serializer.serialize_struct_elt(&mut state, "action", suicide)?;
|
||||
struc.serialize_field("type", "suicide")?;
|
||||
struc.serialize_field("action", suicide)?;
|
||||
},
|
||||
}
|
||||
|
||||
match self.result {
|
||||
Res::Call(ref call) => serializer.serialize_struct_elt(&mut state, "result", call)?,
|
||||
Res::Create(ref create) => serializer.serialize_struct_elt(&mut state, "result", create)?,
|
||||
Res::FailedCall(ref error) => serializer.serialize_struct_elt(&mut state, "error", error.to_string())?,
|
||||
Res::FailedCreate(ref error) => serializer.serialize_struct_elt(&mut state, "error", error.to_string())?,
|
||||
Res::None => serializer.serialize_struct_elt(&mut state, "result", None as Option<u8>)?,
|
||||
Res::Call(ref call) => struc.serialize_field("result", call)?,
|
||||
Res::Create(ref create) => struc.serialize_field("result", create)?,
|
||||
Res::FailedCall(ref error) => struc.serialize_field("error", &error.to_string())?,
|
||||
Res::FailedCreate(ref error) => struc.serialize_field("error", &error.to_string())?,
|
||||
Res::None => struc.serialize_field("result", &None as &Option<u8>)?,
|
||||
}
|
||||
|
||||
serializer.serialize_struct_elt(&mut state, "traceAddress", &self.trace_address)?;
|
||||
serializer.serialize_struct_elt(&mut state, "subtraces", &self.subtraces)?;
|
||||
serializer.serialize_struct_elt(&mut state, "transactionPosition", &self.transaction_position)?;
|
||||
serializer.serialize_struct_elt(&mut state, "transactionHash", &self.transaction_hash)?;
|
||||
serializer.serialize_struct_elt(&mut state, "blockNumber", &self.block_number)?;
|
||||
serializer.serialize_struct_elt(&mut state, "blockHash", &self.block_hash)?;
|
||||
struc.serialize_field("traceAddress", &self.trace_address)?;
|
||||
struc.serialize_field("subtraces", &self.subtraces)?;
|
||||
struc.serialize_field("transactionPosition", &self.transaction_position)?;
|
||||
struc.serialize_field("transactionHash", &self.transaction_hash)?;
|
||||
struc.serialize_field("blockNumber", &self.block_number)?;
|
||||
struc.serialize_field("blockHash", &self.block_hash)?;
|
||||
|
||||
serializer.serialize_struct_end(state)
|
||||
struc.end()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,37 +496,37 @@ pub struct Trace {
|
||||
}
|
||||
|
||||
impl Serialize for Trace {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
let mut state = serializer.serialize_struct("Trace", 4)?;
|
||||
let mut struc = serializer.serialize_struct("Trace", 4)?;
|
||||
match self.action {
|
||||
Action::Call(ref call) => {
|
||||
serializer.serialize_struct_elt(&mut state, "type", "call")?;
|
||||
serializer.serialize_struct_elt(&mut state, "action", call)?;
|
||||
struc.serialize_field("type", "call")?;
|
||||
struc.serialize_field("action", call)?;
|
||||
},
|
||||
Action::Create(ref create) => {
|
||||
serializer.serialize_struct_elt(&mut state, "type", "create")?;
|
||||
serializer.serialize_struct_elt(&mut state, "action", create)?;
|
||||
struc.serialize_field("type", "create")?;
|
||||
struc.serialize_field("action", create)?;
|
||||
},
|
||||
Action::Suicide(ref suicide) => {
|
||||
serializer.serialize_struct_elt(&mut state, "type", "suicide")?;
|
||||
serializer.serialize_struct_elt(&mut state, "action", suicide)?;
|
||||
struc.serialize_field("type", "suicide")?;
|
||||
struc.serialize_field("action", suicide)?;
|
||||
},
|
||||
}
|
||||
|
||||
match self.result {
|
||||
Res::Call(ref call) => serializer.serialize_struct_elt(&mut state, "result", call)?,
|
||||
Res::Create(ref create) => serializer.serialize_struct_elt(&mut state, "result", create)?,
|
||||
Res::FailedCall(ref error) => serializer.serialize_struct_elt(&mut state, "error", error.to_string())?,
|
||||
Res::FailedCreate(ref error) => serializer.serialize_struct_elt(&mut state, "error", error.to_string())?,
|
||||
Res::None => serializer.serialize_struct_elt(&mut state, "result", None as Option<u8>)?,
|
||||
Res::Call(ref call) => struc.serialize_field("result", call)?,
|
||||
Res::Create(ref create) => struc.serialize_field("result", create)?,
|
||||
Res::FailedCall(ref error) => struc.serialize_field("error", &error.to_string())?,
|
||||
Res::FailedCreate(ref error) => struc.serialize_field("error", &error.to_string())?,
|
||||
Res::None => struc.serialize_field("result", &None as &Option<u8>)?,
|
||||
}
|
||||
|
||||
serializer.serialize_struct_elt(&mut state, "traceAddress", &self.trace_address)?;
|
||||
serializer.serialize_struct_elt(&mut state, "subtraces", &self.subtraces)?;
|
||||
struc.serialize_field("traceAddress", &self.trace_address)?;
|
||||
struc.serialize_field("subtraces", &self.subtraces)?;
|
||||
|
||||
serializer.serialize_struct_end(state)
|
||||
struc.end()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::ser::SerializeStruct;
|
||||
use ethcore::miner;
|
||||
use ethcore::contract_address;
|
||||
use ethcore::transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction};
|
||||
@@ -93,7 +94,7 @@ pub enum LocalTransactionStatus {
|
||||
}
|
||||
|
||||
impl Serialize for LocalTransactionStatus {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
use self::LocalTransactionStatus::*;
|
||||
@@ -108,35 +109,36 @@ impl Serialize for LocalTransactionStatus {
|
||||
let status = "status";
|
||||
let transaction = "transaction";
|
||||
|
||||
let mut state = serializer.serialize_struct("LocalTransactionStatus", elems)?;
|
||||
let mut struc = serializer.serialize_struct("LocalTransactionStatus", elems)?;
|
||||
match *self {
|
||||
Pending => serializer.serialize_struct_elt(&mut state, status, "pending")?,
|
||||
Future => serializer.serialize_struct_elt(&mut state, status, "future")?,
|
||||
Pending => struc.serialize_field(status, "pending")?,
|
||||
Future => struc.serialize_field(status, "future")?,
|
||||
Mined(ref tx) => {
|
||||
serializer.serialize_struct_elt(&mut state, status, "mined")?;
|
||||
serializer.serialize_struct_elt(&mut state, transaction, tx)?;
|
||||
struc.serialize_field(status, "mined")?;
|
||||
struc.serialize_field(transaction, tx)?;
|
||||
},
|
||||
Dropped(ref tx) => {
|
||||
serializer.serialize_struct_elt(&mut state, status, "dropped")?;
|
||||
serializer.serialize_struct_elt(&mut state, transaction, tx)?;
|
||||
struc.serialize_field(status, "dropped")?;
|
||||
struc.serialize_field(transaction, tx)?;
|
||||
},
|
||||
Invalid(ref tx) => {
|
||||
serializer.serialize_struct_elt(&mut state, status, "invalid")?;
|
||||
serializer.serialize_struct_elt(&mut state, transaction, tx)?;
|
||||
struc.serialize_field(status, "invalid")?;
|
||||
struc.serialize_field(transaction, tx)?;
|
||||
},
|
||||
Rejected(ref tx, ref reason) => {
|
||||
serializer.serialize_struct_elt(&mut state, status, "rejected")?;
|
||||
serializer.serialize_struct_elt(&mut state, transaction, tx)?;
|
||||
serializer.serialize_struct_elt(&mut state, "error", reason)?;
|
||||
struc.serialize_field(status, "rejected")?;
|
||||
struc.serialize_field(transaction, tx)?;
|
||||
struc.serialize_field("error", reason)?;
|
||||
},
|
||||
Replaced(ref tx, ref gas_price, ref hash) => {
|
||||
serializer.serialize_struct_elt(&mut state, status, "replaced")?;
|
||||
serializer.serialize_struct_elt(&mut state, transaction, tx)?;
|
||||
serializer.serialize_struct_elt(&mut state, "hash", hash)?;
|
||||
serializer.serialize_struct_elt(&mut state, "gasPrice", gas_price)?;
|
||||
struc.serialize_field(status, "replaced")?;
|
||||
struc.serialize_field(transaction, tx)?;
|
||||
struc.serialize_field("hash", hash)?;
|
||||
struc.serialize_field("gasPrice", gas_price)?;
|
||||
},
|
||||
}
|
||||
serializer.serialize_struct_end(state)
|
||||
|
||||
struc.end()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,33 +60,37 @@ macro_rules! impl_uint {
|
||||
}
|
||||
|
||||
impl serde::Serialize for $name {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
|
||||
serializer.serialize_str(&format!("0x{}", self.0.to_hex()))
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Deserialize for $name {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<$name, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<$name, D::Error>
|
||||
where D: serde::Deserializer {
|
||||
struct UintVisitor;
|
||||
|
||||
impl serde::de::Visitor for UintVisitor {
|
||||
type Value = $name;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a 0x-prefixed, hex-encoded number of type {}", stringify!($name))
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> where E: serde::de::Error {
|
||||
// 0x + len
|
||||
if value.len() > 2 + $size * 16 || value.len() < 2 {
|
||||
return Err(serde::Error::custom("Invalid length."));
|
||||
return Err(E::custom("Invalid length."));
|
||||
}
|
||||
|
||||
if &value[0..2] != "0x" {
|
||||
return Err(serde::Error::custom("Use hex encoded numbers with 0x prefix."))
|
||||
return Err(E::custom("Use hex encoded numbers with 0x prefix."))
|
||||
}
|
||||
|
||||
$other::from_str(&value[2..]).map($name).map_err(|_| serde::Error::custom("Invalid hex value."))
|
||||
$other::from_str(&value[2..]).map($name).map_err(|_| E::custom("Invalid hex value."))
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
|
||||
fn visit_string<E>(self, value: String) -> Result<Self::Value, E> where E: serde::de::Error {
|
||||
self.visit_str(&value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct Work {
|
||||
}
|
||||
|
||||
impl Serialize for Work {
|
||||
fn serialize<S>(&self, s: &mut S) -> Result<(), S::Error> where S: Serializer {
|
||||
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
match self.number.as_ref() {
|
||||
Some(num) => (&self.pow_hash, &self.seed_hash, &self.target, U256::from(*num)).serialize(s),
|
||||
None => (&self.pow_hash, &self.seed_hash, &self.target).serialize(s),
|
||||
|
||||
Reference in New Issue
Block a user