2015-12-30 12:46:10 +01:00
|
|
|
//! Evm interface.
|
2015-12-28 22:37:15 +01:00
|
|
|
|
2016-01-10 16:21:01 +01:00
|
|
|
use util::uint::U256;
|
2016-01-09 17:55:47 +01:00
|
|
|
use evm::{EvmParams, Ext};
|
2015-12-28 22:37:15 +01:00
|
|
|
|
2016-01-11 02:17:29 +01:00
|
|
|
/// Evm errors.
|
|
|
|
pub enum EvmError {
|
2016-01-11 03:13:41 +01:00
|
|
|
/// `OutOfGas` is returned when transaction execution runs out of gas.
|
2016-01-11 02:17:29 +01:00
|
|
|
/// The state should be reverted to the state from before the
|
|
|
|
/// transaction execution. But it does not mean that transaction
|
|
|
|
/// was invalid. Balance still should be transfered and nonce
|
|
|
|
/// should be increased.
|
2015-12-28 22:37:15 +01:00
|
|
|
OutOfGas,
|
2016-01-11 02:17:29 +01:00
|
|
|
/// Returned on evm internal error. Should never be ignored during development.
|
|
|
|
/// Likely to cause consensus issues.
|
|
|
|
Internal,
|
2015-12-28 22:37:15 +01:00
|
|
|
}
|
|
|
|
|
2016-01-11 02:17:29 +01:00
|
|
|
/// Evm result.
|
|
|
|
///
|
|
|
|
/// Returns gas_left if execution is successfull, otherwise error.
|
|
|
|
pub type EvmResult = Result<U256, EvmError>;
|
|
|
|
|
|
|
|
/// Evm interface.
|
2015-12-28 22:37:15 +01:00
|
|
|
pub trait Evm {
|
2016-01-11 02:17:29 +01:00
|
|
|
/// This function should be used to execute transaction.
|
2016-01-09 18:25:18 +01:00
|
|
|
fn exec(&self, params: &EvmParams, ext: &mut Ext) -> EvmResult;
|
2015-12-28 22:37:15 +01:00
|
|
|
}
|