1234567891011121314151617#[cfg(not(feature = "std"))]18use alloc::string::{String, ToString};19use evm_core::{ExitError, ExitFatal};20#[cfg(feature = "std")]21use std::string::{String, ToString};2223use crate::Weight;2425#[derive(Debug, Clone)]26pub enum Error {27 Revert(String),28 Fatal(ExitFatal),29 Error(ExitError),30}3132impl<E> From<E> for Error33where34 E: ToString,35{36 fn from(e: E) -> Self {37 Self::Revert(e.to_string())38 }39}4041pub type Result<T> = core::result::Result<T, Error>;4243pub struct DispatchInfo {44 pub weight: Weight,45}4647impl From<Weight> for DispatchInfo {48 fn from(weight: Weight) -> Self {49 Self { weight }50 }51}52impl From<()> for DispatchInfo {53 fn from(_: ()) -> Self {54 Self { weight: 0 }55 }56}5758#[derive(Default, Clone)]59pub struct PostDispatchInfo {60 actual_weight: Option<Weight>,61}6263impl PostDispatchInfo {64 pub fn calc_unspent(&self, info: &DispatchInfo) -> Weight {65 info.weight - self.calc_actual_weight(info)66 }6768 pub fn calc_actual_weight(&self, info: &DispatchInfo) -> Weight {69 if let Some(actual_weight) = self.actual_weight {70 actual_weight.min(info.weight)71 } else {72 info.weight73 }74 }75}7677#[derive(Clone)]78pub struct WithPostDispatchInfo<T> {79 pub data: T,80 pub post_info: PostDispatchInfo,81}8283impl<T> From<T> for WithPostDispatchInfo<T> {84 fn from(data: T) -> Self {85 Self {86 data,87 post_info: Default::default(),88 }89 }90}9192pub type ResultWithPostInfo<T> =93 core::result::Result<WithPostDispatchInfo<T>, WithPostDispatchInfo<Error>>;