simplify block module and usage (#10479)

* removed trait IsBlock and simplify block usage

* removed redundant ClosedBlock::hash function
This commit is contained in:
Marek Kotewicz
2019-03-15 13:22:47 +01:00
committed by Andrew Jones
parent d83143d0ba
commit a574df3132
10 changed files with 125 additions and 152 deletions

View File

@@ -28,7 +28,7 @@ use types::header::Header;
use vm::{CallType, ActionParams, ActionValue, ParamsType};
use vm::{EnvInfo, Schedule, CreateContractAddress};
use block::{ExecutedBlock, IsBlock};
use block::ExecutedBlock;
use builtin::Builtin;
use call_contract::CallContract;
use client::BlockInfo;
@@ -126,7 +126,7 @@ impl EthereumMachine {
data: Option<Vec<u8>>,
) -> Result<Vec<u8>, Error> {
let (code, code_hash) = {
let state = block.state();
let state = &block.state;
(state.code(&contract_address)?,
state.code_hash(&contract_address)?)
@@ -193,12 +193,12 @@ impl EthereumMachine {
/// Push last known block hash to the state.
fn push_last_hash(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
let params = self.params();
if block.header().number() == params.eip210_transition {
if block.header.number() == params.eip210_transition {
let state = block.state_mut();
state.init_code(&params.eip210_contract_address, params.eip210_contract_code.clone())?;
}
if block.header().number() >= params.eip210_transition {
let parent_hash = block.header().parent_hash().clone();
if block.header.number() >= params.eip210_transition {
let parent_hash = *block.header.parent_hash();
let _ = self.execute_as_system(
block,
params.eip210_contract_address,
@@ -215,7 +215,7 @@ impl EthereumMachine {
self.push_last_hash(block)?;
if let Some(ref ethash_params) = self.ethash_extensions {
if block.header().number() == ethash_params.dao_hardfork_transition {
if block.header.number() == ethash_params.dao_hardfork_transition {
let state = block.state_mut();
for child in &ethash_params.dao_hardfork_accounts {
let beneficiary = &ethash_params.dao_hardfork_beneficiary;
@@ -434,7 +434,7 @@ impl super::Machine for EthereumMachine {
type Error = Error;
fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result<U256, Error> {
live.state().balance(address).map_err(Into::into)
live.state.balance(address).map_err(Into::into)
}
fn add_balance(&self, live: &mut ExecutedBlock, address: &Address, amount: &U256) -> Result<(), Error> {