blockheader

This commit is contained in:
debris 2015-12-08 16:31:36 +01:00
parent d516fca165
commit 43b88e4e76
3 changed files with 76 additions and 82 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ Cargo.lock
# Generated by Cargo # Generated by Cargo
/target/ /target/
*.swp

66
src/blockheader.rs Normal file
View File

@ -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<D>(decoder: &D) -> Result<Self, DecoderError> 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<E>(&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);
})
}
}

View File

@ -18,7 +18,7 @@
//! - OSX //! - OSX
//! //!
//! - rocksdb //! - rocksdb
//! ``` //! ```bash
//! brew install rocksdb //! brew install rocksdb
//! ``` //! ```
//! //!
@ -26,7 +26,7 @@
//! //!
//! - download llvm 3.7 from http://llvm.org/apt/ //! - download llvm 3.7 from http://llvm.org/apt/
//! //!
//! ``` //! ```bash
//! cd llvm-3.7.0.src //! cd llvm-3.7.0.src
//! mkdir build && cd $_ //! 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 //! 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 //! - download from https://github.com/debris/evmjit
//! //!
//! ``` //! ```bash
//! cd evmjit //! cd evmjit
//! mkdir build && cd $_ //! mkdir build && cd $_
//! cmake -DLLVM_DIR=/usr/local/lib/llvm-3.7/share/llvm/cmake .. //! cmake -DLLVM_DIR=/usr/local/lib/llvm-3.7/share/llvm/cmake ..
@ -47,7 +47,7 @@
//! //!
//! - rocksdb //! - rocksdb
//! //!
//! ``` //! ```bash
//! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz //! 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 //! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib
//! sudo make install //! sudo make install
@ -61,7 +61,7 @@
//! //!
//! - download from https://github.com/debris/evmjit //! - download from https://github.com/debris/evmjit
//! //!
//! ``` //! ```bash
//! cd evmjit //! cd evmjit
//! mkdir build && cd $_ //! mkdir build && cd $_
//! cmake .. && make //! cmake .. && make
@ -71,87 +71,13 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate ethcore_util; extern crate ethcore_util as util;
#[cfg(feature = "jit" )] #[cfg(feature = "jit" )]
extern crate evmjit; extern crate evmjit;
use ethcore_util::hash::*; pub mod blockheader;
use ethcore_util::uint::*;
pub type Bytes = Vec<u8>;
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<Bytes>,
}
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,
}
#[test] #[test]
fn memorydb() { fn it_works() {
}
/// Silly function to return 69.
///
/// # Example
///
/// ```
/// assert_eq!(ethcore::sixtynine(), 69);
/// ```
pub fn sixtynine() -> i32 {
debug!("Hello world!");
69
} }