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.
#[derive(Clone, Debug)]
pub struct EvmParams {
pub struct ActionParams {
/// Address of currently executed code.
pub address: Address,
/// Sender of current part of the transaction.
@ -24,9 +24,9 @@ pub struct EvmParams {
pub data: Bytes
}
impl EvmParams {
pub fn new() -> EvmParams {
EvmParams {
impl ActionParams {
pub fn new() -> ActionParams {
ActionParams {
address: Address::new(),
sender: Address::new(),
origin: Address::new(),

View File

@ -8,4 +8,5 @@ pub use header::*;
pub use account::*;
pub use transaction::*;
pub use log_entry::*;
pub use receipt::*;
pub use receipt::*;
pub use action_params::*;

View File

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

View File

@ -319,7 +319,7 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
pub struct 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;
// 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)) };
@ -423,7 +423,7 @@ mod tests {
#[test]
fn test_ext_add() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
@ -447,7 +447,7 @@ mod tests {
#[test]
fn test_ext_sha3_0() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "6000600020600055".from_hex().unwrap();
@ -471,7 +471,7 @@ mod tests {
#[test]
fn test_ext_sha3_1() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "6005600420600055".from_hex().unwrap();
@ -495,7 +495,7 @@ mod tests {
#[test]
fn test_origin() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.origin = address.clone();
params.gas = U256::from(0x174876e800u64);
@ -519,7 +519,7 @@ mod tests {
#[test]
fn test_sender() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.sender = address.clone();
params.gas = U256::from(0x174876e800u64);
@ -558,7 +558,7 @@ mod tests {
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
let address_code = "333b60006000333c600051600055".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.sender = sender.clone();
params.origin = sender.clone();
@ -586,7 +586,7 @@ mod tests {
#[test]
fn test_balance() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.sender = address.clone();
params.gas = U256::from(0x174876e800u64);
@ -611,7 +611,7 @@ mod tests {
#[test]
fn test_empty_log() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "60006000a0".from_hex().unwrap();
@ -645,7 +645,7 @@ mod tests {
// a1 - log with 1 topic
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.sender = address.clone();
params.gas = U256::from(0x174876e800u64);
@ -675,7 +675,7 @@ mod tests {
#[test]
fn test_blockhash() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "600040600055".from_hex().unwrap();
@ -700,7 +700,7 @@ mod tests {
#[test]
fn test_calldataload() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut params = EvmParams::new();
let mut params = ActionParams::new();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "600135600055".from_hex().unwrap();

View File

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

View File

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