git.delta.rocks / unique-network / refs/commits / 59b04441b9eb

difftreelog

source

runtime/common/maintenance.rs4.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/>.1617use scale_info::TypeInfo;18use codec::{Encode, Decode};19use up_common::types::AccountId;20use crate::{RuntimeCall, Maintenance, VERSION};2122use sp_runtime::{23	traits::{DispatchInfoOf, SignedExtension},24	transaction_validity::{25		TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,26	},27};2829#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]30pub struct CheckMaintenance;3132impl SignedExtension for CheckMaintenance {33	type AccountId = AccountId;34	type Call = RuntimeCall;35	type AdditionalSigned = ();36	type Pre = ();3738	const IDENTIFIER: &'static str = "CheckMaintenance";3940	fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {41		Ok(())42	}4344	fn pre_dispatch(45		self,46		who: &Self::AccountId,47		call: &Self::Call,48		info: &DispatchInfoOf<Self::Call>,49		len: usize,50	) -> Result<Self::Pre, TransactionValidityError> {51		self.validate(who, call, info, len).map(|_| ())52	}5354	fn validate(55		&self,56		_who: &Self::AccountId,57		call: &Self::Call,58		_info: &DispatchInfoOf<Self::Call>,59		_len: usize,60	) -> TransactionValidity {61		if Maintenance::is_enabled() {62			match call {63				RuntimeCall::EvmMigration(_)64				| RuntimeCall::EVM(_)65				| RuntimeCall::Ethereum(_)66				| RuntimeCall::Inflation(_)67				| RuntimeCall::Structure(_)68				| RuntimeCall::Unique(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),6970				RuntimeCall::Balances(_) if VERSION.spec_version == 942057 => {71					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))72				}7374				RuntimeCall::PolkadotXcm(75					pallet_xcm::Call::execute { .. }76					| pallet_xcm::Call::teleport_assets { .. }77					| pallet_xcm::Call::reserve_transfer_assets { .. }78					| pallet_xcm::Call::limited_reserve_transfer_assets { .. }79					| pallet_xcm::Call::limited_teleport_assets { .. },80				) if VERSION.spec_version == 942057 => {81					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))82				}8384				#[cfg(feature = "scheduler")]85				RuntimeCall::Scheduler(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),8687				#[cfg(feature = "app-promotion")]88				RuntimeCall::AppPromotion(_) => {89					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))90				}9192				#[cfg(feature = "foreign-assets")]93				RuntimeCall::ForeignAssets(_) => {94					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))95				}9697				#[cfg(feature = "collator-selection")]98				RuntimeCall::CollatorSelection(_)99				| RuntimeCall::Session(_)100				| RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),101102				#[cfg(feature = "pallet-test-utils")]103				RuntimeCall::TestUtils(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),104105				_ => Ok(ValidTransaction::default()),106			}107		} else {108			Ok(ValidTransaction::default())109		}110	}111112	fn pre_dispatch_unsigned(113		call: &Self::Call,114		info: &DispatchInfoOf<Self::Call>,115		len: usize,116	) -> Result<(), TransactionValidityError> {117		Self::validate_unsigned(call, info, len).map(|_| ())118	}119120	fn validate_unsigned(121		call: &Self::Call,122		_info: &DispatchInfoOf<Self::Call>,123		_len: usize,124	) -> TransactionValidity {125		if Maintenance::is_enabled() {126			match call {127				RuntimeCall::EVM(_) | RuntimeCall::Ethereum(_) | RuntimeCall::EvmMigration(_) => {128					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))129				}130				_ => Ok(ValidTransaction::default()),131			}132		} else {133			Ok(ValidTransaction::default())134		}135	}136}