Merge branch 'master' of https://github.com/gavofyork/ethcore into blockchain
This commit is contained in:
commit
a63603046c
@ -1,4 +1,5 @@
|
|||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
|
use util::bytes::*;
|
||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
use util::rlp::*;
|
use util::rlp::*;
|
||||||
use util::sha3;
|
use util::sha3;
|
||||||
@ -43,33 +44,64 @@ impl<'a> sha3::Hashable for BlockView<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data structure represening block header
|
pub static ZERO_ADDRESS: Address = Address([0x00; 20]);
|
||||||
/// similar to cpp-ethereum's BlockInfo
|
pub static ZERO_H256: H256 = H256([0x00; 32]);
|
||||||
pub struct BlockHeader {
|
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
|
||||||
|
|
||||||
|
pub type LogBloom = H2048;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Header {
|
||||||
parent_hash: H256,
|
parent_hash: H256,
|
||||||
uncles_hash: H256,
|
|
||||||
coinbase: Address,
|
|
||||||
state_root: H256,
|
|
||||||
transactions_root: H256,
|
|
||||||
receipts_root: H256,
|
|
||||||
log_bloom: H2048,
|
|
||||||
difficulty: U256,
|
|
||||||
number: U256,
|
|
||||||
gas_limit: U256,
|
|
||||||
gas_used: U256,
|
|
||||||
timestamp: U256,
|
timestamp: U256,
|
||||||
mix_hash: H256,
|
number: U256,
|
||||||
nonce: H64
|
author: Address,
|
||||||
|
|
||||||
|
transactions_root: H256,
|
||||||
|
uncles_hash: H256,
|
||||||
|
extra_data: Bytes,
|
||||||
|
|
||||||
|
state_root: H256,
|
||||||
|
receipts_root: H256,
|
||||||
|
log_bloom: LogBloom,
|
||||||
|
gas_used: U256,
|
||||||
|
gas_limit: U256,
|
||||||
|
|
||||||
|
difficulty: U256,
|
||||||
|
seal: Vec<Bytes>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Decodable for BlockHeader {
|
impl Header {
|
||||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
pub fn new() -> Header {
|
||||||
|
Header {
|
||||||
|
parent_hash: ZERO_H256.clone(),
|
||||||
|
timestamp: BAD_U256.clone(),
|
||||||
|
number: ZERO_U256.clone(),
|
||||||
|
author: ZERO_ADDRESS.clone(),
|
||||||
|
|
||||||
|
transactions_root: ZERO_H256.clone(),
|
||||||
|
uncles_hash: ZERO_H256.clone(),
|
||||||
|
extra_data: vec![],
|
||||||
|
|
||||||
|
state_root: ZERO_H256.clone(),
|
||||||
|
receipts_root: ZERO_H256.clone(),
|
||||||
|
log_bloom: ZERO_LOGBLOOM.clone(),
|
||||||
|
gas_used: ZERO_U256.clone(),
|
||||||
|
gas_limit: ZERO_U256.clone(),
|
||||||
|
|
||||||
|
difficulty: ZERO_U256.clone(),
|
||||||
|
seal: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for Header {
|
||||||
|
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||||
decoder.read_list(| d | {
|
decoder.read_list(| d | {
|
||||||
// return an error if d != 14
|
let blockheader = Header {
|
||||||
let blockheader = BlockHeader {
|
|
||||||
parent_hash: try!(Decodable::decode(&d[0])),
|
parent_hash: try!(Decodable::decode(&d[0])),
|
||||||
uncles_hash: try!(Decodable::decode(&d[1])),
|
uncles_hash: try!(Decodable::decode(&d[1])),
|
||||||
coinbase: try!(Decodable::decode(&d[2])),
|
author: try!(Decodable::decode(&d[2])),
|
||||||
state_root: try!(Decodable::decode(&d[3])),
|
state_root: try!(Decodable::decode(&d[3])),
|
||||||
transactions_root: try!(Decodable::decode(&d[4])),
|
transactions_root: try!(Decodable::decode(&d[4])),
|
||||||
receipts_root: try!(Decodable::decode(&d[5])),
|
receipts_root: try!(Decodable::decode(&d[5])),
|
||||||
@ -79,20 +111,21 @@ impl Decodable for BlockHeader {
|
|||||||
gas_limit: try!(Decodable::decode(&d[9])),
|
gas_limit: try!(Decodable::decode(&d[9])),
|
||||||
gas_used: try!(Decodable::decode(&d[10])),
|
gas_used: try!(Decodable::decode(&d[10])),
|
||||||
timestamp: try!(Decodable::decode(&d[11])),
|
timestamp: try!(Decodable::decode(&d[11])),
|
||||||
mix_hash: try!(Decodable::decode(&d[12])),
|
extra_data: try!(Decodable::decode(&d[12])),
|
||||||
nonce: try!(Decodable::decode(&d[13]))
|
seal: vec![],
|
||||||
};
|
};
|
||||||
|
// TODO: fill blockheader.seal with (raw) list items index 12..)
|
||||||
Ok(blockheader)
|
Ok(blockheader)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encodable for BlockHeader {
|
impl Encodable for Header {
|
||||||
fn encode<E>(&self, encoder: &mut E) where E: Encoder {
|
fn encode<E>(&self, encoder: &mut E) where E: Encoder {
|
||||||
encoder.emit_list(| e | {
|
encoder.emit_list(| e | {
|
||||||
self.parent_hash.encode(e);
|
self.parent_hash.encode(e);
|
||||||
self.uncles_hash.encode(e);
|
self.uncles_hash.encode(e);
|
||||||
self.coinbase.encode(e);
|
self.author.encode(e);
|
||||||
self.state_root.encode(e);
|
self.state_root.encode(e);
|
||||||
self.transactions_root.encode(e);
|
self.transactions_root.encode(e);
|
||||||
self.receipts_root.encode(e);
|
self.receipts_root.encode(e);
|
||||||
@ -102,8 +135,8 @@ impl Encodable for BlockHeader {
|
|||||||
self.gas_limit.encode(e);
|
self.gas_limit.encode(e);
|
||||||
self.gas_used.encode(e);
|
self.gas_used.encode(e);
|
||||||
self.timestamp.encode(e);
|
self.timestamp.encode(e);
|
||||||
self.mix_hash.encode(e);
|
self.extra_data.encode(e);
|
||||||
self.nonce.encode(e);
|
// TODO: emit raw seal items.
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@ -73,14 +73,21 @@
|
|||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate flate2;
|
extern crate flate2;
|
||||||
extern crate ethcore_util as util;
|
|
||||||
|
|
||||||
|
extern crate env_logger;
|
||||||
#[cfg(feature = "jit" )]
|
#[cfg(feature = "jit" )]
|
||||||
extern crate evmjit;
|
extern crate evmjit;
|
||||||
|
extern crate ethcore_util as util;
|
||||||
|
|
||||||
|
//use util::error::*;
|
||||||
|
pub use util::hash::*;
|
||||||
|
pub use util::uint::*;
|
||||||
|
pub use util::bytes::*;
|
||||||
|
|
||||||
pub mod account;
|
pub mod account;
|
||||||
pub mod block;
|
pub mod block;
|
||||||
pub mod blockchain;
|
pub mod blockchain;
|
||||||
|
pub mod state;
|
||||||
pub mod blockheader;
|
pub mod blockheader;
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
pub mod genesis;
|
pub mod genesis;
|
||||||
@ -91,7 +98,6 @@ pub mod importroute;
|
|||||||
pub mod networkparams;
|
pub mod networkparams;
|
||||||
pub mod denominations;
|
pub mod denominations;
|
||||||
|
|
||||||
pub mod state;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
|
use util::bytes::*;
|
||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
use util::rlp::*;
|
use util::rlp::*;
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ pub struct Transaction {
|
|||||||
gas: U256,
|
gas: U256,
|
||||||
receive_address: Option<Address>,
|
receive_address: Option<Address>,
|
||||||
value: U256,
|
value: U256,
|
||||||
data: Vec<u8>,
|
data: Bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
|
Loading…
Reference in New Issue
Block a user