From e6f184851dd18f663d5a482587b4b1c1732cb013 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 14 Dec 2018 17:29:15 +0100 Subject: [PATCH] Merge Machine and WithRewards --- ethcore/src/engines/block_reward.rs | 4 ++-- ethcore/src/engines/null_engine.rs | 4 ++-- ethcore/src/machine.rs | 12 +++++------- machine/src/lib.rs | 17 +++++++---------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/ethcore/src/engines/block_reward.rs b/ethcore/src/engines/block_reward.rs index becb776b8ba..6de3533dc38 100644 --- a/ethcore/src/engines/block_reward.rs +++ b/ethcore/src/engines/block_reward.rs @@ -25,7 +25,7 @@ use std::sync::Arc; use hash::keccak; use error::Error; use machine::WithRewards; -use parity_machine::{Machine, WithBalances}; +use parity_machine::Machine; use trace; use types::BlockNumber; use super::{SystemOrCodeCall, SystemOrCodeCallKind}; @@ -152,7 +152,7 @@ impl BlockRewardContract { /// Applies the given block rewards, i.e. adds the given balance to each beneficiary' address. /// If tracing is enabled the operations are recorded. -pub fn apply_block_rewards( +pub fn apply_block_rewards( rewards: &[(Address, RewardKind, U256)], block: &mut M::LiveBlock, machine: &M, diff --git a/ethcore/src/engines/null_engine.rs b/ethcore/src/engines/null_engine.rs index af5aedaac37..0b3ac18a9d3 100644 --- a/ethcore/src/engines/null_engine.rs +++ b/ethcore/src/engines/null_engine.rs @@ -19,7 +19,7 @@ use engines::Engine; use engines::block_reward::{self, RewardKind}; use header::BlockNumber; use machine::WithRewards; -use parity_machine::{Header, LiveBlock, WithBalances, TotalScoredHeader}; +use parity_machine::{Machine, Header, LiveBlock, TotalScoredHeader}; /// Params for a null engine. #[derive(Clone, Default)] @@ -58,7 +58,7 @@ impl Default for NullEngine { } } -impl Engine for NullEngine +impl Engine for NullEngine where M::ExtendedHeader: TotalScoredHeader, ::Value: Ord { diff --git a/ethcore/src/machine.rs b/ethcore/src/machine.rs index 47cea85059b..8bec959867a 100644 --- a/ethcore/src/machine.rs +++ b/ethcore/src/machine.rs @@ -436,14 +436,7 @@ impl ::parity_machine::Machine for EthereumMachine { type AncestryAction = ::types::ancestry_action::AncestryAction; type Error = Error; -} - -impl<'a> ::parity_machine::LocalizedMachine<'a> for EthereumMachine { - type StateContext = Call<'a>; - type AuxiliaryData = AuxiliaryData<'a>; -} -impl ::parity_machine::WithBalances for EthereumMachine { fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result { live.state().balance(address).map_err(Into::into) } @@ -453,6 +446,11 @@ impl ::parity_machine::WithBalances for EthereumMachine { } } +impl<'a> ::parity_machine::LocalizedMachine<'a> for EthereumMachine { + type StateContext = Call<'a>; + type AuxiliaryData = AuxiliaryData<'a>; +} + /// A state machine that uses block rewards. pub trait WithRewards: ::parity_machine::Machine { /// Note block rewards, traces each reward storing information about benefactor, amount and type diff --git a/machine/src/lib.rs b/machine/src/lib.rs index a3f640fe577..8525d926e20 100644 --- a/machine/src/lib.rs +++ b/machine/src/lib.rs @@ -112,6 +112,13 @@ pub trait Machine: for<'a> LocalizedMachine<'a> { /// Errors which can occur when querying or interacting with the machine. type Error; + + /// Get the balance, in base units, associated with an account. + /// Extracts data from the live block. + fn balance(&self, live: &Self::LiveBlock, address: &Address) -> Result; + + /// Increment the balance of an account in the state of the live block. + fn add_balance(&self, live: &mut Self::LiveBlock, address: &Address, amount: &U256) -> Result<(), Self::Error>; } /// Machine-related types localized to a specific lifetime. @@ -123,13 +130,3 @@ pub trait LocalizedMachine<'a>: Sync + Send { /// Generally also provides verifiable proofs. type StateContext: ?Sized + 'a; } - -/// A state machine that uses balances. -pub trait WithBalances: Machine { - /// Get the balance, in base units, associated with an account. - /// Extracts data from the live block. - fn balance(&self, live: &Self::LiveBlock, address: &Address) -> Result; - - /// Increment the balance of an account in the state of the live block. - fn add_balance(&self, live: &mut Self::LiveBlock, address: &Address, amount: &U256) -> Result<(), Self::Error>; -}