ethjson spec submodule
This commit is contained in:
parent
7105ed3f61
commit
1fa019d92a
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"engineName": "Frontier (Test)",
|
"name": "Frontier (Test)",
|
||||||
"engineName": "Ethash",
|
"engineName": "Ethash",
|
||||||
"params": {
|
"params": {
|
||||||
"accountStartNonce": "0x00",
|
"accountStartNonce": "0x00",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"engineName": "Frontier (Test)",
|
"name": "Frontier (Test)",
|
||||||
"engineName": "Ethash",
|
"engineName": "Ethash",
|
||||||
"params": {
|
"params": {
|
||||||
"accountStartNonce": "0x00",
|
"accountStartNonce": "0x00",
|
||||||
|
@ -46,6 +46,10 @@ macro_rules! impl_hash {
|
|||||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: Error {
|
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||||
let value = match value.len() {
|
let value = match value.len() {
|
||||||
0 => $inner::from(0),
|
0 => $inner::from(0),
|
||||||
|
2 if value == "0x" => $inner::from(0),
|
||||||
|
_ if value.starts_with("0x") => try!($inner::from_str(&value[2..]).map_err(|_| {
|
||||||
|
Error::custom(format!("Invalid hex value {}.", value).as_ref())
|
||||||
|
})),
|
||||||
_ => try!($inner::from_str(value).map_err(|_| {
|
_ => try!($inner::from_str(value).map_err(|_| {
|
||||||
Error::custom(format!("Invalid hex value {}.", value).as_ref())
|
Error::custom(format!("Invalid hex value {}.", value).as_ref())
|
||||||
}))
|
}))
|
||||||
|
@ -23,3 +23,4 @@ pub mod hash;
|
|||||||
pub mod uint;
|
pub mod uint;
|
||||||
pub mod bytes;
|
pub mod bytes;
|
||||||
pub mod blockchain;
|
pub mod blockchain;
|
||||||
|
pub mod spec;
|
||||||
|
44
json/src/spec/account.rs
Normal file
44
json/src/spec/account.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Spec account deserialization.
|
||||||
|
|
||||||
|
use uint::Uint;
|
||||||
|
use spec::builtin::Builtin;
|
||||||
|
|
||||||
|
/// Spec account.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
pub struct Account {
|
||||||
|
builtin: Option<Builtin>,
|
||||||
|
balance: Option<Uint>,
|
||||||
|
nonce: Option<Uint>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use spec::account::Account;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn account_deserialization() {
|
||||||
|
let s = r#"{
|
||||||
|
"balance": "1",
|
||||||
|
"builtin": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } }
|
||||||
|
}"#;
|
||||||
|
let _deserialized: Account = serde_json::from_str(s).unwrap();
|
||||||
|
// TODO: validate all fields
|
||||||
|
}
|
||||||
|
}
|
47
json/src/spec/builtin.rs
Normal file
47
json/src/spec/builtin.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Spec builtin deserialization.
|
||||||
|
|
||||||
|
/// Linear builin options.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
pub struct Linear {
|
||||||
|
base: u64,
|
||||||
|
word: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Spec builtin.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
pub struct Builtin {
|
||||||
|
name: String,
|
||||||
|
linear: Linear,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use spec::builtin::Builtin;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn builtin_deserialization() {
|
||||||
|
let s = r#"{
|
||||||
|
"name": "ecrecover",
|
||||||
|
"linear": { "base": 3000, "word": 0 }
|
||||||
|
}"#;
|
||||||
|
let _deserialized: Builtin = serde_json::from_str(s).unwrap();
|
||||||
|
// TODO: validate all fields
|
||||||
|
}
|
||||||
|
}
|
67
json/src/spec/genesis.rs
Normal file
67
json/src/spec/genesis.rs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Spec genesis deserialization.
|
||||||
|
|
||||||
|
use uint::Uint;
|
||||||
|
use hash::{Address, H256};
|
||||||
|
use bytes::Bytes;
|
||||||
|
|
||||||
|
/// Spec genesis.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
pub struct Genesis {
|
||||||
|
// old seal
|
||||||
|
nonce: Option<Uint>,
|
||||||
|
#[serde(rename="mixHash")]
|
||||||
|
mix_hash: Option<H256>,
|
||||||
|
|
||||||
|
// new seal // TODO: consider moving it to a separate seal structure
|
||||||
|
#[serde(rename="sealFields")]
|
||||||
|
seal_fields: Option<Uint>,
|
||||||
|
#[serde(rename="sealRlp")]
|
||||||
|
seal_rlp: Option<Bytes>,
|
||||||
|
|
||||||
|
difficulty: Uint,
|
||||||
|
author: Address,
|
||||||
|
timestamp: Uint,
|
||||||
|
#[serde(rename="parentHash")]
|
||||||
|
parent_hash: H256,
|
||||||
|
#[serde(rename="gasLimit")]
|
||||||
|
gas_limit: Uint,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use spec::genesis::Genesis;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn genesis_deserialization() {
|
||||||
|
let s = r#"{
|
||||||
|
"nonce": "0x0000000000000042",
|
||||||
|
"difficulty": "0x400000000",
|
||||||
|
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"author": "0x0000000000000000000000000000000000000000",
|
||||||
|
"timestamp": "0x00",
|
||||||
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
|
||||||
|
"gasLimit": "0x1388",
|
||||||
|
"stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"
|
||||||
|
}"#;
|
||||||
|
let _deserialized: Genesis = serde_json::from_str(s).unwrap();
|
||||||
|
// TODO: validate all fields
|
||||||
|
}
|
||||||
|
}
|
29
json/src/spec/mod.rs
Normal file
29
json/src/spec/mod.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Spec deserialization.
|
||||||
|
|
||||||
|
pub mod account;
|
||||||
|
pub mod builtin;
|
||||||
|
pub mod genesis;
|
||||||
|
pub mod params;
|
||||||
|
pub mod spec;
|
||||||
|
|
||||||
|
pub use self::account::Account;
|
||||||
|
pub use self::builtin::Builtin;
|
||||||
|
pub use self::genesis::Genesis;
|
||||||
|
pub use self::params::Params;
|
||||||
|
pub use self::spec::Spec;
|
74
json/src/spec/params.rs
Normal file
74
json/src/spec/params.rs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Spec params deserialization.
|
||||||
|
|
||||||
|
use uint::Uint;
|
||||||
|
use hash::Address;
|
||||||
|
|
||||||
|
/// Spec params.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
pub struct Params {
|
||||||
|
#[serde(rename="accountStartNonce")]
|
||||||
|
account_start_nonce: Uint,
|
||||||
|
#[serde(rename="frontierCompatibilityModeLimit")]
|
||||||
|
frontier_compatibility_mode_limit: Uint,
|
||||||
|
#[serde(rename="maximumExtraDataSize")]
|
||||||
|
maximum_extra_data_size: Uint,
|
||||||
|
#[serde(rename="tieBreakingGas")]
|
||||||
|
tie_breaking_gas: bool,
|
||||||
|
#[serde(rename="minGasLimit")]
|
||||||
|
min_gas_limit: Uint,
|
||||||
|
#[serde(rename="gasLimitBoundDivisor")]
|
||||||
|
gas_limit_bound_divisor: Uint,
|
||||||
|
#[serde(rename="minimumDifficulty")]
|
||||||
|
minimum_difficulty: Uint,
|
||||||
|
#[serde(rename="difficultyBoundDivisor")]
|
||||||
|
difficulty_bound_divisor: Uint,
|
||||||
|
#[serde(rename="durationLimit")]
|
||||||
|
duration_limit: Uint,
|
||||||
|
#[serde(rename="blockReward")]
|
||||||
|
block_reward: Uint,
|
||||||
|
registrar: Address,
|
||||||
|
#[serde(rename="networkID")]
|
||||||
|
network_id: Uint,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use spec::params::Params;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn params_deserialization() {
|
||||||
|
let s = r#"{
|
||||||
|
"accountStartNonce": "0x00",
|
||||||
|
"frontierCompatibilityModeLimit": "0x118c30",
|
||||||
|
"maximumExtraDataSize": "0x20",
|
||||||
|
"tieBreakingGas": false,
|
||||||
|
"minGasLimit": "0x1388",
|
||||||
|
"gasLimitBoundDivisor": "0x0400",
|
||||||
|
"minimumDifficulty": "0x020000",
|
||||||
|
"difficultyBoundDivisor": "0x0800",
|
||||||
|
"durationLimit": "0x0d",
|
||||||
|
"blockReward": "0x4563918244F40000",
|
||||||
|
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||||
|
"networkID" : "0x1"
|
||||||
|
}"#;
|
||||||
|
let _deserialized: Params = serde_json::from_str(s).unwrap();
|
||||||
|
// TODO: validate all fields
|
||||||
|
}
|
||||||
|
}
|
84
json/src/spec/spec.rs
Normal file
84
json/src/spec/spec.rs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Spec deserialization.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use hash::Address;
|
||||||
|
use spec::account::Account;
|
||||||
|
use spec::params::Params;
|
||||||
|
use spec::genesis::Genesis;
|
||||||
|
|
||||||
|
/// Spec deserialization.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
pub struct Spec {
|
||||||
|
name: String,
|
||||||
|
#[serde(rename="engineName")]
|
||||||
|
engine_name: String, // TODO: consider making it an enum
|
||||||
|
params: Params,
|
||||||
|
genesis: Genesis,
|
||||||
|
accounts: BTreeMap<Address, Account>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use spec::spec::Spec;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn spec_deserialization() {
|
||||||
|
let s = r#"{
|
||||||
|
"name": "Morden",
|
||||||
|
"engineName": "Ethash",
|
||||||
|
"params": {
|
||||||
|
"accountStartNonce": "0x0100000",
|
||||||
|
"frontierCompatibilityModeLimit": "0x789b0",
|
||||||
|
"maximumExtraDataSize": "0x20",
|
||||||
|
"tieBreakingGas": false,
|
||||||
|
"minGasLimit": "0x1388",
|
||||||
|
"gasLimitBoundDivisor": "0x0400",
|
||||||
|
"minimumDifficulty": "0x020000",
|
||||||
|
"difficultyBoundDivisor": "0x0800",
|
||||||
|
"durationLimit": "0x0d",
|
||||||
|
"blockReward": "0x4563918244F40000",
|
||||||
|
"registrar": "",
|
||||||
|
"networkID" : "0x2"
|
||||||
|
},
|
||||||
|
"genesis": {
|
||||||
|
"nonce": "0x00006d6f7264656e",
|
||||||
|
"difficulty": "0x20000",
|
||||||
|
"mixHash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
|
||||||
|
"author": "0x0000000000000000000000000000000000000000",
|
||||||
|
"timestamp": "0x00",
|
||||||
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"extraData": "0x",
|
||||||
|
"gasLimit": "0x2fefd8"
|
||||||
|
},
|
||||||
|
"nodes": [
|
||||||
|
"enode://b1217cbaa440e35ed471157123fe468e19e8b5ad5bedb4b1fdbcbdab6fb2f5ed3e95dd9c24a22a79fdb2352204cea207df27d92bfd21bfd41545e8b16f637499@104.44.138.37:30303"
|
||||||
|
],
|
||||||
|
"accounts": {
|
||||||
|
"0000000000000000000000000000000000000001": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
|
||||||
|
"0000000000000000000000000000000000000002": { "balance": "1", "nonce": "1048576", "builtin": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
|
||||||
|
"0000000000000000000000000000000000000003": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
|
||||||
|
"0000000000000000000000000000000000000004": { "balance": "1", "nonce": "1048576", "builtin": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
|
||||||
|
"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "1048576" }
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
let _deserialized: Spec = serde_json::from_str(s).unwrap();
|
||||||
|
// TODO: validate all fields
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user