Minor refactoring, OpenBlock::close closer to working.
This commit is contained in:
parent
8b5b493f7d
commit
249c615752
7
src/basic_types.rs
Normal file
7
src/basic_types.rs
Normal file
@ -0,0 +1,7 @@
|
||||
use util::*;
|
||||
|
||||
/// Type for a 2048-bit log-bloom, as used by our blocks.
|
||||
pub type LogBloom = H2048;
|
||||
|
||||
/// Constant 2048-bit datum for 0. Often used as a default.
|
||||
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
|
40
src/block.rs
40
src/block.rs
@ -1,9 +1,5 @@
|
||||
use util::*;
|
||||
use transaction::*;
|
||||
use receipt::*;
|
||||
use common::*;
|
||||
use engine::*;
|
||||
use header::*;
|
||||
use env_info::*;
|
||||
use state::*;
|
||||
|
||||
/// A transaction/receipt execution entry.
|
||||
@ -124,23 +120,19 @@ impl<'engine> OpenBlock<'engine> {
|
||||
}
|
||||
|
||||
/// Turn this into a `ClosedBlock`. A BlockChain must be provided in order to figure out the uncles.
|
||||
pub fn close(self, uncles: Vec<Header>, author: Address, extra_data: Bytes) -> ClosedBlock<'engine> {
|
||||
// TODO: populate rest of header.
|
||||
self.engine.on_close_block(...);
|
||||
self.header.author = author;
|
||||
//self.header.transactions_root = ...;
|
||||
let s = RlpStream::new_list(uncles.len());
|
||||
for u in uncles.iter() {
|
||||
s.append(u.rlp())
|
||||
}
|
||||
let uncle_bytes = u.out();
|
||||
self.header.uncles_hash = uncle_bytes.sha3();
|
||||
self.header.extra_data = extra_data;
|
||||
self.header.state_root = self.state.root().clone();
|
||||
//self.header.receipts_root = ...;
|
||||
//self.header.log_bloom = ...; // will need to amalgamate.
|
||||
self.header.gas_used = self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0));
|
||||
self.header.note_dirty();
|
||||
pub fn close(mut self, uncles: Vec<Header>, author: Address, extra_data: Bytes) -> ClosedBlock<'engine> {
|
||||
// populate rest of header.
|
||||
// self.engine.on_close_block(...);
|
||||
self.block.header.author = author;
|
||||
// self.header.transactions_root = ...;
|
||||
let uncle_bytes = uncles.iter().fold(RlpStream::new_list(uncles.len()), |mut s, u| {s.append(&u.rlp(Seal::With)); s} ).out();
|
||||
self.block.header.uncles_hash = uncle_bytes.sha3();
|
||||
self.block.header.extra_data = extra_data;
|
||||
self.block.header.state_root = self.block.state.root().clone();
|
||||
// self.header.receipts_root = ...;
|
||||
self.block.header.log_bloom = self.block.archive.iter().fold(LogBloom::zero(), |mut b, e| {b |= &e.receipt.log_bloom; b});
|
||||
self.block.header.gas_used = self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0));
|
||||
self.block.header.note_dirty();
|
||||
|
||||
ClosedBlock::new(self, uncle_bytes)
|
||||
}
|
||||
@ -151,8 +143,8 @@ impl<'engine> IsBlock for OpenBlock<'engine> {
|
||||
}
|
||||
|
||||
impl<'engine> ClosedBlock<'engine> {
|
||||
fn new(open_block: OpenBlock, uncles: Bytes) -> Self {
|
||||
Self {
|
||||
fn new<'a>(open_block: OpenBlock<'a>, uncles: Bytes) -> ClosedBlock<'a> {
|
||||
ClosedBlock {
|
||||
open_block: open_block,
|
||||
uncles: uncles,
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub use util::*;
|
||||
pub use basic_types::*;
|
||||
pub use env_info::*;
|
||||
pub use evm_schedule::*;
|
||||
pub use views::*;
|
||||
@ -6,3 +7,4 @@ pub use builtin::*;
|
||||
pub use header::*;
|
||||
pub use account::*;
|
||||
pub use transaction::*;
|
||||
pub use receipt::*;
|
||||
|
@ -1,14 +1,5 @@
|
||||
use util::*;
|
||||
|
||||
/// Type for a 2048-bit log-bloom, as used by our blocks.
|
||||
pub type LogBloom = H2048;
|
||||
|
||||
/// Constant address for point 0. Often used as a default.
|
||||
pub static ZERO_ADDRESS: Address = Address([0x00; 20]);
|
||||
/// Constant 256-bit datum for 0. Often used as a default.
|
||||
pub static ZERO_H256: H256 = H256([0x00; 32]);
|
||||
/// Constant 2048-bit datum for 0. Often used as a default.
|
||||
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
|
||||
use basic_types::*;
|
||||
|
||||
/// A block header.
|
||||
///
|
||||
@ -39,13 +30,11 @@ pub struct Header {
|
||||
pub hash: RefCell<Option<H256>>, //TODO: make this private
|
||||
}
|
||||
|
||||
enum SealInclusion {
|
||||
WithSeal,
|
||||
WithoutSeal,
|
||||
pub enum Seal {
|
||||
With,
|
||||
Without,
|
||||
}
|
||||
|
||||
pub use SealInclusion::*;
|
||||
|
||||
impl Header {
|
||||
/// Create a new, default-valued, header.
|
||||
pub fn new() -> Header {
|
||||
@ -77,8 +66,8 @@ impl Header {
|
||||
match &mut *hash {
|
||||
&mut Some(ref h) => h.clone(),
|
||||
hash @ &mut None => {
|
||||
*hash = Some(self.hash(WithSeal));
|
||||
hash.unwrap().clone()
|
||||
*hash = Some(self.rlp_sha3(Seal::With));
|
||||
hash.as_ref().unwrap().clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,8 +80,8 @@ impl Header {
|
||||
// TODO: get hash without seal.
|
||||
|
||||
// TODO: make these functions traity
|
||||
pub fn stream_rlp(&self, s: &mut RlpStream, with_seal: SealInclusion) {
|
||||
s.append_list(13 + if with_seal == WithSeal {self.seal.len()} else {0})
|
||||
pub fn stream_rlp(&self, s: &mut RlpStream, with_seal: Seal) {
|
||||
s.append_list(13 + match with_seal { Seal::With => self.seal.len(), _ => 0 });
|
||||
s.append(&self.parent_hash);
|
||||
s.append(&self.uncles_hash);
|
||||
s.append(&self.author);
|
||||
@ -106,20 +95,19 @@ impl Header {
|
||||
s.append(&self.gas_used);
|
||||
s.append(&self.timestamp);
|
||||
s.append(&self.extra_data);
|
||||
if with_seal == WithSeal {
|
||||
for b in self.seal.iter() {
|
||||
e.append_raw(&b);
|
||||
}
|
||||
match with_seal {
|
||||
Seal::With => for b in self.seal.iter() { s.append_raw(&b, 1); },
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub rlp(&self, with_seal: SealInclusion) -> Bytes {
|
||||
let s = RlpStream::new();
|
||||
pub fn rlp(&self, with_seal: Seal) -> Bytes {
|
||||
let mut s = RlpStream::new();
|
||||
self.stream_rlp(&mut s, with_seal);
|
||||
s.out()
|
||||
}
|
||||
|
||||
pub hash(&self, with_seal: SealInclusion) -> H256 { self.rlp().sha3() }
|
||||
pub fn rlp_sha3(&self, with_seal: Seal) -> H256 { self.rlp(with_seal).sha3() }
|
||||
}
|
||||
|
||||
impl Decodable for Header {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![feature(cell_extras)]
|
||||
|
||||
#![feature(augmented_assignments)]
|
||||
//! Ethcore's ethereum implementation
|
||||
//!
|
||||
//! ### Rust version
|
||||
@ -85,6 +85,7 @@ extern crate evmjit;
|
||||
extern crate ethcore_util as util;
|
||||
|
||||
pub mod common;
|
||||
pub mod basic_types;
|
||||
pub mod env_info;
|
||||
pub mod engine;
|
||||
pub mod state;
|
||||
|
@ -1,8 +1,10 @@
|
||||
use util::*;
|
||||
use basic_types::LogBloom;
|
||||
|
||||
/// Information describing execution of a transaction.
|
||||
pub struct Receipt {
|
||||
// TODO
|
||||
pub state_root: H256,
|
||||
pub gas_used: U256,
|
||||
pub log_bloom: LogBloom,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user