Move Executive down, remove unneeded Evm prefixes.

This commit is contained in:
Gav Wood 2016-01-11 17:01:42 +01:00
parent b0cceddb7c
commit 0cc57483f8
7 changed files with 53 additions and 59 deletions

View File

@ -2,7 +2,7 @@ use common::*;
use block::*; use block::*;
use spec::*; use spec::*;
use engine::*; use engine::*;
use evm::*; use evm::Schedule;
/// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum /// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum
/// mainnet chains in the Olympic, Frontier and Homestead eras. /// mainnet chains in the Olympic, Frontier and Homestead eras.
@ -46,7 +46,7 @@ impl Engine for Ethash {
} }
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> { fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
let min_difficulty = decode(self.spec().engine_params.get("minimumDifficulty").unwrap()); let min_difficulty = decode(self.spec().engine_params.get("minimumDifficulty").unwrap());
if header.difficulty < min_difficulty { if header.difficulty < min_difficulty {
return Err(From::from(BlockError::InvalidDifficulty(Mismatch { expected: min_difficulty, found: header.difficulty }))) return Err(From::from(BlockError::InvalidDifficulty(Mismatch { expected: min_difficulty, found: header.difficulty })))
@ -63,12 +63,12 @@ impl Engine for Ethash {
Ok(()) Ok(())
} }
fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> Result<(), Error> { fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
// TODO: Verify seal (full) // TODO: Verify seal (full)
Ok(()) Ok(())
} }
fn verify_block_final(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> Result<(), Error> { fn verify_block_final(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
// Check difficulty is correct given the two timestamps. // Check difficulty is correct given the two timestamps.
let expected_difficulty = self.calculate_difficuty(header, parent); let expected_difficulty = self.calculate_difficuty(header, parent);
if header.difficulty != expected_difficulty { if header.difficulty != expected_difficulty {
@ -83,7 +83,7 @@ impl Engine for Ethash {
Ok(()) Ok(())
} }
fn verify_transaction(&self, _t: &Transaction, _header: &Header) -> Result<(), Error> { Ok(()) } fn verify_transaction(&self, _t: &Transaction, _header: &Header) -> result::Result<(), Error> { Ok(()) }
} }
impl Ethash { impl Ethash {

View File

@ -5,7 +5,7 @@ use evm::Ext;
/// Evm errors. /// Evm errors.
#[derive(Debug)] #[derive(Debug)]
pub enum EvmError { pub enum Error {
/// `OutOfGas` is returned when transaction execution runs out of gas. /// `OutOfGas` is returned when transaction execution runs out of gas.
/// The state should be reverted to the state from before the /// The state should be reverted to the state from before the
/// transaction execution. But it does not mean that transaction /// transaction execution. But it does not mean that transaction
@ -20,10 +20,10 @@ pub enum EvmError {
/// Evm result. /// Evm result.
/// ///
/// Returns gas_left if execution is successfull, otherwise error. /// Returns gas_left if execution is successfull, otherwise error.
pub type EvmResult = Result<U256, EvmError>; pub type Result = result::Result<U256, Error>;
/// 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: &ActionParams, ext: &mut Ext) -> EvmResult; fn exec(&self, params: &ActionParams, ext: &mut Ext) -> Result;
} }

View File

@ -4,7 +4,7 @@ use util::hash::*;
use util::uint::*; use util::uint::*;
use util::bytes::*; use util::bytes::*;
use evm::Schedule; use evm::Schedule;
use evm::EvmError; use evm::Error;
// TODO: replace all u64 with u256 // TODO: replace all u64 with u256
pub trait Ext { pub trait Ext {
@ -24,13 +24,13 @@ pub trait Ext {
/// ///
/// If contract creation is successfull, return gas_left and contract address, /// If contract creation is successfull, return gas_left and contract address,
/// If depth is too big or transfer value exceeds balance, return None /// If depth is too big or transfer value exceeds balance, return None
/// Otherwise return appropriate `EvmError`. /// Otherwise return appropriate `Error`.
fn create(&mut self, gas: u64, value: &U256, code: &[u8]) -> Result<(u64, Option<Address>), EvmError>; fn create(&mut self, gas: u64, value: &U256, code: &[u8]) -> Result<(u64, Option<Address>), Error>;
/// Message call. /// Message call.
/// ///
/// If call is successfull, returns gas left. /// If call is successfull, returns gas left.
/// otherwise `EvmError`. /// otherwise `Error`.
fn call(&mut self, fn call(&mut self,
gas: u64, gas: u64,
call_gas: u64, call_gas: u64,
@ -38,7 +38,7 @@ pub trait Ext {
value: &U256, value: &U256,
data: &[u8], data: &[u8],
code_address: &Address, code_address: &Address,
output: &mut [u8]) -> Result<u64, EvmError>; output: &mut [u8]) -> Result<u64, Error>;
/// Returns code at given address /// Returns code at given address
fn extcode(&self, address: &Address) -> Vec<u8>; fn extcode(&self, address: &Address) -> Vec<u8>;
@ -48,7 +48,7 @@ pub trait Ext {
/// Should be called when transaction calls `RETURN` opcode. /// Should be called when transaction calls `RETURN` opcode.
/// Returns gas_left if cost of returning the data is not too high. /// Returns gas_left if cost of returning the data is not too high.
fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, EvmError>; fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, Error>;
/// Should be called when contract commits suicide. /// Should be called when contract commits suicide.
fn suicide(&mut self); fn suicide(&mut self);

View File

@ -1,12 +1,6 @@
//! Just in time compiler execution environment. //! Just in time compiler execution environment.
use std::mem; use common::*;
use std::ptr;
use std::slice;
use evmjit; use evmjit;
use util::hash::*;
use util::uint::*;
use util::bytes::*;
use util::sha3::*;
use evm; use evm;
/// Ethcore representation of evmjit runtime data. /// Ethcore representation of evmjit runtime data.
@ -165,11 +159,11 @@ impl IntoJit<evmjit::RuntimeDataHandle> for RuntimeData {
/// This adapter 'catches' them and moves upstream. /// This adapter 'catches' them and moves upstream.
struct ExtAdapter<'a> { struct ExtAdapter<'a> {
ext: &'a mut evm::Ext, ext: &'a mut evm::Ext,
err: &'a mut Option<evm::EvmError> err: &'a mut Option<evm::Error>
} }
impl<'a> ExtAdapter<'a> { impl<'a> ExtAdapter<'a> {
fn new(ext: &'a mut evm::Ext, err: &'a mut Option<evm::EvmError>) -> Self { fn new(ext: &'a mut evm::Ext, err: &'a mut Option<evm::Error>) -> Self {
ExtAdapter { ExtAdapter {
ext: ext, ext: ext,
err: err err: err
@ -222,7 +216,7 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
*address = addr.into_jit(); *address = addr.into_jit();
} }
}, },
Err(err @ evm::EvmError::OutOfGas) => { Err(err @ evm::Error::OutOfGas) => {
*self.err = Some(err); *self.err = Some(err);
// hack to propagate `OutOfGas` to evmjit and stop // hack to propagate `OutOfGas` to evmjit and stop
// the execution immediately. // the execution immediately.
@ -258,7 +252,7 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
*io_gas = gas_left; *io_gas = gas_left;
true true
}, },
Err(err @ evm::EvmError::OutOfGas) => { Err(err @ evm::Error::OutOfGas) => {
*self.err = Some(err); *self.err = Some(err);
// hack to propagate `OutOfGas` to evmjit and stop // hack to propagate `OutOfGas` to evmjit and stop
// the execution immediately. // the execution immediately.
@ -319,7 +313,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::ActionParams, ext: &mut evm::Ext) -> evm::EvmResult { fn exec(&self, params: &evm::ActionParams, ext: &mut evm::Ext) -> evm::Result {
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)) };
@ -357,8 +351,8 @@ impl evm::Evm for JitEvm {
ext.suicide(); ext.suicide();
Ok(U256::from(context.gas_left())) Ok(U256::from(context.gas_left()))
}, },
evmjit::ReturnCode::OutOfGas => Err(evm::EvmError::OutOfGas), evmjit::ReturnCode::OutOfGas => Err(evm::Error::OutOfGas),
_err => Err(evm::EvmError::Internal) _err => Err(evm::Error::Internal)
} }
} }
} }
@ -437,7 +431,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop); //assert_eq!(evm.exec(&params, &mut ext), Result::Stop);
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -461,7 +455,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::Stop {});
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -485,7 +479,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::Stop {});
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -510,7 +504,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::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());
@ -535,7 +529,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::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());
@ -576,7 +570,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::Stop {});
} }
assert_eq!(state.storage_at(&address, &H256::new()), assert_eq!(state.storage_at(&address, &H256::new()),
@ -602,7 +596,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::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)));
@ -624,7 +618,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::Stop {});
} }
let logs = substate.logs(); let logs = substate.logs();
assert_eq!(logs.len(), 1); assert_eq!(logs.len(), 1);
@ -659,7 +653,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::Stop {});
} }
let logs = substate.logs(); let logs = substate.logs();
assert_eq!(logs.len(), 1); assert_eq!(logs.len(), 1);
@ -691,7 +685,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::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()));
@ -717,7 +711,7 @@ mod tests {
let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract); let mut ext = Externalities::new(&mut state, &info, &engine, 0, &params, &mut substate, OutputPolicy::InitContract);
let evm = JitEvm; let evm = JitEvm;
let _res = evm.exec(&params, &mut ext); let _res = evm.exec(&params, &mut ext);
//assert_eq!(evm.exec(&params, &mut ext), EvmResult::Stop {}); //assert_eq!(evm.exec(&params, &mut ext), Result::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

