git.delta.rocks / unique-network / refs/commits / 258c7f483482

difftreelog

source

crates/evm-coder/src/execution.rs2.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#[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>>;