make fields defaulting to 0 optional

This commit is contained in:
keorn 2016-12-22 07:06:40 +01:00
parent b369939f20
commit 552a772cc1
5 changed files with 16 additions and 16 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::{Address, H256, Uint, U256}; use util::{Address, H256, Uint, U256, FixedHash};
use util::sha3::SHA3_NULL_RLP; use util::sha3::SHA3_NULL_RLP;
use ethjson; use ethjson;
use super::seal::Seal; use super::seal::Seal;
@ -50,9 +50,9 @@ impl From<ethjson::spec::Genesis> for Genesis {
Genesis { Genesis {
seal: From::from(g.seal), seal: From::from(g.seal),
difficulty: g.difficulty.into(), difficulty: g.difficulty.into(),
author: g.author.into(), author: g.author.map_or_else(Address::zero, Into::into),
timestamp: g.timestamp.into(), timestamp: g.timestamp.map_or(0, Into::into),
parent_hash: g.parent_hash.into(), parent_hash: g.parent_hash.map_or_else(H256::zero, Into::into),
gas_limit: g.gas_limit.into(), gas_limit: g.gas_limit.into(),
transactions_root: g.transactions_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::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), receipts_root: g.receipts_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),

View File

@ -49,7 +49,7 @@ pub struct CommonParams {
impl From<ethjson::spec::Params> for CommonParams { impl From<ethjson::spec::Params> for CommonParams {
fn from(p: ethjson::spec::Params) -> Self { fn from(p: ethjson::spec::Params) -> Self {
CommonParams { 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(), maximum_extra_data_size: p.maximum_extra_data_size.into(),
network_id: p.network_id.into(), network_id: p.network_id.into(),
subprotocol_name: p.subprotocol_name.unwrap_or_else(|| "eth".to_owned()), subprotocol_name: p.subprotocol_name.unwrap_or_else(|| "eth".to_owned()),

View File

@ -59,9 +59,9 @@ impl BlockChain {
mix_hash: self.genesis_block.mix_hash.clone(), mix_hash: self.genesis_block.mix_hash.clone(),
}), }),
difficulty: self.genesis_block.difficulty, difficulty: self.genesis_block.difficulty,
author: self.genesis_block.author.clone(), author: Some(self.genesis_block.author.clone()),
timestamp: self.genesis_block.timestamp, timestamp: Some(self.genesis_block.timestamp),
parent_hash: self.genesis_block.parent_hash.clone(), parent_hash: Some(self.genesis_block.parent_hash.clone()),
gas_limit: self.genesis_block.gas_limit, gas_limit: self.genesis_block.gas_limit,
transactions_root: Some(self.genesis_block.transactions_root.clone()), transactions_root: Some(self.genesis_block.transactions_root.clone()),
receipts_root: Some(self.genesis_block.receipts_root.clone()), receipts_root: Some(self.genesis_block.receipts_root.clone()),

View File

@ -28,13 +28,13 @@ pub struct Genesis {
pub seal: Seal, pub seal: Seal,
/// Difficulty. /// Difficulty.
pub difficulty: Uint, pub difficulty: Uint,
/// Block author. /// Block author, defaults to 0.
pub author: Address, pub author: Option<Address>,
/// Block timestamp. /// Block timestamp, defaults to 0.
pub timestamp: Uint, pub timestamp: Option<Uint>,
/// Parent hash. /// Parent hash, defaults to 0.
#[serde(rename="parentHash")] #[serde(rename="parentHash")]
pub parent_hash: H256, pub parent_hash: Option<H256>,
/// Gas limit. /// Gas limit.
#[serde(rename="gasLimit")] #[serde(rename="gasLimit")]
pub gas_limit: Uint, pub gas_limit: Uint,

View File

@ -22,9 +22,9 @@ use hash::H256;
/// Spec params. /// Spec params.
#[derive(Debug, PartialEq, Deserialize)] #[derive(Debug, PartialEq, Deserialize)]
pub struct Params { pub struct Params {
/// Account start nonce. /// Account start nonce, defaults to 0.
#[serde(rename="accountStartNonce")] #[serde(rename="accountStartNonce")]
pub account_start_nonce: Uint, pub account_start_nonce: Option<Uint>,
/// Maximum size of extra data. /// Maximum size of extra data.
#[serde(rename="maximumExtraDataSize")] #[serde(rename="maximumExtraDataSize")]
pub maximum_extra_data_size: Uint, pub maximum_extra_data_size: Uint,