separated executive and externalities

This commit is contained in:
debris 2016-01-09 17:55:47 +01:00
parent 50af19a7c8
commit 130b2fc46a
6 changed files with 133 additions and 151 deletions

View File

@ -1,6 +1,6 @@
//! Evm interface. //! Evm interface.
use evm::Ext; use evm::{EvmParams, Ext};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum ReturnCode { pub enum ReturnCode {
@ -12,5 +12,5 @@ pub enum ReturnCode {
} }
pub trait Evm { pub trait Evm {
fn exec(&self, ext: &mut Ext) -> ReturnCode; fn exec(&self, params: &EvmParams, ext: &mut Ext) -> ReturnCode;
} }

View File

@ -1,3 +1,4 @@
use std::mem;
use util::hash::*; use util::hash::*;
use util::uint::*; use util::uint::*;
use util::rlp::*; use util::rlp::*;
@ -7,7 +8,7 @@ use state::*;
use env_info::*; use env_info::*;
use engine::*; use engine::*;
use transaction::*; use transaction::*;
use evm::{VmFactory, Ext, LogEntry, EvmParams, ParamsKind, ReturnCode}; use evm::{VmFactory, Ext, LogEntry, EvmParams, ReturnCode};
/// 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 {
@ -29,95 +30,78 @@ pub struct Executive<'a> {
info: &'a EnvInfo, info: &'a EnvInfo,
engine: &'a Engine, engine: &'a Engine,
depth: usize, depth: usize,
params: EvmParams,
logs: Vec<LogEntry>,
refunds: U256,
} }
impl<'a> Executive<'a> { impl<'a> Executive<'a> {
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, t: &Transaction) -> Self { pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine) -> Self {
// TODO: validate nonce ? Executive::new_with_depth(state, info, engine, 0)
let sender = t.sender();
let params = match t.kind() {
TransactionKind::ContractCreation => EvmParams {
address: contract_address(&sender, &t.nonce),
sender: sender.clone(),
origin: sender.clone(),
gas: t.gas,
gas_price: t.gas_price,
value: t.value,
code: t.data.clone(),
data: vec![],
kind: ParamsKind::Create
},
TransactionKind::MessageCall => EvmParams {
address: t.to.clone().unwrap(),
sender: sender.clone(),
origin: sender.clone(),
gas: t.gas,
gas_price: t.gas_price,
value: t.value,
code: state.code(&t.to.clone().unwrap()).unwrap_or(vec![]),
data: t.data.clone(),
kind: ParamsKind::Call
}
};
Executive::new_from_params(state, info, engine, params)
} }
pub fn new_from_params(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, params: EvmParams) -> Self { fn from_parent(e: &'a mut Externalities) -> Self {
Executive::new_with_depth(e.state, e.info, e.engine, e.depth + 1)
}
fn new_with_depth(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, depth: usize) -> Self {
Executive { Executive {
state: state, state: state,
info: info, info: info,
engine: engine, engine: engine,
depth: 0, depth: depth,
params: params,
logs: vec![],
refunds: U256::zero(),
} }
} }
fn from_parent(e: &'a mut Executive, params: EvmParams) -> Self { pub fn transact(e: &mut Executive<'a>, t: &Transaction) -> ExecutiveResult {
Executive {
state: e.state,
info: e.info,
engine: e.engine,
depth: e.depth + 1,
params: params,
logs: vec![],
refunds: U256::zero(),
}
}
pub fn exec(&mut self) -> ExecutiveResult {
// TODO: validate that we have enough funds // TODO: validate that we have enough funds
// TODO: validate nonce ?
let sender = t.sender();
match &self.params.kind() { match t.kind() {
&ParamsKind::Call => { TransactionKind::ContractCreation => {
self.state.inc_nonce(&self.params.address); let params = EvmParams {
self.call() address: contract_address(&sender, &t.nonce),
sender: sender.clone(),
origin: sender.clone(),
gas: t.gas,
gas_price: t.gas_price,
value: t.value,
code: t.data.clone(),
data: vec![],
};
e.state.inc_nonce(&params.address);
unimplemented!()
//Executive::call(e, &params)
}, },
&ParamsKind::Create => self.create() TransactionKind::MessageCall => {
let params = EvmParams {
address: t.to.clone().unwrap(),
sender: sender.clone(),
origin: sender.clone(),
gas: t.gas,
gas_price: t.gas_price,
value: t.value,
code: e.state.code(&t.to.clone().unwrap()).unwrap_or(vec![]),
data: t.data.clone(),
};
e.state.inc_nonce(&params.address);
Executive::create(e, &params)
}
} }
} }
fn call(&mut self) -> ExecutiveResult { fn call(e: &mut Executive<'a>, p: &EvmParams) -> ExecutiveResult {
//let _ext = Externalities::from_executive(e, &p);
ExecutiveResult::Ok ExecutiveResult::Ok
} }
fn create(&mut self) -> ExecutiveResult {
self.state.inc_nonce(&self.params.sender);
fn create(e: &mut Executive<'a>, params: &EvmParams) -> ExecutiveResult {
//self.state.require_or_from(&self.params.address, false, ||Account::new_contract(U256::from(0))); //self.state.require_or_from(&self.params.address, false, ||Account::new_contract(U256::from(0)));
self.state.transfer_balance(&self.params.sender, &self.params.address, &self.params.value); e.state.transfer_balance(&params.sender, &params.address, &params.value);
let mut ext = Externalities::new(e.state, e.info, e.engine, e.depth, params);
let code = { let code = {
let evm = VmFactory::create(); let evm = VmFactory::create();
// TODO: valdidate that exec returns proper code evm.exec(&params, &mut ext)
evm.exec(self)
}; };
match code { match code {
@ -139,17 +123,43 @@ impl<'a> Executive<'a> {
} }
} }
} }
}
pub struct Externalities<'a> {
state: &'a mut State,
info: &'a EnvInfo,
engine: &'a Engine,
depth: usize,
params: &'a EvmParams,
logs: Vec<LogEntry>,
refunds: U256
}
impl<'a> Externalities<'a> {
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, depth: usize, params: &'a EvmParams) -> Self {
Externalities {
state: state,
info: info,
engine: engine,
depth: depth,
params: params,
logs: vec![],
refunds: U256::zero()
}
}
// TODO: figure out how to use this function
// so the lifetime checker is satisfied
//pub fn from_executive(e: &mut Executive<'a>, params: &EvmParams) -> Self {
//Externalities::new(e.state, e.info, e.engine, e.depth, params)
//}
pub fn logs(&self) -> &[LogEntry] { pub fn logs(&self) -> &[LogEntry] {
&self.logs &self.logs
} }
} }
impl<'a> Ext for Executive<'a> { impl<'a> Ext for Externalities<'a> {
fn params(&self) -> &EvmParams {
&self.params
}
fn sload(&self, key: &H256) -> H256 { fn sload(&self, key: &H256) -> H256 {
self.state.storage_at(&self.params.address, key) self.state.storage_at(&self.params.address, key)
} }
@ -189,12 +199,10 @@ impl<'a> Ext for Executive<'a> {
value: endowment.clone(), value: endowment.clone(),
code: code.to_vec(), code: code.to_vec(),
data: vec![], data: vec![],
kind: ParamsKind::Create
}; };
println!("address: {:?}", address); let mut ex = Executive::from_parent(self);
println!("code: {:?}", code); ex.state.inc_nonce(&address);
let mut ex = Executive::from_parent(self, params); let res = Executive::create(&mut ex, &params);
let res = ex.create();
println!("res: {:?}", res); println!("res: {:?}", res);
(address, gas) (address, gas)
} }
@ -213,12 +221,11 @@ impl<'a> Ext for Executive<'a> {
value: value.clone(), value: value.clone(),
code: self.state.code(code_address).unwrap_or(vec![]), code: self.state.code(code_address).unwrap_or(vec![]),
data: data.to_vec(), data: data.to_vec(),
kind: ParamsKind::Call
}; };
{ {
let mut ex = Executive::from_parent(self, params); let mut ex = Executive::from_parent(self);
ex.call(); Executive::call(&mut ex, &params);
unimplemented!(); unimplemented!();
} }
@ -280,7 +287,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_create(); let mut params = EvmParams::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);
@ -292,8 +299,8 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ex = Executive::new_from_params(&mut state, &info, &engine, params); let mut ex = Executive::new(&mut state, &info, &engine);
assert_eq!(ex.exec(), ExecutiveResult::Ok); assert_eq!(Executive::create(&mut ex, &params), ExecutiveResult::Ok);
} }
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0xf9u64))); assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0xf9u64)));
@ -308,7 +315,7 @@ mod tests {
let next_address = contract_address(&address, &U256::zero()); let next_address = contract_address(&address, &U256::zero());
println!("address: {:?}", address); println!("address: {:?}", address);
println!("next address: {:?}", next_address); println!("next address: {:?}", next_address);
let mut params = EvmParams::new_create(); let mut params = EvmParams::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();
@ -320,8 +327,8 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ex = Executive::new_from_params(&mut state, &info, &engine, params); let mut ex = Executive::new(&mut state, &info, &engine);
assert_eq!(ex.exec(), ExecutiveResult::Ok); assert_eq!(Executive::create(&mut ex, &params), ExecutiveResult::Ok);
} }
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(next_address.clone())); assert_eq!(state.storage_at(&address, &H256::new()), H256::from(next_address.clone()));

