use ::{ResumeCall, ResumeCreate};
use ethereum_types::Address;
use action_params::ActionParams;
use std::fmt;
use ethtrie;
#[derive(Debug)]
pub enum TrapKind {
Call(ActionParams),
Create(ActionParams, Address),
}
pub enum TrapError<Call, Create> {
Call(ActionParams, Call),
Create(ActionParams, Address, Create),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
OutOfGas,
BadJumpDestination {
destination: usize
},
BadInstruction {
instruction: u8,
},
StackUnderflow {
instruction: &'static str,
wanted: usize,
on_stack: usize
},
OutOfStack {
instruction: &'static str,
wanted: usize,
limit: usize
},
BuiltIn(&'static str),
MutableCallInStaticContext,
Internal(String),
Wasm(String),
OutOfBounds,
Reverted,
}
impl From<Box<ethtrie::TrieError>> for Error {
fn from(err: Box<ethtrie::TrieError>) -> Self {
Error::Internal(format!("Internal error: {}", err))
}
}
impl From<ethtrie::TrieError> for Error {
fn from(err: ethtrie::TrieError) -> Self {
Error::Internal(format!("Internal error: {}", err))
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match *self {
OutOfGas => write!(f, "Out of gas"),
BadJumpDestination { destination } => write!(f, "Bad jump destination {:x}", destination),
BadInstruction { instruction } => write!(f, "Bad instruction {:x}", instruction),
StackUnderflow { instruction, wanted, on_stack } => write!(f, "Stack underflow {} {}/{}", instruction, wanted, on_stack),
OutOfStack { instruction, wanted, limit } => write!(f, "Out of stack {} {}/{}", instruction, wanted, limit),
BuiltIn(name) => write!(f, "Built-in failed: {}", name),
Internal(ref msg) => write!(f, "Internal error: {}", msg),
MutableCallInStaticContext => write!(f, "Mutable call in static context"),
Wasm(ref msg) => write!(f, "Internal error: {}", msg),
OutOfBounds => write!(f, "Out of bounds"),
Reverted => write!(f, "Reverted"),
}
}
}
pub type Result<T> = ::std::result::Result<T, Error>;
pub type TrapResult<T, Call, Create> = ::std::result::Result<Result<T>, TrapError<Call, Create>>;
pub type ExecTrapResult<T> = TrapResult<T, Box<dyn ResumeCall>, Box<dyn ResumeCreate>>;
pub type ExecTrapError = TrapError<Box<dyn ResumeCall>, Box<dyn ResumeCreate>>;