@ -4,15 +4,14 @@ pub mod ext;
pub mod evm; pub mod evm;
pub mod vmfactory; pub mod vmfactory;
//pub mod logentry; //pub mod logentry;
pub mod executive;
pub mod schedule; pub mod schedule;
#[cfg(feature = "jit" )] #[cfg(feature = "jit" )]
mod jit; mod jit;
pub use self::evm::{Evm, EvmError, EvmResult}; // TODO: Error -> evm::Error, Result -> evm::Result
pub use self::ext::{Ext}; pub use self::evm::{Evm, Error, Result};
//pub use self::logentry::LogEntry; pub use self::ext::Ext;
// TODO: VmFactory -> evm::Factory
// TODO: module rename vmfactory -> factory
pub use self::vmfactory::VmFactory; pub use self::vmfactory::VmFactory;
// TODO: reduce this to absolutely necessary things
pub use self::executive::{Executive, ExecutionResult, Externalities, Substate, OutputPolicy};
pub use self::schedule::Schedule; pub use self::schedule::Schedule;

View File

@ -2,7 +2,7 @@
use common::*; use common::*;
use state::*; use state::*;
use engine::*; use engine::*;
use evm::{Schedule, VmFactory, Ext, EvmResult, EvmError}; use evm::{Schedule, VmFactory, Ext};
/// 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 {
@ -182,8 +182,8 @@ impl<'a> Executive<'a> {
/// Calls contract function with given contract params. /// Calls contract function 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 and the output. /// Modifies the substate and the output.
/// Returns either gas_left or `EvmError`. /// Returns either gas_left or `evm::Error`.
fn call(&mut self, params: &ActionParams, substate: &mut Substate, output: &mut [u8]) -> EvmResult { fn call(&mut self, params: &ActionParams, substate: &mut Substate, output: &mut [u8]) -> evm::Result {
// 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);
@ -195,7 +195,7 @@ impl<'a> Executive<'a> {
self.engine.execute_builtin(&params.address, &params.data, output); self.engine.execute_builtin(&params.address, &params.data, output);
Ok(params.gas - cost) Ok(params.gas - cost)
}, },
false => Err(EvmError::OutOfGas) false => Err(evm::Error::OutOfGas)
} }
} else if params.code.len() > 0 { } else if params.code.len() > 0 {
// if destination is a contract, do normal message call // if destination is a contract, do normal message call
@ -211,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: &ActionParams, substate: &mut Substate) -> EvmResult { fn create(&mut self, params: &ActionParams, substate: &mut Substate) -> evm::Result {
// 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
@ -223,10 +223,10 @@ impl<'a> Executive<'a> {
} }
/// Finalizes the transaction (does refunds and suicides). /// Finalizes the transaction (does refunds and suicides).
fn finalize(&mut self, t: &Transaction, substate: Substate, backup: State, result: EvmResult) -> ExecutionResult { fn finalize(&mut self, t: &Transaction, substate: Substate, backup: State, result: evm::Result) -> ExecutionResult {
match result { match result {
Err(EvmError::Internal) => Err(ExecutionError::Internal), Err(evm::Error::Internal) => Err(ExecutionError::Internal),
Err(EvmError::OutOfGas) => { Err(evm::Error::OutOfGas) => {
*self.state = backup; *self.state = backup;
Err(ExecutionError::OutOfGas) Err(ExecutionError::OutOfGas)
}, },
@ -341,7 +341,7 @@ impl<'a> Ext for Externalities<'a> {
} }
} }
fn create(&mut self, gas: u64, value: &U256, code: &[u8]) -> Result<(u64, Option<Address>), EvmError> { fn create(&mut self, gas: u64, value: &U256, code: &[u8]) -> Result<(u64, Option<Address>), evm::Error> {
// if balance is insufficient or we are to deep, return // if balance is insufficient or we are to deep, return
if self.state.balance(&self.params.address) < *value && self.depth >= 1024 { if self.state.balance(&self.params.address) < *value && self.depth >= 1024 {
return Ok((gas, None)); return Ok((gas, None));
@ -367,7 +367,7 @@ impl<'a> Ext for Externalities<'a> {
ex.create(&params, self.substate).map(|gas_left| (gas_left.low_u64(), Some(address))) ex.create(&params, self.substate).map(|gas_left| (gas_left.low_u64(), Some(address)))
} }
fn call(&mut self, gas: u64, call_gas: u64, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address, output: &mut [u8]) -> Result<u64, EvmError> { fn call(&mut self, gas: u64, call_gas: u64, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address, output: &mut [u8]) -> Result<u64, evm::Error> {
let mut gas_cost = call_gas; let mut gas_cost = call_gas;
let mut call_gas = call_gas; let mut call_gas = call_gas;
@ -383,7 +383,7 @@ impl<'a> Ext for Externalities<'a> {
} }
if gas_cost > gas { if gas_cost > gas {
return Err(EvmError::OutOfGas) return Err(evm::Error::OutOfGas)
} }
let gas = gas - gas_cost; let gas = gas - gas_cost;
@ -413,7 +413,7 @@ impl<'a> Ext for Externalities<'a> {
self.state.code(address).unwrap_or(vec![]) self.state.code(address).unwrap_or(vec![])
} }
fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, EvmError> { fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, evm::Error> {
match &mut self.output { match &mut self.output {
&mut OutputPolicy::Return(ref mut slice) => unsafe { &mut OutputPolicy::Return(ref mut slice) => unsafe {
let len = cmp::min(slice.len(), data.len()); let len = cmp::min(slice.len(), data.len());
@ -423,7 +423,7 @@ impl<'a> Ext for Externalities<'a> {
&mut OutputPolicy::InitContract => { &mut OutputPolicy::InitContract => {
let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64; let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64;
if return_cost > gas { if return_cost > gas {
return Err(EvmError::OutOfGas); return Err(evm::Error::OutOfGas);
} }
let mut code = vec![]; let mut code = vec![];
code.reserve(data.len()); code.reserve(data.len());

View File

@ -1,5 +1,6 @@
use common::*; use common::*;
use engine::Engine; use engine::Engine;
//use executive::Executive;
/// Information concerning the result of the `State::apply` operation. /// Information concerning the result of the `State::apply` operation.
pub struct ApplyInfo { pub struct ApplyInfo {
@ -134,7 +135,7 @@ impl State {
/// Execute a given transaction. /// Execute a given transaction.
/// This will change the state accordingly. /// This will change the state accordingly.
pub fn apply(&mut self, _env_info: &EnvInfo, _engine: &Engine, _t: &Transaction) -> ApplyResult { pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &Transaction) -> ApplyResult {
unimplemented!(); unimplemented!();
} }