openethereum/src/ethash.rs

33 lines
913 B
Rust
Raw Normal View History

2016-01-08 21:33:41 +01:00
use util::error::*;
use util::rlp::decode;
2016-01-08 12:15:59 +01:00
use engine::Engine;
use spec::Spec;
2016-01-08 21:33:41 +01:00
use block::*;
2016-01-08 12:15:59 +01:00
use evm_schedule::EvmSchedule;
use env_info::EnvInfo;
/// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum
/// mainnet chains in the Olympic, Frontier and Homestead eras.
pub struct Ethash {
spec: Spec,
}
impl Ethash {
pub fn new_boxed(spec: Spec) -> Box<Engine> {
2016-01-08 12:27:00 +01:00
Box::new(Ethash{spec: spec})
2016-01-08 12:15:59 +01:00
}
}
2016-01-08 12:27:00 +01:00
impl Engine for Ethash {
2016-01-08 12:15:59 +01:00
fn name(&self) -> &str { "Ethash" }
fn spec(&self) -> &Spec { &self.spec }
fn evm_schedule(&self, _env_info: &EnvInfo) -> EvmSchedule { EvmSchedule::new_frontier() }
2016-01-08 19:12:19 +01:00
/// Apply the block reward on finalisation of the block.
fn on_close_block(&self, block: &mut Block) -> Result<(), EthcoreError> {
let a = block.header().author.clone();
2016-01-08 21:33:41 +01:00
block.state_mut().add_balance(&a, &decode(&self.spec().engine_params.get("block_reward").unwrap()));
Ok(())
2016-01-08 19:12:19 +01:00
}
2016-01-08 12:15:59 +01:00
}