Allow fields to be returned so they can be used simultaneously.

This commit is contained in:
Gav Wood 2016-01-10 17:09:02 +01:00
parent 76bb480afb
commit 2cc3ee66d7
2 changed files with 26 additions and 3 deletions

View File

@ -8,6 +8,14 @@ pub struct Entry {
receipt: Receipt,
}
/// A set of fields that are publicly alterable.
pub struct BlockRefMut<'a> {
pub header: &'a Header,
pub state: &'a mut State,
pub archive: &'a Vec<Entry>,
pub uncles: &'a Vec<Header>,
}
/// Internal type for a block's common elements.
pub struct Block {
header: Header,
@ -32,7 +40,14 @@ impl Block {
}
}
pub fn state_mut(&mut self) -> &mut State { &mut self.state }
pub fn fields(&mut self) -> BlockRefMut {
BlockRefMut {
header: &self.header,
state: &mut self.state,
archive: &self.archive,
uncles: &self.uncles,
}
}
}
/// Trait for a object that is_a `Block`.

View File

@ -22,8 +22,16 @@ impl Engine for Ethash {
/// Apply the block reward on finalisation of the block.
fn on_close_block(&self, block: &mut Block) {
let a = block.header().author.clone();
block.state_mut().add_balance(&a, &decode(&self.spec().engine_params.get("blockReward").unwrap()));
let reward = self.spec().engine_params.get("blockReward").map(|a| decode(&a)).unwrap_or(U256::from(0u64));
let fields = block.fields();
let author = &fields.header.author;
fields.state.add_balance(author, &reward);
/*
let uncle_authors = block.uncles.iter().map(|u| u.author().clone()).collect();
for a in uncle_authors {
block.state_mut().addBalance(a, _blockReward * (8 + i.number() - m_currentBlock.number()) / 8);
r += _blockReward / 32;
}*/
}
}