diff --git a/src/block.rs b/src/block.rs index 941cef985..e725a69f6 100644 --- a/src/block.rs +++ b/src/block.rs @@ -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(); @@ -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 { - 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 { + 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()); @@ -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); } diff --git a/src/header.rs b/src/header.rs index 5a274bb5e..41230b2ce 100644 --- a/src/header.rs +++ b/src/header.rs @@ -70,6 +70,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 { &self.seal } // TODO: seal_at, set_seal_at &c.