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]);
|
36
src/block.rs
36
src/block.rs
@ -1,9 +1,5 @@
|
|||||||
use util::*;
|
use common::*;
|
||||||
use transaction::*;
|
|
||||||
use receipt::*;
|
|
||||||
use engine::*;
|
use engine::*;
|
||||||
use header::*;
|
|
||||||
use env_info::*;
|
|
||||||
use state::*;
|
use state::*;
|
||||||
|
|
||||||
/// A transaction/receipt execution entry.
|
/// 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.
|
/// 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> {
|
pub fn close(mut self, uncles: Vec<Header>, author: Address, extra_data: Bytes) -> ClosedBlock<'engine> {
|
||||||
// TODO: populate rest of header.
|
// populate rest of header.
|
||||||
self.engine.on_close_block(...);
|
// self.engine.on_close_block(...);
|
||||||
self.header.author = author;
|
self.block.header.author = author;
|
||||||
// self.header.transactions_root = ...;
|
// self.header.transactions_root = ...;
|
||||||
let s = RlpStream::new_list(uncles.len());
|
let uncle_bytes = uncles.iter().fold(RlpStream::new_list(uncles.len()), |mut s, u| {s.append(&u.rlp(Seal::With)); s} ).out();
|
||||||
for u in uncles.iter() {
|
self.block.header.uncles_hash = uncle_bytes.sha3();
|
||||||
s.append(u.rlp())
|
self.block.header.extra_data = extra_data;
|
||||||
}
|
self.block.header.state_root = self.block.state.root().clone();
|
||||||
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.receipts_root = ...;
|
||||||
//self.header.log_bloom = ...; // will need to amalgamate.
|
self.block.header.log_bloom = self.block.archive.iter().fold(LogBloom::zero(), |mut b, e| {b |= &e.receipt.log_bloom; b});
|
||||||
self.header.gas_used = self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0));
|
self.block.header.gas_used = self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0));
|
||||||
self.header.note_dirty();
|
self.block.header.note_dirty();
|
||||||
|
|
||||||
ClosedBlock::new(self, uncle_bytes)
|
ClosedBlock::new(self, uncle_bytes)
|
||||||
}
|
}
|
||||||
@ -151,8 +143,8 @@ impl<'engine> IsBlock for OpenBlock<'engine> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'engine> ClosedBlock<'engine> {
|
impl<'engine> ClosedBlock<'engine> {
|
||||||
fn new(open_block: OpenBlock, uncles: Bytes) -> Self {
|
fn new<'a>(open_block: OpenBlock<'a>, uncles: Bytes) -> ClosedBlock<'a> {
|
||||||
Self {
|
ClosedBlock {
|
||||||
open_block: open_block,
|
open_block: open_block,
|
||||||
uncles: uncles,
|
uncles: uncles,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pub use util::*;
|
pub use util::*;
|
||||||
|
pub use basic_types::*;
|
||||||
pub use env_info::*;
|
pub use env_info::*;
|
||||||
pub use evm_schedule::*;
|
pub use evm_schedule::*;
|
||||||
pub use views::*;
|
pub use views::*;
|
||||||
@ -6,3 +7,4 @@ pub use builtin::*;
|
|||||||
pub use header::*;
|
pub use header::*;
|
||||||
pub use account::*;
|
pub use account::*;
|
||||||
pub use transaction::*;
|
pub use transaction::*;
|
||||||
|
pub use receipt::*;
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
use util::*;
|
use util::*;
|
||||||
|
use basic_types::*;
|
||||||
/// 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]);
|
|
||||||
|
|
||||||
/// A block header.
|
/// A block header.
|
||||||
///
|
///
|
||||||
@ -39,13 +30,11 @@ pub struct Header {
|
|||||||
pub hash: RefCell<Option<H256>>, //TODO: make this private
|
pub hash: RefCell<Option<H256>>, //TODO: make this private
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SealInclusion {
|
pub enum Seal {
|
||||||
WithSeal,
|
With,
|
||||||
WithoutSeal,
|
Without,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use SealInclusion::*;
|
|
||||||
|
|
||||||
impl Header {
|
impl Header {
|
||||||
/// Create a new, default-valued, header.
|
/// Create a new, default-valued, header.
|
||||||
pub fn new() -> Header {
|
pub fn new() -> Header {
|
||||||
@ -77,8 +66,8 @@ impl Header {
|
|||||||
match &mut *hash {
|
match &mut *hash {
|
||||||
&mut Some(ref h) => h.clone(),
|
&mut Some(ref h) => h.clone(),
|
||||||
hash @ &mut None => {
|
hash @ &mut None => {
|
||||||
*hash = Some(self.hash(WithSeal));
|
*hash = Some(self.rlp_sha3(Seal::With));
|
||||||
hash.unwrap().clone()
|
hash.as_ref().unwrap().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,8 +80,8 @@ impl Header {
|
|||||||
// TODO: get hash without seal.
|
// TODO: get hash without seal.
|
||||||
|
|
||||||
// TODO: make these functions traity
|
// TODO: make these functions traity
|
||||||
pub fn stream_rlp(&self, s: &mut RlpStream, with_seal: SealInclusion) {
|
pub fn stream_rlp(&self, s: &mut RlpStream, with_seal: Seal) {
|
||||||
s.append_list(13 + if with_seal == WithSeal {self.seal.len()} else {0})
|
s.append_list(13 + match with_seal { Seal::With => self.seal.len(), _ => 0 });
|
||||||
s.append(&self.parent_hash);
|
s.append(&self.parent_hash);
|
||||||
s.append(&self.uncles_hash);
|
s.append(&self.uncles_hash);
|
||||||
s.append(&self.author);
|
s.append(&self.author);
|
||||||
@ -106,20 +95,19 @@ impl Header {
|
|||||||
s.append(&self.gas_used);
|
s.append(&self.gas_used);
|
||||||
s.append(&self.timestamp);
|
s.append(&self.timestamp);
|
||||||
s.append(&self.extra_data);
|
s.append(&self.extra_data);
|
||||||
if with_seal == WithSeal {
|
match with_seal {
|
||||||
for b in self.seal.iter() {
|
Seal::With => for b in self.seal.iter() { s.append_raw(&b, 1); },
|
||||||
e.append_raw(&b);
|
_ => {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub rlp(&self, with_seal: SealInclusion) -> Bytes {
|
pub fn rlp(&self, with_seal: Seal) -> Bytes {
|
||||||
let s = RlpStream::new();
|
let mut s = RlpStream::new();
|
||||||
self.stream_rlp(&mut s, with_seal);
|
self.stream_rlp(&mut s, with_seal);
|
||||||
s.out()
|
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 {
|
impl Decodable for Header {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#![feature(cell_extras)]
|
#![feature(cell_extras)]
|
||||||
|
#![feature(augmented_assignments)]
|
||||||
//! Ethcore's ethereum implementation
|
//! Ethcore's ethereum implementation
|
||||||
//!
|
//!
|
||||||
//! ### Rust version
|
//! ### Rust version
|
||||||
@ -85,6 +85,7 @@ extern crate evmjit;
|
|||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
pub mod basic_types;
|
||||||
pub mod env_info;
|
pub mod env_info;
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use util::*;
|
use util::*;
|
||||||
|
use basic_types::LogBloom;
|
||||||
|
|
||||||
/// Information describing execution of a transaction.
|
/// Information describing execution of a transaction.
|
||||||
pub struct Receipt {
|
pub struct Receipt {
|
||||||
// TODO
|
// TODO
|
||||||
pub state_root: H256,
|
pub state_root: H256,
|
||||||
pub gas_used: U256,
|
pub gas_used: U256,
|
||||||
|
pub log_bloom: LogBloom,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user