diff --git a/.gitignore b/.gitignore index f56ad1659..46f403421 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ Cargo.lock # Generated by Cargo /target/ + +*.swp diff --git a/src/blockheader.rs b/src/blockheader.rs new file mode 100644 index 000000000..920688d24 --- /dev/null +++ b/src/blockheader.rs @@ -0,0 +1,66 @@ +use util::hash::*; +use util::uint::*; +use util::rlp::*; + +pub struct BlockHeader { + parent_hash: H256, + ommers_hash: H256, + beneficiary: 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, + mix_hash: H256, + nonce: H64 +} + +impl Decodable for BlockHeader { + fn decode(decoder: &D) -> Result where D: Decoder { + decoder.read_list(| d | { + let blockheader = BlockHeader { + parent_hash: try!(H256::decode(&d[0])), + ommers_hash: try!(H256::decode(&d[1])), + beneficiary: try!(Address::decode(&d[2])), + state_root: try!(H256::decode(&d[3])), + transactions_root: try!(H256::decode(&d[4])), + receipts_root: try!(H256::decode(&d[5])), + log_bloom: try!(H2048::decode(&d[6])), + difficulty: try!(U256::decode(&d[7])), + number: try!(U256::decode(&d[8])), + gas_limit: try!(U256::decode(&d[9])), + gas_used: try!(U256::decode(&d[10])), + timestamp: try!(U256::decode(&d[11])), + mix_hash: try!(H256::decode(&d[12])), + nonce: try!(H64::decode(&d[13])) + }; + Ok(blockheader) + }) + } +} + +impl Encodable for BlockHeader { + fn encode(&self, encoder: &mut E) where E: Encoder { + encoder.emit_list(| e | { + self.parent_hash.encode(e); + self.ommers_hash.encode(e); + self.beneficiary.encode(e); + self.state_root.encode(e); + self.transactions_root.encode(e); + self.receipts_root.encode(e); + self.log_bloom.encode(e); + self.difficulty.encode(e); + self.number.encode(e); + self.gas_limit.encode(e); + self.gas_used.encode(e); + self.timestamp.encode(e); + self.mix_hash.encode(e); + self.nonce.encode(e); + }) + } +} + diff --git a/src/lib.rs b/src/lib.rs index d51f17bef..b55c90299 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ //! - OSX //! //! - rocksdb -//! ``` +//! ```bash //! brew install rocksdb //! ``` //! @@ -26,7 +26,7 @@ //! //! - download llvm 3.7 from http://llvm.org/apt/ //! -//! ``` +//! ```bash //! cd llvm-3.7.0.src //! mkdir build && cd $_ //! cmake -G "Unix Makefiles" .. -DCMAKE_C_FLAGS_RELEASE= -DCMAKE_CXX_FLAGS_RELEASE= -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/llvm/3.7 -DCMAKE_BUILD_TYPE=Release @@ -36,7 +36,7 @@ //! //! - download from https://github.com/debris/evmjit //! -//! ``` +//! ```bash //! cd evmjit //! mkdir build && cd $_ //! cmake -DLLVM_DIR=/usr/local/lib/llvm-3.7/share/llvm/cmake .. @@ -47,7 +47,7 @@ //! //! - rocksdb //! -//! ``` +//! ```bash //! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz //! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib //! sudo make install @@ -61,7 +61,7 @@ //! //! - download from https://github.com/debris/evmjit //! -//! ``` +//! ```bash //! cd evmjit //! mkdir build && cd $_ //! cmake .. && make @@ -71,87 +71,13 @@ #[macro_use] extern crate log; -extern crate ethcore_util; +extern crate ethcore_util as util; #[cfg(feature = "jit" )] extern crate evmjit; -use ethcore_util::hash::*; -use ethcore_util::uint::*; - -pub type Bytes = Vec; -pub type LogBloom = H2048; - -pub static ZERO_ADDRESS: Address = Address([0x00; 20]); -pub static ZERO_H256: H256 = H256([0x00; 32]); -pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]); - -#[derive(Debug)] -pub struct Header { - parent_hash: H256, - timestamp: U256, - number: U256, - author: Address, - - transactions_root: H256, - uncles_hash: H256, - extra_data_hash: H256, - - state_root: H256, - receipts_root: H256, - log_bloom: LogBloom, - gas_used: U256, - gas_limit: U256, - - difficulty: U256, - seal: Vec, -} - -impl Header { - 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_hash: ZERO_H256.clone(), - - 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![], - } - } -} - -pub struct Transaction { - pub to: Address, - pub gas: U256, - pub data: Bytes, - pub code: Bytes, -} +pub mod blockheader; #[test] -fn memorydb() { - -} - - -/// Silly function to return 69. -/// -/// # Example -/// -/// ``` -/// assert_eq!(ethcore::sixtynine(), 69); -/// ``` -pub fn sixtynine() -> i32 { - debug!("Hello world!"); - 69 +fn it_works() { }