1#[cfg(not(feature = "std"))]2use alloc::string::{String, ToString};3use evm_core::{ExitError, ExitFatal};4#[cfg(feature = "std")]5use std::string::{String, ToString};67use crate::Weight;89#[derive(Debug, Clone)]10pub enum Error {11 Revert(String),12 Fatal(ExitFatal),13 Error(ExitError),14}1516impl<E> From<E> for Error17where18 E: ToString,19{20 fn from(e: E) -> Self {21 Self::Revert(e.to_string())22 }23}2425pub type Result<T> = core::result::Result<T, Error>;2627pub struct DispatchInfo {28 pub weight: Weight,29}3031impl From<Weight> for DispatchInfo {32 fn from(weight: Weight) -> Self {33 Self { weight }34 }35}36impl From<()> for DispatchInfo {37 fn from(_: ()) -> Self {38 Self { weight: 0 }39 }40}4142#[derive(Default, Clone)]43pub struct PostDispatchInfo {44 actual_weight: Option<Weight>,45}4647impl PostDispatchInfo {48 pub fn calc_unspent(&self, info: &DispatchInfo) -> Weight {49 info.weight - self.calc_actual_weight(info)50 }5152 pub fn calc_actual_weight(&self, info: &DispatchInfo) -> Weight {53 if let Some(actual_weight) = self.actual_weight {54 actual_weight.min(info.weight)55 } else {56 info.weight57 }58 }59}6061#[derive(Clone)]62pub struct WithPostDispatchInfo<T> {63 pub data: T,64 pub post_info: PostDispatchInfo,65}6667impl<T> From<T> for WithPostDispatchInfo<T> {68 fn from(data: T) -> Self {69 Self {70 data,71 post_info: Default::default(),72 }73 }74}7576pub type ResultWithPostInfo<T> =77 core::result::Result<WithPostDispatchInfo<T>, WithPostDispatchInfo<Error>>;