View File

@ -3,12 +3,8 @@
use util::hash::*; use util::hash::*;
use util::uint::*; use util::uint::*;
use util::bytes::*; use util::bytes::*;
use evm::EvmParams;
pub trait Ext { pub trait Ext {
/// Returns evm params.
fn params(&self) -> &EvmParams;
/// Returns a value for given key. /// Returns a value for given key.
fn sload(&self, key: &H256) -> H256; fn sload(&self, key: &H256) -> H256;

View File

@ -301,12 +301,11 @@ impl From<evmjit::ReturnCode> for evm::ReturnCode {
pub struct JitEvm; pub struct JitEvm;
impl evm::Evm for JitEvm { impl evm::Evm for JitEvm {
fn exec(&self, ext: &mut evm::Ext) -> evm::ReturnCode { fn exec(&self, params: &evm::EvmParams, ext: &mut evm::Ext) -> evm::ReturnCode {
// 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)) }; let ext_adapter: ExtAdapter<'static> = unsafe { ::std::mem::transmute(ExtAdapter::new(ext)) };
let mut ext_handle = evmjit::ExtHandle::new(ext_adapter); let mut ext_handle = evmjit::ExtHandle::new(ext_adapter);
let mut data = RuntimeData::new(); let mut data = RuntimeData::new();
let params = ext.params();
data.gas = params.gas; data.gas = params.gas;
data.gas_price = params.gas_price; data.gas_price = params.gas_price;
data.call_data = params.data.clone(); data.call_data = params.data.clone();
@ -315,6 +314,7 @@ impl evm::Evm for JitEvm {
data.origin = params.origin.clone(); data.origin = params.origin.clone();
data.call_value = params.value; data.call_value = params.value;
data.code = params.code.clone(); data.code = params.code.clone();
println!("params.address: {:?}, params.code: {:?}", params.address, params.code);
// TODO: // TODO:
data.coinbase = Address::new(); data.coinbase = Address::new();
@ -394,7 +394,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_create(); let mut params = EvmParams::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();
@ -404,9 +404,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -416,7 +416,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_create(); let mut params = EvmParams::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();
@ -426,9 +426,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -438,7 +438,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_create(); let mut params = EvmParams::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();
@ -448,9 +448,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -460,7 +460,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_create(); let mut params = EvmParams::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);
@ -471,9 +471,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone()); assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
@ -482,7 +482,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_create(); let mut params = EvmParams::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);
@ -494,9 +494,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone()); assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
@ -519,7 +519,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_create(); let mut params = EvmParams::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();
@ -533,9 +533,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -545,7 +545,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_create(); let mut params = EvmParams::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);
@ -557,9 +557,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10))); assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10)));
@ -568,7 +568,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_create(); let mut params = EvmParams::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();
@ -576,9 +576,9 @@ mod tests {
let mut state = State::new_temp(); let mut state = State::new_temp();
let info = EnvInfo::new(); let info = EnvInfo::new();
let engine = TestEngine::new(); let engine = TestEngine::new();
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
let logs = ext.logs(); let logs = ext.logs();
assert_eq!(logs.len(), 1); assert_eq!(logs.len(), 1);
let log = &logs[0]; let log = &logs[0];
@ -598,7 +598,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_create(); let mut params = EvmParams::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);
@ -607,9 +607,9 @@ mod tests {
let mut state = State::new_temp(); let mut state = State::new_temp();
let info = EnvInfo::new(); let info = EnvInfo::new();
let engine = TestEngine::new(); let engine = TestEngine::new();
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
let logs = ext.logs(); let logs = ext.logs();
assert_eq!(logs.len(), 1); assert_eq!(logs.len(), 1);
let log = &logs[0]; let log = &logs[0];
@ -624,7 +624,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_create(); let mut params = EvmParams::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();
@ -636,9 +636,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone())); assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone()));
@ -647,7 +647,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_create(); let mut params = EvmParams::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();
@ -660,9 +660,9 @@ mod tests {
let engine = TestEngine::new(); let engine = TestEngine::new();
{ {
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params);
let evm = JitEvm; let evm = JitEvm;
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop); assert_eq!(evm.exec(&params, &mut ext), ReturnCode::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), H256::from_str("23ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").unwrap()); assert_eq!(state.storage_at(&address, &H256::new()), H256::from_str("23ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").unwrap());

