use pchain_types::blockchain::ExitStatus;
use crate::contract::{FuncError, MethodCallError};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TransitionError {
WrongNonce,
NotEnoughBalanceForGasLimit,
NotEnoughBalanceForTransfer,
PreExecutionGasExhausted,
DisallowedOpcode,
CannotCompile,
NoExportedContractMethod,
OtherDeployError,
ContractAlreadyExists,
NoContractcode,
InvalidCBI,
ExecutionProperGasExhausted,
RuntimeError,
InternalExecutionProperGasExhaustion,
InternalRuntimeError,
PoolAlreadyExists,
PoolNotExists,
PoolHasNoStakes,
InvalidPoolPolicy,
DepositsAlreadyExists,
DepositsNotExists,
InvalidDepositPolicy,
InvalidStakeAmount,
InvalidCommands,
InvalidNextEpochCommand,
}
impl From<MethodCallError> for TransitionError {
fn from(call_error: MethodCallError) -> Self {
match call_error {
MethodCallError::GasExhaustion => TransitionError::ExecutionProperGasExhausted,
MethodCallError::NoExportedMethod(_) => TransitionError::RuntimeError,
MethodCallError::Runtime(e) => {
match e.downcast::<FuncError>() {
Err(_) => TransitionError::RuntimeError,
Ok(FuncError::GasExhaustionError) => {
TransitionError::ExecutionProperGasExhausted
}
Ok(_) => TransitionError::InternalRuntimeError,
}
}
}
}
}
impl<'a> From<&'a TransitionError> for ExitStatus {
fn from(value: &'a TransitionError) -> Self {
match value {
TransitionError::ExecutionProperGasExhausted
| TransitionError::InternalExecutionProperGasExhaustion => ExitStatus::GasExhausted,
_ => ExitStatus::Failed,
}
}
}