Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Use getter in header in preparation for a Header trait; additional testing in enact_block(). #64

Merged
merged 1 commit into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
/// Create a new OpenBlock ready for transaction pushing.
pub fn new<'a, 'b>(engine: &'a Engine, db: OverlayDB, parent: &Header, last_hashes: &'b LastHashes, author: Address, extra_data: Bytes) -> OpenBlock<'a, 'b> {
let mut r = OpenBlock {
block: Block::new(State::from_existing(db, parent.state_root.clone(), engine.account_start_nonce())),
block: Block::new(State::from_existing(db, parent.state_root().clone(), engine.account_start_nonce())),
engine: engine,
last_hashes: last_hashes,
};

r.block.header.set_number(parent.number() + 1);
r.block.header.set_author(author);
r.block.header.set_extra_data(extra_data);
r.block.header.set_timestamp_now();
Expand Down Expand Up @@ -249,8 +250,10 @@ impl IsBlock for SealedBlock {
fn block(&self) -> &Block { &self.block }
}

pub fn enact(rlp_bytes: &[u8], engine: &Engine, db: OverlayDB, parent: &Header, last_hashes: &LastHashes) -> Result<SealedBlock, Error> {
let block = BlockView::new(rlp_bytes);
/// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header
///
pub fn enact(block_bytes: &[u8], engine: &Engine, db: OverlayDB, parent: &Header, last_hashes: &LastHashes) -> Result<SealedBlock, Error> {
let block = BlockView::new(block_bytes);
let header = block.header_view();
let mut b = OpenBlock::new(engine, db, parent, last_hashes, header.author(), header.extra_data());
b.set_timestamp(header.timestamp());
Expand Down Expand Up @@ -292,4 +295,5 @@ fn enact_block() {

let db = e.drain();
assert_eq!(orig_db.keys(), db.keys());
assert!(orig_db.keys().iter().filter(|k| orig_db.get(k.0) != db.get(k.0)).next() == None);
}
3 changes: 3 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ impl Header {

pub fn extra_data(&self) -> &Bytes { &self.extra_data }

pub fn state_root(&self) -> &H256 { &self.state_root }
pub fn receipts_root(&self) -> &H256 { &self.receipts_root }

pub fn seal(&self) -> &Vec<Bytes> { &self.seal }

// TODO: seal_at, set_seal_at &c.
Expand Down