new way of loading PodState
This commit is contained in:
parent
1f03ae54d6
commit
c695b83e52
@ -101,13 +101,13 @@ pub mod spec;
|
|||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
pub mod views;
|
pub mod views;
|
||||||
pub mod receipt;
|
pub mod receipt;
|
||||||
|
pub mod pod_state;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
mod basic_types;
|
mod basic_types;
|
||||||
#[macro_use] mod evm;
|
#[macro_use] mod evm;
|
||||||
mod env_info;
|
mod env_info;
|
||||||
mod pod_account;
|
mod pod_account;
|
||||||
mod pod_state;
|
|
||||||
mod account_diff;
|
mod account_diff;
|
||||||
mod state_diff;
|
mod state_diff;
|
||||||
mod engine;
|
mod engine;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
use util::*;
|
use util::*;
|
||||||
use account::*;
|
use account::*;
|
||||||
use account_db::*;
|
use account_db::*;
|
||||||
|
use ethjson;
|
||||||
|
|
||||||
#[derive(Debug,Clone,PartialEq,Eq)]
|
#[derive(Debug,Clone,PartialEq,Eq)]
|
||||||
/// An account, expressed as Plain-Old-Data (hence the name).
|
/// An account, expressed as Plain-Old-Data (hence the name).
|
||||||
@ -73,6 +74,21 @@ impl PodAccount {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ethjson::blockchain::Account> for PodAccount {
|
||||||
|
fn from(a: ethjson::blockchain::Account) -> Self {
|
||||||
|
PodAccount {
|
||||||
|
balance: a.balance.into(),
|
||||||
|
nonce: a.nonce.into(),
|
||||||
|
code: a.code.into(),
|
||||||
|
storage: a.storage.into_iter().fold(BTreeMap::new(), |mut acc, (key, value)| {
|
||||||
|
let key: U256 = key.into();
|
||||||
|
acc.insert(H256::from(key), value.into());
|
||||||
|
acc
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for PodAccount {
|
impl fmt::Display for PodAccount {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "(bal={}; nonce={}; code={} bytes, #{}; storage={} items)", self.balance, self.nonce, self.code.len(), self.code.sha3(), self.storage.len())
|
write!(f, "(bal={}; nonce={}; code={} bytes, #{}; storage={} items)", self.balance, self.nonce, self.code.len(), self.code.sha3(), self.storage.len())
|
||||||
|
@ -14,11 +14,14 @@
|
|||||||
// 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/>.
|
||||||
|
|
||||||
|
//! State of all accounts in the system expressed in Plain Old Data.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use pod_account::*;
|
use pod_account::*;
|
||||||
|
use ethjson;
|
||||||
|
|
||||||
#[derive(Debug,Clone,PartialEq,Eq,Default)]
|
|
||||||
/// State of all accounts in the system expressed in Plain Old Data.
|
/// State of all accounts in the system expressed in Plain Old Data.
|
||||||
|
#[derive(Debug,Clone,PartialEq,Eq,Default)]
|
||||||
pub struct PodState (BTreeMap<Address, PodAccount>);
|
pub struct PodState (BTreeMap<Address, PodAccount>);
|
||||||
|
|
||||||
impl PodState {
|
impl PodState {
|
||||||
@ -64,6 +67,15 @@ impl FromJson for PodState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ethjson::blockchain::State> for PodState {
|
||||||
|
fn from(s: ethjson::blockchain::State) -> PodState {
|
||||||
|
PodState(s.0.into_iter().fold(BTreeMap::new(), |mut acc, (key, value)| {
|
||||||
|
acc.insert(key.into(), PodAccount::from(value));
|
||||||
|
acc
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for PodState {
|
impl fmt::Display for PodState {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for (add, acc) in &self.0 {
|
for (add, acc) in &self.0 {
|
||||||
|
@ -20,3 +20,4 @@ mod genesis;
|
|||||||
pub mod spec;
|
pub mod spec;
|
||||||
|
|
||||||
pub use self::spec::*;
|
pub use self::spec::*;
|
||||||
|
pub use self::genesis::Genesis;
|
||||||
|
@ -19,14 +19,19 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use uint::Uint;
|
use uint::Uint;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use hash::H256;
|
||||||
|
|
||||||
/// Blockchain test account deserializer.
|
/// Blockchain test account deserializer.
|
||||||
#[derive(Debug, PartialEq, Deserialize)]
|
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
balance: Uint,
|
/// Balance.
|
||||||
code: Bytes,
|
pub balance: Uint,
|
||||||
nonce: Uint,
|
/// Code.
|
||||||
storage: BTreeMap<Uint, Bytes>,
|
pub code: Bytes,
|
||||||
|
/// Nonce.
|
||||||
|
pub nonce: Uint,
|
||||||
|
/// Storage.
|
||||||
|
pub storage: BTreeMap<Uint, H256>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -35,7 +40,7 @@ mod tests {
|
|||||||
use blockchain::account::Account;
|
use blockchain::account::Account;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn header_deserialization() {
|
fn account_deserialization() {
|
||||||
let s = r#"{
|
let s = r#"{
|
||||||
"balance" : "0x09184e72a078",
|
"balance" : "0x09184e72a078",
|
||||||
"code" : "0x600140600155",
|
"code" : "0x600140600155",
|
||||||
|
@ -25,15 +25,20 @@ use spec::Genesis;
|
|||||||
/// Blockchain deserialization.
|
/// Blockchain deserialization.
|
||||||
#[derive(Debug, PartialEq, Deserialize)]
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct BlockChain {
|
pub struct BlockChain {
|
||||||
|
/// Genesis block header.
|
||||||
#[serde(rename="genesisBlockHeader")]
|
#[serde(rename="genesisBlockHeader")]
|
||||||
genesis_block: Header,
|
pub genesis_block: Header,
|
||||||
|
/// Genesis block rlp.
|
||||||
#[serde(rename="genesisRLP")]
|
#[serde(rename="genesisRLP")]
|
||||||
genesis_rlp: Bytes,
|
pub genesis_rlp: Bytes,
|
||||||
blocks: Vec<Block>,
|
/// Blocks.
|
||||||
|
pub blocks: Vec<Block>,
|
||||||
|
/// Post state.
|
||||||
#[serde(rename="postState")]
|
#[serde(rename="postState")]
|
||||||
post_state: State,
|
pub post_state: State,
|
||||||
|
/// Pre state.
|
||||||
#[serde(rename="pre")]
|
#[serde(rename="pre")]
|
||||||
pre_state: State,
|
pub pre_state: State,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockChain {
|
impl BlockChain {
|
||||||
|
@ -22,8 +22,8 @@ use hash::Address;
|
|||||||
use blockchain::account::Account;
|
use blockchain::account::Account;
|
||||||
|
|
||||||
/// Blockchain test state deserializer.
|
/// Blockchain test state deserializer.
|
||||||
#[derive(Debug, PartialEq, Deserialize)]
|
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||||
pub struct State(BTreeMap<Address, Account>);
|
pub struct State(pub BTreeMap<Address, Account>);
|
||||||
|
|
||||||
impl Deref for State {
|
impl Deref for State {
|
||||||
type Target = BTreeMap<Address, Account>;
|
type Target = BTreeMap<Address, Account>;
|
||||||
|
@ -18,11 +18,15 @@ extern crate docopt;
|
|||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate ethjson;
|
extern crate ethjson;
|
||||||
|
extern crate ethcore;
|
||||||
|
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
|
use ethcore::spec::Genesis;
|
||||||
|
use ethcore::pod_state::PodState;
|
||||||
|
use ethcore::ethereum;
|
||||||
|
|
||||||
const USAGE: &'static str = r#"
|
const USAGE: &'static str = r#"
|
||||||
Parity rpctest client.
|
Parity rpctest client.
|
||||||
@ -70,7 +74,15 @@ impl Configuration {
|
|||||||
process::exit(3);
|
process::exit(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let genesis = Genesis::from(blockchain.genesis());
|
||||||
|
let state = PodState::from(blockchain.pre_state.clone());
|
||||||
|
let mut spec = ethereum::new_frontier_test();
|
||||||
|
spec.set_genesis_state(state);
|
||||||
|
spec.overwrite_genesis_params(genesis);
|
||||||
|
assert!(spec.is_state_root_valid());
|
||||||
|
|
||||||
|
//let temp = RandomTempPath::new();
|
||||||
|
//spec.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user