View File

@ -13,5 +13,5 @@ pub use self::evm::{Evm, ReturnCode};
pub use self::ext::{Ext}; pub use self::ext::{Ext};
pub use self::logentry::LogEntry; pub use self::logentry::LogEntry;
pub use self::vmfactory::VmFactory; pub use self::vmfactory::VmFactory;
pub use self::executive::{Executive, ExecutiveResult}; pub use self::executive::{Executive, ExecutiveResult, Externalities};
pub use self::params::{EvmParams, ParamsKind}; pub use self::params::EvmParams;

View File

@ -2,12 +2,6 @@ use util::hash::*;
use util::uint::*; use util::uint::*;
use util::bytes::*; use util::bytes::*;
#[derive(Eq, PartialEq, Clone)]
pub enum ParamsKind {
Create,
Call
}
#[derive(Clone)] #[derive(Clone)]
pub struct EvmParams { pub struct EvmParams {
pub address: Address, pub address: Address,
@ -17,12 +11,11 @@ pub struct EvmParams {
pub gas_price: U256, pub gas_price: U256,
pub value: U256, pub value: U256,
pub code: Bytes, pub code: Bytes,
pub data: Bytes, pub data: Bytes
pub kind: ParamsKind
} }
impl EvmParams { impl EvmParams {
pub fn new(kind: ParamsKind) -> EvmParams { pub fn new() -> EvmParams {
EvmParams { EvmParams {
address: Address::new(), address: Address::new(),
sender: Address::new(), sender: Address::new(),
@ -32,20 +25,6 @@ impl EvmParams {
value: U256::zero(), value: U256::zero(),
code: vec![], code: vec![],
data: vec![], data: vec![],
kind: kind
} }
} }
pub fn new_call() -> EvmParams {
EvmParams::new(ParamsKind::Call)
}
pub fn new_create() -> EvmParams {
EvmParams::new(ParamsKind::Create)
}
pub fn kind(&self) -> ParamsKind {
//TODO
ParamsKind::Create
}
} }