// Copyright 2015, 2016 Ethcore (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 .
//! Parameters for a block chain.
use common::*;
use engine::*;
use pod_state::*;
use null_engine::*;
use account_db::*;
/// Convert JSON value to equivalent RLP representation.
// TODO: handle container types.
fn json_to_rlp(json: &Json) -> Bytes {
match *json {
Json::Boolean(o) => encode(&(if o {1u64} else {0})).to_vec(),
Json::I64(o) => encode(&(o as u64)).to_vec(),
Json::U64(o) => encode(&o).to_vec(),
Json::String(ref s) if s.len() >= 2 && &s[0..2] == "0x" && U256::from_str(&s[2..]).is_ok() => {
encode(&U256::from_str(&s[2..]).unwrap()).to_vec()
},
Json::String(ref s) => {
encode(s).to_vec()
},
_ => panic!()
}
}
/// Convert JSON to a string->RLP map.
fn json_to_rlp_map(json: &Json) -> HashMap {
json.as_object().unwrap().iter().map(|(k, v)| (k, json_to_rlp(v))).fold(HashMap::new(), |mut acc, kv| {
acc.insert(kv.0.clone(), kv.1);
acc
})
}
/// Parameters for a block chain; includes both those intrinsic to the design of the
/// chain and those to be interpreted by the active chain engine.
#[derive(Debug)]
pub struct Spec {
/// User friendly spec name
pub name: String,
/// What engine are we using for this?
pub engine_name: String,
/// Known nodes on the network in enode format.
pub nodes: Vec,
/// Network ID
pub network_id: U256,
/// Parameters concerning operation of the specific engine we're using.
/// Maps the parameter name to an RLP-encoded value.
pub engine_params: HashMap,
/// Builtin-contracts we would like to see in the chain.
/// (In principle these are just hints for the engine since that has the last word on them.)
pub builtins: BTreeMap,
/// The genesis block's parent hash field.
pub parent_hash: H256,
/// The genesis block's author field.
pub author: Address,
/// The genesis block's difficulty field.
pub difficulty: U256,
/// The genesis block's gas limit field.
pub gas_limit: U256,
/// The genesis block's gas used field.
pub gas_used: U256,
/// The genesis block's timestamp field.
pub timestamp: u64,
/// Transactions root of the genesis block. Should be SHA3_NULL_RLP.
pub transactions_root: H256,
/// Receipts root of the genesis block. Should be SHA3_NULL_RLP.
pub receipts_root: H256,
/// The genesis block's extra data field.
pub extra_data: Bytes,
/// The number of seal fields in the genesis block.
pub seal_fields: usize,
/// Each seal field, expressed as RLP, concatenated.
pub seal_rlp: Bytes,
// May be prepopulated if we know this in advance.
state_root_memo: RwLock