From 8509a183edd079c78495b078a1d2a15514a07597 Mon Sep 17 00:00:00 2001 From: keorn Date: Wed, 14 Dec 2016 12:14:04 +0100 Subject: [PATCH] deserialize new seal --- json/src/hash.rs | 3 ++- json/src/spec/mod.rs | 2 +- json/src/spec/seal.rs | 27 ++++++++++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/json/src/hash.rs b/json/src/hash.rs index 9aad33115..b09c596f1 100644 --- a/json/src/hash.rs +++ b/json/src/hash.rs @@ -20,7 +20,7 @@ use std::str::FromStr; use serde::{Deserialize, Deserializer, Serialize, Serializer, Error}; use serde::de::Visitor; use rustc_serialize::hex::ToHex; -use util::hash::{H64 as Hash64, H160 as Hash160, H256 as Hash256, H2048 as Hash2048}; +use util::hash::{H64 as Hash64, H160 as Hash160, H256 as Hash256, H520 as Hash520, H2048 as Hash2048}; macro_rules! impl_hash { @@ -87,6 +87,7 @@ macro_rules! impl_hash { impl_hash!(H64, Hash64); impl_hash!(Address, Hash160); impl_hash!(H256, Hash256); +impl_hash!(H520, Hash520); impl_hash!(Bloom, Hash2048); #[cfg(test)] diff --git a/json/src/spec/mod.rs b/json/src/spec/mod.rs index 19b9974d9..dcd1f3361 100644 --- a/json/src/spec/mod.rs +++ b/json/src/spec/mod.rs @@ -33,7 +33,7 @@ pub use self::builtin::{Builtin, Pricing, Linear}; pub use self::genesis::Genesis; pub use self::params::Params; pub use self::spec::Spec; -pub use self::seal::{Seal, Ethereum, Generic}; +pub use self::seal::{Seal, Ethereum, AuthorityRoundSeal}; pub use self::engine::Engine; pub use self::state::State; pub use self::ethash::{Ethash, EthashParams}; diff --git a/json/src/spec/seal.rs b/json/src/spec/seal.rs index eba75840a..d586ed501 100644 --- a/json/src/spec/seal.rs +++ b/json/src/spec/seal.rs @@ -16,7 +16,8 @@ //! Spec seal deserialization. -use hash::{H64, H256}; +use hash::*; +use uint::Uint; use bytes::Bytes; /// Ethereum seal. @@ -29,11 +30,13 @@ pub struct Ethereum { pub mix_hash: H256, } -/// Generic seal. +/// AuthorityRound seal. #[derive(Debug, PartialEq, Deserialize)] -pub struct Generic { - /// Seal rlp. - pub rlp: Bytes, +pub struct AuthorityRoundSeal { + /// Seal step. + pub step: Uint, + /// Seal signature. + pub signature: H520, } /// Seal variants. @@ -42,9 +45,12 @@ pub enum Seal { /// Ethereum seal. #[serde(rename="ethereum")] Ethereum(Ethereum), + /// AuthorityRound seal. + #[serde(rename="authority_round")] + AuthorityRound(AuthorityRoundSeal), /// Generic seal. #[serde(rename="generic")] - Generic(Generic), + Generic(Bytes), } #[cfg(test)] @@ -53,15 +59,18 @@ mod tests { use spec::Seal; #[test] - fn builtin_deserialization() { + fn seal_deserialization() { let s = r#"[{ "ethereum": { "nonce": "0x0000000000000042", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" } },{ - "generic": { - "rlp": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" + "generic": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" + },{ + "authority_round": { + "step": "0x0", + "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } }]"#; let _deserialized: Vec = serde_json::from_str(s).unwrap();