Move evm::EvmParams -> ActionParams.

This commit is contained in:
Gav Wood 2016-01-11 16:33:08 +01:00
parent 85ac9af832
commit b0cceddb7c
7 changed files with 36 additions and 46 deletions

View File

@ -5,7 +5,7 @@ use util::bytes::*;
/// Evm input params. Everything else should be specified in Externalities. /// Evm input params. Everything else should be specified in Externalities.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct EvmParams { pub struct ActionParams {
/// Address of currently executed code. /// Address of currently executed code.
pub address: Address, pub address: Address,
/// Sender of current part of the transaction. /// Sender of current part of the transaction.
@ -24,9 +24,9 @@ pub struct EvmParams {
pub data: Bytes pub data: Bytes
} }
impl EvmParams { impl ActionParams {
pub fn new() -> EvmParams { pub fn new() -> ActionParams {
EvmParams { ActionParams {
address: Address::new(), address: Address::new(),
sender: Address::new(), sender: Address::new(),
origin: Address::new(), origin: Address::new(),

View File

@ -9,3 +9,4 @@ pub use account::*;
pub use transaction::*; pub use transaction::*;
pub use log_entry::*; pub use log_entry::*;
pub use receipt::*; pub use receipt::*;
pub use action_params::*;

View File

@ -1,7 +1,7 @@
//! Evm interface. //! Evm interface.
use util::uint::U256; use common::*;
use evm::{EvmParams, Ext}; use evm::Ext;
/// Evm errors. /// Evm errors.
#[derive(Debug)] #[derive(Debug)]
@ -25,5 +25,5 @@ pub type EvmResult = Result<U256, EvmError>;
/// Evm interface. /// Evm interface.
pub trait Evm { pub trait Evm {
/// This function should be used to execute transaction. /// This function should be used to execute transaction.
fn exec(&self, params: &EvmParams, ext: &mut Ext) -> EvmResult; fn exec(&self, params: &ActionParams, ext: &mut Ext) -> EvmResult;
} }

View File

@ -1,18 +1,8 @@
//! Transaction Execution environment. //! Transaction Execution environment.
use std::collections::HashSet; use common::*;
use std::cmp;
use std::ptr;
use util::hash::*;
use util::uint::*;
use util::rlp::*;
use util::sha3::*;
use util::bytes::*;
use state::*; use state::*;
use env_info::*;
use engine::*; use engine::*;
use transaction::*; use evm::{Schedule, VmFactory, Ext, EvmResult, EvmError};
use log_entry::*;
use evm::{Schedule, VmFactory, Ext, EvmParams, EvmResult, EvmError};
/// Returns new address created from address and given nonce. /// Returns new address created from address and given nonce.
pub fn contract_address(address: &Address, nonce: &U256) -> Address { pub fn contract_address(address: &Address, nonce: &U256) -> Address {
@ -158,7 +148,7 @@ impl<'a> Executive<'a> {
let res = match t.action() { let res = match t.action() {
&Action::Create => { &Action::Create => {
let params = EvmParams { let params = ActionParams {
address: contract_address(&sender, &nonce), address: contract_address(&sender, &nonce),
sender: sender.clone(), sender: sender.clone(),
origin: sender.clone(), origin: sender.clone(),
@ -171,7 +161,7 @@ impl<'a> Executive<'a> {
self.create(&params, &mut substate) self.create(&params, &mut substate)
}, },
&Action::Call(ref address) => { &Action::Call(ref address) => {
let params = EvmParams { let params = ActionParams {
address: address.clone(), address: address.clone(),
sender: sender.clone(), sender: sender.clone(),
origin: sender.clone(), origin: sender.clone(),
@ -193,7 +183,7 @@ impl<'a> Executive<'a> {
/// NOTE. It does not finalize the transaction (doesn't do refunds, nor suicides). /// NOTE. It does not finalize the transaction (doesn't do refunds, nor suicides).
/// Modifies the substate and the output. /// Modifies the substate and the output.
/// Returns either gas_left or `EvmError`. /// Returns either gas_left or `EvmError`.
fn call(&mut self, params: &EvmParams, substate: &mut Substate, output: &mut [u8]) -> EvmResult { fn call(&mut self, params: &ActionParams, substate: &mut Substate, output: &mut [u8]) -> EvmResult {
// at first, transfer value to destination // at first, transfer value to destination
self.state.transfer_balance(&params.sender, &params.address, &params.value); self.state.transfer_balance(&params.sender, &params.address, &params.value);
@ -221,7 +211,7 @@ impl<'a> Executive<'a> {
/// Creates contract with given contract params. /// Creates contract with given contract params.
/// NOTE. It does not finalize the transaction (doesn't do refunds, nor suicides). /// NOTE. It does not finalize the transaction (doesn't do refunds, nor suicides).
/// Modifies the substate. /// Modifies the substate.
fn create(&mut self, params: &EvmParams, substate: &mut Substate) -> EvmResult { fn create(&mut self, params: &ActionParams, substate: &mut Substate) -> EvmResult {
// at first create new contract // at first create new contract
self.state.new_contract(&params.address); self.state.new_contract(&params.address);
// then transfer value to it // then transfer value to it
@ -291,7 +281,7 @@ pub struct Externalities<'a> {
info: &'a EnvInfo, info: &'a EnvInfo,
engine: &'a Engine, engine: &'a Engine,
depth: usize, depth: usize,
params: &'a EvmParams, params: &'a ActionParams,
substate: &'a mut Substate, substate: &'a mut Substate,
schedule: Schedule, schedule: Schedule,
output: OutputPolicy<'a> output: OutputPolicy<'a>
@ -303,7 +293,7 @@ impl<'a> Externalities<'a> {
info: &'a EnvInfo, info: &'a EnvInfo,
engine: &'a Engine, engine: &'a Engine,
depth: usize, depth: usize,
params: &'a EvmParams, params: &'a ActionParams,
substate: &'a mut Substate, substate: &'a mut Substate,
output: OutputPolicy<'a>) -> Self { output: OutputPolicy<'a>) -> Self {
Externalities { Externalities {
@ -319,7 +309,7 @@ impl<'a> Externalities<'a> {
} }
/// Creates `Externalities` from `Executive`. /// Creates `Externalities` from `Executive`.
pub fn from_executive(e: &'a mut Executive, params: &'a EvmParams, substate: &'a mut Substate, output: OutputPolicy<'a>) -> Self { pub fn from_executive(e: &'a mut Executive, params: &'a ActionParams, substate: &'a mut Substate, output: OutputPolicy<'a>) -> Self {
Self::new(e.state, e.info, e.engine, e.depth, params, substate, output) Self::new(e.state, e.info, e.engine, e.depth, params, substate, output)
} }
} }
@ -361,7 +351,7 @@ impl<'a> Ext for Externalities<'a> {
let address = contract_address(&self.params.address, &self.state.nonce(&self.params.address)); let address = contract_address(&self.params.address, &self.state.nonce(&self.params.address));
// prepare the params // prepare the params
let params = EvmParams { let params = ActionParams {
address: address.clone(), address: address.clone(),
sender: self.params.address.clone(), sender: self.params.address.clone(),
origin: self.params.origin.clone(), origin: self.params.origin.clone(),
@ -404,7 +394,7 @@ impl<'a> Ext for Externalities<'a> {
return Ok(gas + call_gas) return Ok(gas + call_gas)
} }
let params = EvmParams { let params = ActionParams {
address: receive_address.clone(), address: receive_address.clone(),
sender: self.params.address.clone(), sender: self.params.address.clone(),
origin: self.params.origin.clone(), origin: self.params.origin.clone(),
@ -489,7 +479,7 @@ mod tests {
fn test_executive() { fn test_executive() {
let sender = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let sender = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let address = contract_address(&sender, &U256::zero()); let address = contract_address(&sender, &U256::zero());
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = sender.clone(); params.sender = sender.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
@ -516,7 +506,7 @@ mod tests {
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(); let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
let address = contract_address(&sender, &U256::zero()); let address = contract_address(&sender, &U256::zero());
let next_address = contract_address(&address, &U256::zero()); let next_address = contract_address(&address, &U256::zero());
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = sender.clone(); params.sender = sender.clone();
params.origin = sender.clone(); params.origin = sender.clone();
@ -562,7 +552,7 @@ mod tests {
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(); let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
let code = "600160005401600055600060006000600060003060e05a03f1600155".from_hex().unwrap(); let code = "600160005401600055600060006000600060003060e05a03f1600155".from_hex().unwrap();
let address = contract_address(&sender, &U256::zero()); let address = contract_address(&sender, &U256::zero());
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = sender.clone(); params.sender = sender.clone();
params.origin = sender.clone(); params.origin = sender.clone();

View File

@ -319,7 +319,7 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
pub struct JitEvm; pub struct JitEvm;
impl evm::Evm for JitEvm { impl evm::Evm for JitEvm {
fn exec(&self, params: &evm::EvmParams, ext: &mut evm::Ext) -> evm::EvmResult { fn exec(&self, params: &evm::ActionParams, ext: &mut evm::Ext) -> evm::EvmResult {
let mut optional_err = None; let mut optional_err = None;
// Dirty hack. This is unsafe, but we interact with ffi, so it's justified. // Dirty hack. This is unsafe, but we interact with ffi, so it's justified.
let ext_adapter: ExtAdapter<'static> = unsafe { ::std::mem::transmute(ExtAdapter::new(ext, &mut optional_err)) }; let ext_adapter: ExtAdapter<'static> = unsafe { ::std::mem::transmute(ExtAdapter::new(ext, &mut optional_err)) };
@ -423,7 +423,7 @@ mod tests {
#[test] #[test]
fn test_ext_add() { fn test_ext_add() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap(); params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
@ -447,7 +447,7 @@ mod tests {
#[test] #[test]
fn test_ext_sha3_0() { fn test_ext_sha3_0() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
params.code = "6000600020600055".from_hex().unwrap(); params.code = "6000600020600055".from_hex().unwrap();
@ -471,7 +471,7 @@ mod tests {
#[test] #[test]
fn test_ext_sha3_1() { fn test_ext_sha3_1() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
params.code = "6005600420600055".from_hex().unwrap(); params.code = "6005600420600055".from_hex().unwrap();
@ -495,7 +495,7 @@ mod tests {
#[test] #[test]
fn test_origin() { fn test_origin() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.origin = address.clone(); params.origin = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
@ -519,7 +519,7 @@ mod tests {
#[test] #[test]
fn test_sender() { fn test_sender() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = address.clone(); params.sender = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
@ -558,7 +558,7 @@ mod tests {
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(); let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
let address_code = "333b60006000333c600051600055".from_hex().unwrap(); let address_code = "333b60006000333c600051600055".from_hex().unwrap();
let sender_code = "6005600055".from_hex().unwrap(); let sender_code = "6005600055".from_hex().unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = sender.clone(); params.sender = sender.clone();
params.origin = sender.clone(); params.origin = sender.clone();
@ -586,7 +586,7 @@ mod tests {
#[test] #[test]
fn test_balance() { fn test_balance() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = address.clone(); params.sender = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
@ -611,7 +611,7 @@ mod tests {
#[test] #[test]
fn test_empty_log() { fn test_empty_log() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
params.code = "60006000a0".from_hex().unwrap(); params.code = "60006000a0".from_hex().unwrap();
@ -645,7 +645,7 @@ mod tests {
// a1 - log with 1 topic // a1 - log with 1 topic
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.sender = address.clone(); params.sender = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
@ -675,7 +675,7 @@ mod tests {
#[test] #[test]
fn test_blockhash() { fn test_blockhash() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
params.code = "600040600055".from_hex().unwrap(); params.code = "600040600055".from_hex().unwrap();
@ -700,7 +700,7 @@ mod tests {
#[test] #[test]
fn test_calldataload() { fn test_calldataload() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new(); let mut params = ActionParams::new();
params.address = address.clone(); params.address = address.clone();
params.gas = U256::from(0x174876e800u64); params.gas = U256::from(0x174876e800u64);
params.code = "600135600055".from_hex().unwrap(); params.code = "600135600055".from_hex().unwrap();

View File

@ -5,7 +5,6 @@ pub mod evm;
pub mod vmfactory; pub mod vmfactory;
//pub mod logentry; //pub mod logentry;
pub mod executive; pub mod executive;
pub mod params;
pub mod schedule; pub mod schedule;
#[cfg(feature = "jit" )] #[cfg(feature = "jit" )]
mod jit; mod jit;
@ -16,5 +15,4 @@ pub use self::ext::{Ext};
pub use self::vmfactory::VmFactory; pub use self::vmfactory::VmFactory;
// TODO: reduce this to absolutely necessary things // TODO: reduce this to absolutely necessary things
pub use self::executive::{Executive, ExecutionResult, Externalities, Substate, OutputPolicy}; pub use self::executive::{Executive, ExecutionResult, Externalities, Substate, OutputPolicy};
pub use self::params::EvmParams;
pub use self::schedule::Schedule; pub use self::schedule::Schedule;

View File

@ -94,6 +94,7 @@ pub mod env_info;
pub mod engine; pub mod engine;
pub mod state; pub mod state;
pub mod account; pub mod account;
pub mod action_params;
pub mod header; pub mod header;
pub mod transaction; pub mod transaction;
pub mod receipt; pub mod receipt;