Allow fields to be returned so they can be used simultaneously.
This commit is contained in:
parent
76bb480afb
commit
2cc3ee66d7
17
src/block.rs
17
src/block.rs
@ -8,6 +8,14 @@ pub struct Entry {
|
|||||||
receipt: Receipt,
|
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.
|
/// Internal type for a block's common elements.
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
header: Header,
|
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`.
|
/// Trait for a object that is_a `Block`.
|
||||||
|
@ -22,8 +22,16 @@ impl Engine for Ethash {
|
|||||||
|
|
||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
fn on_close_block(&self, block: &mut Block) {
|
fn on_close_block(&self, block: &mut Block) {
|
||||||
let a = block.header().author.clone();
|
let reward = self.spec().engine_params.get("blockReward").map(|a| decode(&a)).unwrap_or(U256::from(0u64));
|
||||||
block.state_mut().add_balance(&a, &decode(&self.spec().engine_params.get("blockReward").unwrap()));
|
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;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user