diff --git a/src/block.rs b/src/block.rs index ac43be23b..fe6474306 100644 --- a/src/block.rs +++ b/src/block.rs @@ -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, + pub uncles: &'a Vec
, +} + /// 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`. diff --git a/src/ethereum/ethash.rs b/src/ethereum/ethash.rs index f959c3d1d..75b7aa17f 100644 --- a/src/ethereum/ethash.rs +++ b/src/ethereum/ethash.rs @@ -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; + }*/ } }