2016-01-09 12:30:41 +01:00
|
|
|
use common::*;
|
2016-01-08 21:33:41 +01:00
|
|
|
use block::*;
|
2016-01-09 12:30:41 +01:00
|
|
|
use spec::*;
|
|
|
|
use engine::*;
|
2016-01-08 12:15:59 +01:00
|
|
|
|
|
|
|
/// 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.
|
2016-01-08 22:04:21 +01:00
|
|
|
fn on_close_block(&self, block: &mut Block) {
|
2016-01-08 19:12:19 +01:00
|
|
|
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()));
|
2016-01-08 19:12:19 +01:00
|
|
|
}
|
2016-01-08 12:15:59 +01:00
|
|
|
}
|
2016-01-08 22:04:21 +01:00
|
|
|
|
|
|
|
// TODO: test for on_close_block.
|
2016-01-09 12:30:41 +01:00
|
|
|
#[test]
|
|
|
|
fn playpen() {
|
|
|
|
use util::overlaydb::*;
|
|
|
|
let engine = Spec::new_morden().to_engine().unwrap();
|
|
|
|
let genesis_header = engine.spec().genesis_header();
|
|
|
|
let mut db = OverlayDB::new_temp();
|
|
|
|
engine.spec().ensure_db_good(&mut db);
|
2016-01-09 14:19:35 +01:00
|
|
|
// let b = OpenBlock::new(engine.deref(), db, &genesis_header, vec![genesis_header.hash()]);
|
2016-01-09 12:30:41 +01:00
|
|
|
}
|