added genesis method to ethjson blockchain
This commit is contained in:
@@ -20,6 +20,7 @@ use bytes::Bytes;
|
||||
use blockchain::state::State;
|
||||
use blockchain::header::Header;
|
||||
use blockchain::block::Block;
|
||||
use spec::Genesis;
|
||||
|
||||
/// Blockchain deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
@@ -45,6 +46,21 @@ impl BlockChain {
|
||||
pub fn blocks_rlp(&self) -> Vec<Vec<u8>> {
|
||||
self.blocks.iter().map(|block| block.rlp()).collect()
|
||||
}
|
||||
|
||||
/// Returns spec compatible genesis struct.
|
||||
pub fn genesis(&self) -> Genesis {
|
||||
Genesis {
|
||||
nonce: Some(self.genesis_block.nonce.clone()),
|
||||
mix_hash: Some(self.genesis_block.mix_hash.clone()),
|
||||
seal_fields: None,
|
||||
seal_rlp: None,
|
||||
difficulty: self.genesis_block.difficulty,
|
||||
author: self.genesis_block.author.clone(),
|
||||
timestamp: self.genesis_block.timestamp,
|
||||
parent_hash: self.genesis_block.parent_hash.clone(),
|
||||
gas_limit: self.genesis_block.gas_limit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -23,31 +23,48 @@ use bytes::Bytes;
|
||||
/// Blockchain test header deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Header {
|
||||
bloom: Bloom,
|
||||
coinbase: Address,
|
||||
difficulty: Uint,
|
||||
/// Blocks bloom.
|
||||
pub bloom: Bloom,
|
||||
/// Blocks author.
|
||||
#[serde(rename="coinbase")]
|
||||
pub author: Address,
|
||||
/// Difficulty.
|
||||
pub difficulty: Uint,
|
||||
#[serde(rename="extraData")]
|
||||
extra_data: Bytes,
|
||||
/// Extra data.
|
||||
pub extra_data: Bytes,
|
||||
/// Gas limit.
|
||||
#[serde(rename="gasLimit")]
|
||||
gas_limit: Uint,
|
||||
pub gas_limit: Uint,
|
||||
/// Gas used.
|
||||
#[serde(rename="gasUsed")]
|
||||
gas_used: Uint,
|
||||
hash: H256,
|
||||
pub gas_used: Uint,
|
||||
/// Hash.
|
||||
pub hash: H256,
|
||||
#[serde(rename="mixHash")]
|
||||
mix_hash: H256,
|
||||
nonce: H64,
|
||||
number: Uint,
|
||||
/// Mix hash.
|
||||
pub mix_hash: H256,
|
||||
/// Seal nonce.
|
||||
pub nonce: H64,
|
||||
/// Block number.
|
||||
pub number: Uint,
|
||||
/// Parent hash.
|
||||
#[serde(rename="parentHash")]
|
||||
parent_hash: H256,
|
||||
pub parent_hash: H256,
|
||||
/// Receipt root.
|
||||
#[serde(rename="receiptTrie")]
|
||||
receipt_trie: H256,
|
||||
pub receipt_root: H256,
|
||||
/// State root.
|
||||
#[serde(rename="stateRoot")]
|
||||
state_root: H256,
|
||||
timestamp: Uint,
|
||||
pub state_root: H256,
|
||||
/// Timestamp.
|
||||
pub timestamp: Uint,
|
||||
/// Transactions root.
|
||||
#[serde(rename="transactionsTrie")]
|
||||
transactions_trie: H256,
|
||||
pub transactions_root: H256,
|
||||
/// Uncles hash.
|
||||
#[serde(rename="uncleHash")]
|
||||
uncle_hash: H256,
|
||||
pub uncles_hash: H256,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user