#![cfg_attr(not(feature = "std"), no_std)]
use bitflags::bitflags;
use codec::{Decode, Encode};
use sp_runtime::{DispatchError, RuntimeDebug};
use sp_std::prelude::*;
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub struct ContractExecResult {
pub exec_result: ExecResult,
pub gas_consumed: u64,
}
pub type GetStorageResult = Result<Option<Vec<u8>>, ContractAccessError>;
pub type RentProjectionResult<BlockNumber> =
Result<RentProjection<BlockNumber>, ContractAccessError>;
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub enum ContractAccessError {
DoesntExist,
IsTombstone,
}
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub enum RentProjection<BlockNumber> {
EvictionAt(BlockNumber),
NoEviction,
}
bitflags! {
#[derive(Encode, Decode)]
pub struct ReturnFlags: u32 {
const REVERT = 0x0000_0001;
}
}
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug)]
pub struct ExecReturnValue {
pub flags: ReturnFlags,
pub data: Vec<u8>,
}
impl ExecReturnValue {
pub fn is_success(&self) -> bool {
!self.flags.contains(ReturnFlags::REVERT)
}
}
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug)]
pub enum ErrorOrigin {
Caller,
Callee,
}
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug)]
pub struct ExecError {
pub error: DispatchError,
pub origin: ErrorOrigin,
}
impl<T: Into<DispatchError>> From<T> for ExecError {
fn from(error: T) -> Self {
Self {
error: error.into(),
origin: ErrorOrigin::Caller,
}
}
}
pub type ExecResult = Result<ExecReturnValue, ExecError>;