git.delta.rocks / unique-network / refs/commits / 347f218123fd

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::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf},20	transaction_validity::{InvalidTransaction, TransactionValidity, TransactionValidityError},21};2223use crate::{Maintenance, RuntimeCall, RuntimeOrigin};2425impl fp_self_contained::SelfContainedCall for RuntimeCall {26	type SignedInfo = H160;2728	fn is_self_contained(&self) -> bool {29		match self {30			RuntimeCall::Ethereum(call) => call.is_self_contained(),31			_ => false,32		}33	}3435	fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {36		match self {37			RuntimeCall::Ethereum(call) => {38				if Maintenance::is_enabled() {39					Some(Err(TransactionValidityError::Invalid(40						InvalidTransaction::Call,41					)))42				} else {43					call.check_self_contained()44				}45			}46			_ => None,47		}48	}4950	fn validate_self_contained(51		&self,52		info: &Self::SignedInfo,53		dispatch_info: &DispatchInfoOf<RuntimeCall>,54		len: usize,55	) -> Option<TransactionValidity> {56		match self {57			RuntimeCall::Ethereum(call) => {58				if Maintenance::is_enabled() {59					Some(Err(TransactionValidityError::Invalid(60						InvalidTransaction::Call,61					)))62				} else {63					call.validate_self_contained(info, dispatch_info, len)64				}65			}66			_ => None,67		}68	}6970	fn pre_dispatch_self_contained(71		&self,72		info: &Self::SignedInfo,73		dispatch_info: &DispatchInfoOf<RuntimeCall>,74		len: usize,75	) -> Option<Result<(), TransactionValidityError>> {76		match self {77			RuntimeCall::Ethereum(call) => {78				call.pre_dispatch_self_contained(info, dispatch_info, len)79			}80			_ => None,81		}82	}8384	fn apply_self_contained(85		self,86		info: Self::SignedInfo,87	) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {88		match self {89			call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => {90				Some(call.dispatch(RuntimeOrigin::from(91					pallet_ethereum::RawOrigin::EthereumTransaction(info),92				)))93			}94			_ => None,95		}96	}97}