Skip to content
Snippets Groups Projects
Commit fea41870 authored by Gav Wood's avatar Gav Wood
Browse files

Better API allowing one fewer clone.

parent 2cc3ee66
Branches
Tags
No related merge requests found
......@@ -8,14 +8,6 @@ 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,
......@@ -29,7 +21,16 @@ pub struct Block {
uncles: Vec<Header>,
}
/// A set of references to `Block` fields that are publicly accessible.
pub struct BlockRefMut<'a> {
pub header: &'a Header,
pub state: &'a mut State,
pub archive: &'a Vec<Entry>,
pub uncles: &'a Vec<Header>,
}
impl Block {
/// Create a new block from the given `state`.
fn new(state: State) -> Block {
Block {
header: Header::new(),
......@@ -40,6 +41,7 @@ impl Block {
}
}
/// Get a structure containing individual references to all public fields.
pub fn fields(&mut self) -> BlockRefMut {
BlockRefMut {
header: &self.header,
......
......@@ -24,8 +24,7 @@ impl Engine for Ethash {
fn on_close_block(&self, block: &mut Block) {
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);
fields.state.add_balance(&fields.header.author, &reward);
/*
let uncle_authors = block.uncles.iter().map(|u| u.author().clone()).collect();
for a in uncle_authors {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment