2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-03-17 13:41:11 +01:00
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
//! Spec deserialization.
|
|
|
|
|
2016-04-09 19:20:35 +02:00
|
|
|
use std::io::Read;
|
|
|
|
use serde_json;
|
|
|
|
use serde_json::Error;
|
|
|
|
use spec::{Params, Genesis, Engine, State};
|
2016-03-17 13:41:11 +01:00
|
|
|
|
|
|
|
/// Spec deserialization.
|
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
|
|
|
pub struct Spec {
|
2016-04-09 19:20:35 +02:00
|
|
|
/// Spec name.
|
|
|
|
pub name: String,
|
2016-07-25 10:20:22 +02:00
|
|
|
/// Special fork name.
|
2016-12-12 16:51:07 +01:00
|
|
|
#[serde(rename="dataDir")]
|
|
|
|
pub data_dir: Option<String>,
|
2016-04-09 19:20:35 +02:00
|
|
|
/// Engine.
|
|
|
|
pub engine: Engine,
|
|
|
|
/// Spec params.
|
|
|
|
pub params: Params,
|
|
|
|
/// Genesis header.
|
|
|
|
pub genesis: Genesis,
|
|
|
|
/// Genesis state.
|
|
|
|
pub accounts: State,
|
|
|
|
/// Boot nodes.
|
|
|
|
pub nodes: Option<Vec<String>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Spec {
|
|
|
|
/// Loads test from json.
|
|
|
|
pub fn load<R>(reader: R) -> Result<Self, Error> where R: Read {
|
|
|
|
serde_json::from_reader(reader)
|
|
|
|
}
|
2016-03-17 13:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use serde_json;
|
|
|
|
use spec::spec::Spec;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn spec_deserialization() {
|
|
|
|
let s = r#"{
|
|
|
|
"name": "Morden",
|
2016-12-12 16:51:07 +01:00
|
|
|
"dataDir": "morden",
|
2016-04-09 19:20:35 +02:00
|
|
|
"engine": {
|
|
|
|
"Ethash": {
|
|
|
|
"params": {
|
|
|
|
"gasLimitBoundDivisor": "0x0400",
|
|
|
|
"minimumDifficulty": "0x020000",
|
|
|
|
"difficultyBoundDivisor": "0x0800",
|
|
|
|
"durationLimit": "0x0d",
|
|
|
|
"blockReward": "0x4563918244F40000",
|
2016-05-03 17:23:53 +02:00
|
|
|
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
2016-10-15 14:39:15 +02:00
|
|
|
"homesteadTransition" : "0x",
|
2016-07-16 13:02:56 +02:00
|
|
|
"daoHardforkTransition": "0xffffffffffffffff",
|
|
|
|
"daoHardforkBeneficiary": "0x0000000000000000000000000000000000000000",
|
|
|
|
"daoHardforkAccounts": []
|
2016-04-09 19:20:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-03-17 13:41:11 +01:00
|
|
|
"params": {
|
|
|
|
"accountStartNonce": "0x0100000",
|
2016-10-15 14:39:15 +02:00
|
|
|
"homesteadTransition": "0x789b0",
|
2016-03-17 13:41:11 +01:00
|
|
|
"maximumExtraDataSize": "0x20",
|
|
|
|
"minGasLimit": "0x1388",
|
2016-07-28 20:31:56 +02:00
|
|
|
"networkID" : "0x2",
|
2016-07-27 21:38:22 +02:00
|
|
|
"forkBlock": "0xffffffffffffffff",
|
2016-07-28 20:31:56 +02:00
|
|
|
"forkCanonHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
2016-03-17 13:41:11 +01:00
|
|
|
},
|
|
|
|
"genesis": {
|
2016-04-09 19:20:35 +02:00
|
|
|
"seal": {
|
|
|
|
"ethereum": {
|
|
|
|
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
|
|
"nonce": "0x00006d6f7264656e"
|
|
|
|
}
|
|
|
|
},
|
2016-03-17 13:41:11 +01:00
|
|
|
"difficulty": "0x20000",
|
|
|
|
"author": "0x0000000000000000000000000000000000000000",
|
|
|
|
"timestamp": "0x00",
|
|
|
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
|
|
"extraData": "0x",
|
|
|
|
"gasLimit": "0x2fefd8"
|
|
|
|
},
|
|
|
|
"nodes": [
|
|
|
|
"enode://b1217cbaa440e35ed471157123fe468e19e8b5ad5bedb4b1fdbcbdab6fb2f5ed3e95dd9c24a22a79fdb2352204cea207df27d92bfd21bfd41545e8b16f637499@104.44.138.37:30303"
|
|
|
|
],
|
|
|
|
"accounts": {
|
2016-03-18 22:54:36 +01:00
|
|
|
"0000000000000000000000000000000000000001": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
|
|
|
|
"0000000000000000000000000000000000000002": { "balance": "1", "nonce": "1048576", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
|
|
|
"0000000000000000000000000000000000000003": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
|
|
|
"0000000000000000000000000000000000000004": { "balance": "1", "nonce": "1048576", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
2016-03-17 13:41:11 +01:00
|
|
|
"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "1048576" }
|
|
|
|
}
|
|
|
|
}"#;
|
|
|
|
let _deserialized: Spec = serde_json::from_str(s).unwrap();
|
|
|
|
// TODO: validate all fields
|
|
|
|
}
|
|
|
|
}
|