From 552a772cc18c10a4926f2fd543f17e038bd0fc98 Mon Sep 17 00:00:00 2001 From: keorn Date: Thu, 22 Dec 2016 07:06:40 +0100 Subject: [PATCH] make fields defaulting to 0 optional --- ethcore/src/spec/genesis.rs | 8 ++++---- ethcore/src/spec/spec.rs | 2 +- json/src/blockchain/blockchain.rs | 6 +++--- json/src/spec/genesis.rs | 12 ++++++------ json/src/spec/params.rs | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ethcore/src/spec/genesis.rs b/ethcore/src/spec/genesis.rs index be3b7c808..1fad0836d 100644 --- a/ethcore/src/spec/genesis.rs +++ b/ethcore/src/spec/genesis.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::{Address, H256, Uint, U256}; +use util::{Address, H256, Uint, U256, FixedHash}; use util::sha3::SHA3_NULL_RLP; use ethjson; use super::seal::Seal; @@ -50,9 +50,9 @@ impl From for Genesis { Genesis { seal: From::from(g.seal), difficulty: g.difficulty.into(), - author: g.author.into(), - timestamp: g.timestamp.into(), - parent_hash: g.parent_hash.into(), + author: g.author.map_or_else(Address::zero, Into::into), + timestamp: g.timestamp.map_or(0, Into::into), + parent_hash: g.parent_hash.map_or_else(H256::zero, Into::into), gas_limit: g.gas_limit.into(), transactions_root: g.transactions_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into), receipts_root: g.receipts_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into), diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index bdcd5eee2..b6a688402 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -49,7 +49,7 @@ pub struct CommonParams { impl From for CommonParams { fn from(p: ethjson::spec::Params) -> Self { CommonParams { - account_start_nonce: p.account_start_nonce.into(), + account_start_nonce: p.account_start_nonce.map_or_else(U256::zero, Into::into), maximum_extra_data_size: p.maximum_extra_data_size.into(), network_id: p.network_id.into(), subprotocol_name: p.subprotocol_name.unwrap_or_else(|| "eth".to_owned()), diff --git a/json/src/blockchain/blockchain.rs b/json/src/blockchain/blockchain.rs index 8a0de8801..9d18796da 100644 --- a/json/src/blockchain/blockchain.rs +++ b/json/src/blockchain/blockchain.rs @@ -59,9 +59,9 @@ impl BlockChain { mix_hash: self.genesis_block.mix_hash.clone(), }), difficulty: self.genesis_block.difficulty, - author: self.genesis_block.author.clone(), - timestamp: self.genesis_block.timestamp, - parent_hash: self.genesis_block.parent_hash.clone(), + author: Some(self.genesis_block.author.clone()), + timestamp: Some(self.genesis_block.timestamp), + parent_hash: Some(self.genesis_block.parent_hash.clone()), gas_limit: self.genesis_block.gas_limit, transactions_root: Some(self.genesis_block.transactions_root.clone()), receipts_root: Some(self.genesis_block.receipts_root.clone()), diff --git a/json/src/spec/genesis.rs b/json/src/spec/genesis.rs index c732a1293..393bc49d5 100644 --- a/json/src/spec/genesis.rs +++ b/json/src/spec/genesis.rs @@ -28,13 +28,13 @@ pub struct Genesis { pub seal: Seal, /// Difficulty. pub difficulty: Uint, - /// Block author. - pub author: Address, - /// Block timestamp. - pub timestamp: Uint, - /// Parent hash. + /// Block author, defaults to 0. + pub author: Option
, + /// Block timestamp, defaults to 0. + pub timestamp: Option, + /// Parent hash, defaults to 0. #[serde(rename="parentHash")] - pub parent_hash: H256, + pub parent_hash: Option, /// Gas limit. #[serde(rename="gasLimit")] pub gas_limit: Uint, diff --git a/json/src/spec/params.rs b/json/src/spec/params.rs index 882686319..f4492f874 100644 --- a/json/src/spec/params.rs +++ b/json/src/spec/params.rs @@ -22,9 +22,9 @@ use hash::H256; /// Spec params. #[derive(Debug, PartialEq, Deserialize)] pub struct Params { - /// Account start nonce. + /// Account start nonce, defaults to 0. #[serde(rename="accountStartNonce")] - pub account_start_nonce: Uint, + pub account_start_nonce: Option, /// Maximum size of extra data. #[serde(rename="maximumExtraDataSize")] pub maximum_extra_data_size: Uint,