proper blockchain json parsing
This commit is contained in:
30
json/src/blockchain/account.rs
Normal file
30
json/src/blockchain/account.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test account deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
|
||||
/// Blockchain test account deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Account {
|
||||
balance: Uint,
|
||||
code: Bytes,
|
||||
nonce: Uint,
|
||||
storage: BTreeMap<Uint, Bytes>,
|
||||
}
|
||||
35
json/src/blockchain/block.rs
Normal file
35
json/src/blockchain/block.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test block deserializer.
|
||||
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
use blockchain::header::Header;
|
||||
use blockchain::transaction::Transaction;
|
||||
|
||||
/// Blockchain test block deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Block {
|
||||
#[serde(rename="blockHeader")]
|
||||
header: Header,
|
||||
#[serde(rename="blocknumber")]
|
||||
number: Uint,
|
||||
rlp: Bytes,
|
||||
transactions: Vec<Transaction>,
|
||||
#[serde(rename="uncleHeaders")]
|
||||
uncles: Vec<Header>,
|
||||
}
|
||||
35
json/src/blockchain/blockchain.rs
Normal file
35
json/src/blockchain/blockchain.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain deserialization.
|
||||
|
||||
use bytes::Bytes;
|
||||
use blockchain::state::State;
|
||||
use blockchain::header::Header;
|
||||
|
||||
/// Blockchain deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct BlockChain {
|
||||
#[serde(rename="genesisBlockHeader")]
|
||||
genesis_block: Header,
|
||||
#[serde(rename="genesisRLP")]
|
||||
genesis_rlp: Bytes,
|
||||
blocks: Vec<Header>,
|
||||
#[serde(rename="postState")]
|
||||
post_state: State,
|
||||
#[serde(rename="preState")]
|
||||
pre_state: State,
|
||||
}
|
||||
51
json/src/blockchain/header.rs
Normal file
51
json/src/blockchain/header.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test header deserializer.
|
||||
|
||||
use hash::Hash;
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
|
||||
/// Blockchain test header deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Header {
|
||||
bloom: Hash, // TODO Bloom
|
||||
coinbase: Hash,
|
||||
difficulty: Uint,
|
||||
#[serde(rename="extraData")]
|
||||
extra_data: Bytes,
|
||||
#[serde(rename="gasLimit")]
|
||||
gas_limit: Uint,
|
||||
#[serde(rename="gasUsed")]
|
||||
gas_used: Uint,
|
||||
hash: Hash,
|
||||
#[serde(rename="mixHash")]
|
||||
mix_hash: Hash,
|
||||
nonce: Uint, // TODO fix parsing
|
||||
number: Uint,
|
||||
#[serde(rename="parentHash")]
|
||||
parent_hash: Hash,
|
||||
#[serde(rename="receiptTrie")]
|
||||
receipt_trie: Hash,
|
||||
#[serde(rename="stateRoot")]
|
||||
state_root: Hash,
|
||||
timestamp: Uint,
|
||||
#[serde(rename="transactionsTrie")]
|
||||
transactions_trie: Hash,
|
||||
#[serde(rename="uncleHash")]
|
||||
uncle_hash: Hash,
|
||||
}
|
||||
25
json/src/blockchain/mod.rs
Normal file
25
json/src/blockchain/mod.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test deserialization.
|
||||
|
||||
pub mod account;
|
||||
pub mod block;
|
||||
pub mod blockchain;
|
||||
pub mod header;
|
||||
pub mod state;
|
||||
pub mod transaction;
|
||||
pub mod test;
|
||||
34
json/src/blockchain/state.rs
Normal file
34
json/src/blockchain/state.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test state deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use hash::Hash;
|
||||
use blockchain::account::Account;
|
||||
|
||||
/// Blockchain test state deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct State(BTreeMap<Hash, Account>);
|
||||
|
||||
impl Deref for State {
|
||||
type Target = BTreeMap<Hash, Account>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
32
json/src/blockchain/test.rs
Normal file
32
json/src/blockchain/test.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use blockchain::blockchain::BlockChain;
|
||||
|
||||
/// Blockchain test deserializer.
|
||||
pub struct Test(BTreeMap<String, BlockChain>);
|
||||
|
||||
impl Deref for Test {
|
||||
type Target = BTreeMap<String, BlockChain>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
35
json/src/blockchain/transaction.rs
Normal file
35
json/src/blockchain/transaction.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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/>.
|
||||
|
||||
//! Blockchain test transaction deserialization.
|
||||
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
|
||||
/// Blockchain test transaction deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Transaction {
|
||||
data: Bytes,
|
||||
#[serde(rename="gasLimit")]
|
||||
gas_limit: Uint,
|
||||
#[serde(rename="gasPrice")]
|
||||
gas_price: Uint,
|
||||
nonce: Uint,
|
||||
r: Uint,
|
||||
s: Uint,
|
||||
v: Uint,
|
||||
value: Uint
|
||||
}
|
||||
Reference in New Issue
Block a user