Better API allowing one fewer clone.
This commit is contained in:
parent
2cc3ee66d7
commit
fea418703b
18
src/block.rs
18
src/block.rs
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user