git.delta.rocks / unique-network / refs/commits / 5ef5e6b4aa6d

difftreelog

source

runtime/common/ethereum/self_contained_call.rs2.6 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/>.1617use sp_core::H160;18use sp_runtime::{19	traits::{Dispatchable, DispatchInfoOf, PostDispatchInfoOf},20	transaction_validity::{TransactionValidityError, TransactionValidity, InvalidTransaction},21};22use crate::{RuntimeOrigin, RuntimeCall, Maintenance};2324impl fp_self_contained::SelfContainedCall for RuntimeCall {25	type SignedInfo = H160;2627	fn is_self_contained(&self) -> bool {28		match self {29			RuntimeCall::Ethereum(call) => call.is_self_contained(),30			_ => false,31		}32	}3334	fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {35		match self {36			RuntimeCall::Ethereum(call) => {37				if Maintenance::is_enabled() {38					Some(Err(TransactionValidityError::Invalid(39						InvalidTransaction::Call,40					)))41				} else {42					call.check_self_contained()43				}44			}45			_ => None,46		}47	}4849	fn validate_self_contained(50		&self,51		info: &Self::SignedInfo,52		dispatch_info: &DispatchInfoOf<RuntimeCall>,53		len: usize,54	) -> Option<TransactionValidity> {55		match self {56			RuntimeCall::Ethereum(call) => {57				if Maintenance::is_enabled() {58					Some(Err(TransactionValidityError::Invalid(59						InvalidTransaction::Call,60					)))61				} else {62					call.validate_self_contained(info, dispatch_info, len)63				}64			}65			_ => None,66		}67	}6869	fn pre_dispatch_self_contained(70		&self,71		info: &Self::SignedInfo,72		dispatch_info: &DispatchInfoOf<RuntimeCall>,73		len: usize,74	) -> Option<Result<(), TransactionValidityError>> {75		match self {76			RuntimeCall::Ethereum(call) => {77				call.pre_dispatch_self_contained(info, dispatch_info, len)78			}79			_ => None,80		}81	}8283	fn apply_self_contained(84		self,85		info: Self::SignedInfo,86	) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {87		match self {88			call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => {89				Some(call.dispatch(RuntimeOrigin::from(90					pallet_ethereum::RawOrigin::EthereumTransaction(info),91				)))92			}93			_ => None,94		}95	}96}