git.delta.rocks / unique-network / refs/commits / ff8cf82e5d8a

difftreelog

fix check maintenance in self-contained

Daniel Shiposha2022-11-07parent: #d1c5686.patch.diff
in: master

1 file changed

modifiedruntime/common/ethereum/self_contained_call.rsdiffbeforeafterboth
before · runtime/common/ethereum/self_contained_call.rs
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},21};22use crate::{RuntimeOrigin, RuntimeCall};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) => call.check_self_contained(),37			_ => None,38		}39	}4041	fn validate_self_contained(42		&self,43		info: &Self::SignedInfo,44		dispatch_info: &DispatchInfoOf<RuntimeCall>,45		len: usize,46	) -> Option<TransactionValidity> {47		match self {48			RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len),49			_ => None,50		}51	}5253	fn pre_dispatch_self_contained(54		&self,55		info: &Self::SignedInfo,56	) -> Option<Result<(), TransactionValidityError>> {57		match self {58			RuntimeCall::Ethereum(call) => call.pre_dispatch_self_contained(info),59			_ => None,60		}61	}6263	fn apply_self_contained(64		self,65		info: Self::SignedInfo,66	) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {67		match self {68			call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => {69				Some(call.dispatch(RuntimeOrigin::from(70					pallet_ethereum::RawOrigin::EthereumTransaction(info),71				)))72			}73			_ => None,74		}75	}76}
after · runtime/common/ethereum/self_contained_call.rs
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	) -> Option<Result<(), TransactionValidityError>> {73		match self {74			RuntimeCall::Ethereum(call) => call.pre_dispatch_self_contained(info),75			_ => None,76		}77	}7879	fn apply_self_contained(80		self,81		info: Self::SignedInfo,82	) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {83		match self {84			call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => {85				Some(call.dispatch(RuntimeOrigin::from(86					pallet_ethereum::RawOrigin::EthereumTransaction(info),87				)))88			}89			_ => None,90		}91	}92}