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

difftreelog

fix make pallets build on 0.9.42

Yaroslav Bolyukin2023-05-22parent: #09fadf7.patch.diff
in: master

9 files changed

modifiedpallets/app-promotion/Cargo.tomldiffbeforeafterboth
--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -48,7 +48,7 @@
 frame-benchmarking = { workspace = true, optional = true }
 frame-support = { workspace = true }
 frame-system = { workspace = true }
-pallet-balances = { workspace = true }
+pallet-balances = { features = ["insecure_zero_ed"], workspace = true }
 pallet-evm = { workspace = true }
 sp-core = { workspace = true }
 sp-runtime = { workspace = true }
modifiedpallets/collator-selection/Cargo.tomldiffbeforeafterboth
--- a/pallets/collator-selection/Cargo.toml
+++ b/pallets/collator-selection/Cargo.toml
@@ -33,7 +33,7 @@
 
 [dev-dependencies]
 pallet-aura = { workspace = true }
-pallet-balances = { workspace = true }
+pallet-balances = { features = ["insecure_zero_ed"], workspace = true }
 pallet-timestamp = { workspace = true }
 sp-consensus-aura = { workspace = true }
 sp-core = { workspace = true }
modifiedpallets/foreign-assets/Cargo.tomldiffbeforeafterboth
--- a/pallets/foreign-assets/Cargo.toml
+++ b/pallets/foreign-assets/Cargo.toml
@@ -15,7 +15,7 @@
 frame-system = { workspace = true }
 log = { workspace = true }
 orml-tokens = { workspace = true }
-pallet-balances = { workspace = true }
+pallet-balances = { features = ["insecure_zero_ed"], workspace = true }
 pallet-common = { workspace = true }
 pallet-fungible = { workspace = true }
 serde = { workspace = true, optional = true }
modifiedpallets/foreign-assets/src/impl_fungibles.rsdiffbeforeafterboth
--- a/pallets/foreign-assets/src/impl_fungibles.rs
+++ b/pallets/foreign-assets/src/impl_fungibles.rs
@@ -19,7 +19,9 @@
 use super::*;
 use frame_system::Config as SystemConfig;
 
-use frame_support::traits::tokens::{DepositConsequence, WithdrawConsequence};
+use frame_support::traits::tokens::{
+	DepositConsequence, WithdrawConsequence, Preservation, Fortitude, Provenance, Precision,
+};
 use pallet_common::CollectionHandle;
 use pallet_fungible::FungibleHandle;
 use pallet_common::CommonCollectionOperations;
@@ -118,17 +120,24 @@
 		}
 	}
 
+	fn total_balance(asset: Self::AssetId, who: &<T as SystemConfig>::AccountId) -> Self::Balance {
+		Self::balance(asset, who)
+	}
+
 	fn reducible_balance(
 		asset: Self::AssetId,
 		who: &<T as SystemConfig>::AccountId,
-		keep_alive: bool,
+		preservation: Preservation,
+		fortitude: Fortitude,
 	) -> Self::Balance {
 		log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible reducible_balance");
 
 		match asset {
 			AssetIds::NativeAssetId(NativeCurrency::Here) => {
 				<pallet_balances::Pallet<T> as fungible::Inspect<T::AccountId>>::reducible_balance(
-					who, keep_alive,
+					who,
+					preservation,
+					fortitude,
 				)
 				.into()
 			}
@@ -136,7 +145,8 @@
 				<orml_tokens::Pallet<T> as fungibles::Inspect<T::AccountId>>::reducible_balance(
 					AssetIds::NativeAssetId(NativeCurrency::Parent),
 					who,
-					keep_alive,
+					preservation,
+					fortitude,
 				)
 				.into()
 			}
@@ -148,7 +158,7 @@
 		asset: Self::AssetId,
 		who: &<T as SystemConfig>::AccountId,
 		amount: Self::Balance,
-		mint: bool,
+		provenance: Provenance,
 	) -> DepositConsequence {
 		log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible can_deposit");
 
@@ -157,7 +167,7 @@
 				<pallet_balances::Pallet<T> as fungible::Inspect<T::AccountId>>::can_deposit(
 					who,
 					amount.into(),
-					mint,
+					provenance,
 				)
 			}
 			AssetIds::NativeAssetId(NativeCurrency::Parent) => {
@@ -165,7 +175,7 @@
 					AssetIds::NativeAssetId(NativeCurrency::Parent),
 					who,
 					amount.into(),
-					mint,
+					provenance,
 				)
 			}
 			_ => {
@@ -220,14 +230,14 @@
 					who,
 					this_amount,
 				) {
-					WithdrawConsequence::NoFunds => WithdrawConsequence::NoFunds,
+					WithdrawConsequence::BalanceLow => WithdrawConsequence::BalanceLow,
 					WithdrawConsequence::WouldDie => WithdrawConsequence::WouldDie,
 					WithdrawConsequence::UnknownAsset => WithdrawConsequence::UnknownAsset,
 					WithdrawConsequence::Underflow => WithdrawConsequence::Underflow,
 					WithdrawConsequence::Overflow => WithdrawConsequence::Overflow,
 					WithdrawConsequence::Frozen => WithdrawConsequence::Frozen,
 					WithdrawConsequence::Success => WithdrawConsequence::Success,
-					_ => WithdrawConsequence::NoFunds,
+					_ => WithdrawConsequence::BalanceLow,
 				}
 			}
 			AssetIds::NativeAssetId(NativeCurrency::Parent) => {
@@ -242,19 +252,19 @@
 					who,
 					parent_amount,
 				) {
-					WithdrawConsequence::NoFunds => WithdrawConsequence::NoFunds,
+					WithdrawConsequence::BalanceLow => WithdrawConsequence::BalanceLow,
 					WithdrawConsequence::WouldDie => WithdrawConsequence::WouldDie,
 					WithdrawConsequence::UnknownAsset => WithdrawConsequence::UnknownAsset,
 					WithdrawConsequence::Underflow => WithdrawConsequence::Underflow,
 					WithdrawConsequence::Overflow => WithdrawConsequence::Overflow,
 					WithdrawConsequence::Frozen => WithdrawConsequence::Frozen,
 					WithdrawConsequence::Success => WithdrawConsequence::Success,
-					_ => WithdrawConsequence::NoFunds,
+					_ => WithdrawConsequence::BalanceLow,
 				}
 			}
 			_ => match Self::balance(asset, who).checked_sub(&amount) {
 				Some(_) => WithdrawConsequence::Success,
-				None => WithdrawConsequence::NoFunds,
+				None => WithdrawConsequence::BalanceLow,
 			},
 		}
 	}
@@ -280,7 +290,7 @@
 		asset: Self::AssetId,
 		who: &<T as SystemConfig>::AccountId,
 		amount: Self::Balance,
-	) -> DispatchResult {
+	) -> Result<BalanceOf<T>, DispatchError> {
 		//Self::do_mint(asset, who, amount, None)
 		log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible mint_into {:?}", asset);
 
@@ -290,7 +300,7 @@
 					who,
 					amount.into(),
 				)
-				.into()
+				.map(Into::into)
 			}
 			AssetIds::NativeAssetId(NativeCurrency::Parent) => {
 				<orml_tokens::Pallet<T> as fungibles::Mutate<T::AccountId>>::mint_into(
@@ -298,7 +308,7 @@
 					who,
 					amount.into(),
 				)
-				.into()
+				.map(Into::into)
 			}
 			AssetIds::ForeignAssetId(fid) => {
 				let target_collection_id = match <AssetBinding<T>>::get(fid) {
@@ -323,7 +333,7 @@
 					&Value::new(0),
 				)?;
 
-				Ok(())
+				Ok(amount.into())
 			}
 		}
 	}
@@ -332,29 +342,31 @@
 		asset: Self::AssetId,
 		who: &<T as SystemConfig>::AccountId,
 		amount: Self::Balance,
+		precision: Precision,
+		fortitude: Fortitude,
 	) -> Result<Self::Balance, DispatchError> {
 		// let f = DebitFlags { keep_alive: false, best_effort: false };
 		log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible burn_from");
 
 		match asset {
 			AssetIds::NativeAssetId(NativeCurrency::Here) => {
-				match <pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::burn_from(
+				<pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::burn_from(
 					who,
 					amount.into(),
-				) {
-					Ok(v) => Ok(v.into()),
-					Err(e) => Err(e),
-				}
+					precision,
+					fortitude,
+				)
+				.map(Into::into)
 			}
 			AssetIds::NativeAssetId(NativeCurrency::Parent) => {
-				match <orml_tokens::Pallet<T> as fungibles::Mutate<T::AccountId>>::burn_from(
+				<orml_tokens::Pallet<T> as fungibles::Mutate<T::AccountId>>::burn_from(
 					AssetIds::NativeAssetId(NativeCurrency::Parent),
 					who,
 					amount.into(),
-				) {
-					Ok(v) => Ok(v.into()),
-					Err(e) => Err(e),
-				}
+					precision,
+					fortitude,
+				)
+				.map(Into::into)
 			}
 			AssetIds::ForeignAssetId(fid) => {
 				let target_collection_id = match <AssetBinding<T>>::get(fid) {
@@ -376,45 +388,25 @@
 				Ok(amount)
 			}
 		}
-	}
-
-	fn slash(
-		asset: Self::AssetId,
-		who: &<T as SystemConfig>::AccountId,
-		amount: Self::Balance,
-	) -> Result<Self::Balance, DispatchError> {
-		// let f = DebitFlags { keep_alive: false, best_effort: true };
-		log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible slash");
-		Ok(Self::burn_from(asset, who, amount)?)
 	}
-}
 
-impl<T: Config> fungibles::Transfer<T::AccountId> for Pallet<T>
-where
-	T: orml_tokens::Config<CurrencyId = AssetIds>,
-	BalanceOf<T>: From<<T as pallet_balances::Config>::Balance>,
-	BalanceOf<T>: From<<T as orml_tokens::Config>::Balance>,
-	<T as pallet_balances::Config>::Balance: From<BalanceOf<T>>,
-	<T as orml_tokens::Config>::Balance: From<BalanceOf<T>>,
-	u128: From<BalanceOf<T>>,
-{
 	fn transfer(
 		asset: Self::AssetId,
 		source: &<T as SystemConfig>::AccountId,
 		dest: &<T as SystemConfig>::AccountId,
 		amount: Self::Balance,
-		keep_alive: bool,
+		preservation: Preservation,
 	) -> Result<Self::Balance, DispatchError> {
 		// let f = TransferFlags { keep_alive, best_effort: false, burn_dust: false };
 		log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible transfer");
 
 		match asset {
 			AssetIds::NativeAssetId(NativeCurrency::Here) => {
-				match <pallet_balances::Pallet<T> as fungible::Transfer<T::AccountId>>::transfer(
+				match <pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::transfer(
 					source,
 					dest,
 					amount.into(),
-					keep_alive,
+					preservation,
 				) {
 					Ok(_) => Ok(amount),
 					Err(_) => Err(DispatchError::Other(
@@ -423,12 +415,12 @@
 				}
 			}
 			AssetIds::NativeAssetId(NativeCurrency::Parent) => {
-				match <orml_tokens::Pallet<T> as fungibles::Transfer<T::AccountId>>::transfer(
+				match <orml_tokens::Pallet<T> as fungibles::Mutate<T::AccountId>>::transfer(
 					AssetIds::NativeAssetId(NativeCurrency::Parent),
 					source,
 					dest,
 					amount.into(),
-					keep_alive,
+					preservation,
 				) {
 					Ok(_) => Ok(amount),
 					Err(e) => Err(e),
@@ -460,3 +452,51 @@
 		}
 	}
 }
+
+#[cfg(not(debug_assertions))]
+extern "C" {
+	// This function does not exists, thus compilation will fail, if its call is
+	// not optimized away, which is only possible if it's not called at all.
+	//
+	// not(debug_assertions) is used to ensure compiler is dropping unused functions, as
+	// this option is enabled in release by defailt
+	//
+	// FIXME: maybe use build.rs, to ensure it will fail even in release with debug_assertions
+	// enabled?
+	fn unbalanced_fungible_is_called();
+}
+macro_rules! ensure_balanced {
+	() => {{
+		#[cfg(debug_assertions)]
+		panic!("unbalanced fungible methods should not be used");
+		#[cfg(not(debug_assertions))]
+		{
+			unsafe { unbalanced_fungible_is_called() };
+			unreachable!();
+		}
+	}};
+}
+
+impl<T: Config> fungibles::Unbalanced<<T as SystemConfig>::AccountId> for Pallet<T>
+where
+	T: orml_tokens::Config<CurrencyId = AssetIds>,
+	BalanceOf<T>: From<<T as pallet_balances::Config>::Balance>,
+	BalanceOf<T>: From<<T as orml_tokens::Config>::Balance>,
+	<T as pallet_balances::Config>::Balance: From<BalanceOf<T>>,
+	<T as orml_tokens::Config>::Balance: From<BalanceOf<T>>,
+	u128: From<BalanceOf<T>>,
+{
+	fn handle_dust(_dust: fungibles::Dust<<T as SystemConfig>::AccountId, Self>) {
+		ensure_balanced!();
+	}
+	fn write_balance(
+		_asset: Self::AssetId,
+		_who: &<T as SystemConfig>::AccountId,
+		_amount: Self::Balance,
+	) -> Result<Option<Self::Balance>, DispatchError> {
+		ensure_balanced!();
+	}
+	fn set_total_issuance(_asset: Self::AssetId, _amount: Self::Balance) {
+		ensure_balanced!();
+	}
+}
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -448,9 +448,7 @@
 
 pub use frame_support::{
 	traits::{
-		fungibles::{Balanced, CreditOf},
-		tokens::currency::Currency as CurrencyT,
-		OnUnbalanced as OnUnbalancedT,
+		fungibles::Balanced, tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT,
 	},
 	weights::{WeightToFeePolynomial, WeightToFee},
 };
modifiedpallets/identity/Cargo.tomldiffbeforeafterboth
--- a/pallets/identity/Cargo.toml
+++ b/pallets/identity/Cargo.toml
@@ -26,7 +26,7 @@
 sp-std = { workspace = true }
 
 [dev-dependencies]
-pallet-balances = { workspace = true }
+pallet-balances = { features = ["insecure_zero_ed"], workspace = true }
 sp-core = { workspace = true }
 
 [features]
modifiedpallets/inflation/Cargo.tomldiffbeforeafterboth
--- a/pallets/inflation/Cargo.toml
+++ b/pallets/inflation/Cargo.toml
@@ -37,7 +37,7 @@
 frame-benchmarking = { workspace = true, optional = true }
 frame-support = { workspace = true }
 frame-system = { workspace = true }
-pallet-balances = { workspace = true }
+pallet-balances = { features = ["insecure_zero_ed"], workspace = true }
 sp-core = { workspace = true }
 sp-io = { workspace = true }
 sp-runtime = { workspace = true }
modifiedruntime/common/config/xcm/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/xcm/mod.rs
+++ b/runtime/common/config/xcm/mod.rs
@@ -114,12 +114,26 @@
 );
 
 pub trait TryPass {
+<<<<<<< HEAD
 	fn try_pass<Call>(origin: &MultiLocation, message: &mut [Instruction<Call>]) -> Result<(), ()>;
+=======
+	fn try_pass<Call>(
+		origin: &MultiLocation,
+		message: &mut [Instruction<Call>],
+	) -> Result<(), ProcessMessageError>;
+>>>>>>> fd33b0ac (fixup pallets)
 }
 
 #[impl_trait_for_tuples::impl_for_tuples(30)]
 impl TryPass for Tuple {
+<<<<<<< HEAD
 	fn try_pass<Call>(origin: &MultiLocation, message: &mut [Instruction<Call>]) -> Result<(), ()> {
+=======
+	fn try_pass<Call>(
+		origin: &MultiLocation,
+		message: &mut [Instruction<Call>],
+	) -> Result<(), ProcessMessageError> {
+>>>>>>> fd33b0ac (fixup pallets)
 		for_tuples!( #(
 			Tuple::try_pass(origin, message)?;
 		)* );
modifiedtest-pallets/utils/src/lib.rsdiffbeforeafterboth
before · test-pallets/utils/src/lib.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;20use frame_support::pallet_prelude::*;21use frame_system::pallet_prelude::*;2223#[frame_support::pallet]24pub mod pallet {25	use frame_support::{26		pallet_prelude::*,27		dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},28		traits::{UnfilteredDispatchable, IsSubType, OriginTrait},29	};30	use frame_system::pallet_prelude::*;31	use sp_std::vec::Vec;32	// use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};3334	#[pallet::config]35	pub trait Config: frame_system::Config /*+ pallet_unique_scheduler_v2::Config*/ {36		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;3738		/// The overarching call type.39		type RuntimeCall: Parameter40			+ Dispatchable<41				RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin,42				PostInfo = PostDispatchInfo,43			> + GetDispatchInfo44			+ From<frame_system::Call<Self>>45			+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>46			+ IsSubType<Call<Self>>47			+ IsType<<Self as frame_system::Config>::RuntimeCall>;48	}4950	#[pallet::event]51	#[pallet::generate_deposit(pub(super) fn deposit_event)]52	pub enum Event<T: Config> {53		ValueIsSet,54		ShouldRollback,55		BatchCompleted,56	}5758	#[pallet::pallet]59	pub struct Pallet<T>(_);6061	#[pallet::storage]62	#[pallet::getter(fn is_enabled)]63	pub type Enabled<T> = StorageValue<_, bool, ValueQuery>;6465	#[pallet::storage]66	#[pallet::getter(fn test_value)]67	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;6869	#[pallet::error]70	pub enum Error<T> {71		TestPalletDisabled,72		TriggerRollback,73	}7475	#[pallet::call]76	impl<T: Config> Pallet<T> {77		#[pallet::call_index(0)]78		#[pallet::weight(10_000)]79		pub fn enable(origin: OriginFor<T>) -> DispatchResult {80			ensure_root(origin)?;81			<Enabled<T>>::set(true);8283			Ok(())84		}8586		#[pallet::call_index(1)]87		#[pallet::weight(10_000)]88		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {89			Self::ensure_origin_and_enabled(origin)?;9091			<TestValue<T>>::put(value);9293			Self::deposit_event(Event::ValueIsSet);9495			Ok(())96		}9798		#[pallet::call_index(2)]99		#[pallet::weight(10_000)]100		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {101			Self::set_test_value(origin, value)?;102103			Self::deposit_event(Event::ShouldRollback);104105			Err(<Error<T>>::TriggerRollback.into())106		}107108		#[pallet::call_index(3)]109		#[pallet::weight(10_000)]110		pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {111			Self::set_test_value(origin, <TestValue<T>>::get() + 1)112		}113114		// #[pallet::weight(10_000)]115		// pub fn self_canceling_inc(116		// 	origin: OriginFor<T>,117		// 	id: TaskName,118		// 	max_test_value: u32,119		// ) -> DispatchResult {120		// 	Self::ensure_origin_and_enabled(origin.clone())?;121		// 	Self::inc_test_value(origin.clone())?;122123		// 	if <TestValue<T>>::get() == max_test_value {124		// 		SchedulerPallet::<T>::cancel_named(origin, id)?;125		// 	}126127		// 	Ok(())128		// }129130		#[pallet::call_index(4)]131		#[pallet::weight(100_000_000)]132		pub fn just_take_fee(origin: OriginFor<T>) -> DispatchResult {133			Self::ensure_origin_and_enabled(origin)?;134			Ok(())135		}136137		#[pallet::call_index(5)]138		#[pallet::weight(10_000)]139		pub fn batch_all(140			origin: OriginFor<T>,141			calls: Vec<<T as Config>::RuntimeCall>,142		) -> DispatchResultWithPostInfo {143			Self::ensure_origin_and_enabled(origin.clone())?;144145			let is_root = ensure_root(origin.clone()).is_ok();146147			for call in calls {148				if is_root {149					call.dispatch_bypass_filter(origin.clone())?;150				} else {151					let mut filtered_origin = origin.clone();152					// Don't allow users to nest `batch_all` calls.153					filtered_origin.add_filter(154						move |c: &<T as frame_system::Config>::RuntimeCall| {155							let c = <T as Config>::RuntimeCall::from_ref(c);156							!matches!(c.is_sub_type(), Some(Call::batch_all { .. }))157						},158					);159					call.dispatch(filtered_origin)?;160				}161			}162163			Self::deposit_event(Event::BatchCompleted);164			Ok(None::<Weight>.into())165		}166	}167}168169impl<T: Config> Pallet<T> {170	fn ensure_origin_and_enabled(origin: OriginFor<T>) -> DispatchResult {171		ensure_signed(origin)?;172		<Enabled<T>>::get()173			.then(|| ())174			.ok_or(<Error<T>>::TestPalletDisabled.into())175	}176}
after · test-pallets/utils/src/lib.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;20use frame_support::pallet_prelude::*;21use frame_system::pallet_prelude::*;2223#[frame_support::pallet(dev_mode)]24pub mod pallet {25	use frame_support::{26		pallet_prelude::*,27		dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},28		traits::{UnfilteredDispatchable, IsSubType, OriginTrait},29	};30	use frame_system::pallet_prelude::*;31	use sp_std::vec::Vec;32	// use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};3334	#[pallet::config]35	pub trait Config: frame_system::Config /*+ pallet_unique_scheduler_v2::Config*/ {36		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;3738		/// The overarching call type.39		type RuntimeCall: Parameter40			+ Dispatchable<41				RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin,42				PostInfo = PostDispatchInfo,43			> + GetDispatchInfo44			+ From<frame_system::Call<Self>>45			+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>46			+ IsSubType<Call<Self>>47			+ IsType<<Self as frame_system::Config>::RuntimeCall>;48	}4950	#[pallet::event]51	#[pallet::generate_deposit(pub(super) fn deposit_event)]52	pub enum Event<T: Config> {53		ValueIsSet,54		ShouldRollback,55		BatchCompleted,56	}5758	#[pallet::pallet]59	pub struct Pallet<T>(_);6061	#[pallet::storage]62	#[pallet::getter(fn is_enabled)]63	pub type Enabled<T> = StorageValue<_, bool, ValueQuery>;6465	#[pallet::storage]66	#[pallet::getter(fn test_value)]67	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;6869	#[pallet::error]70	pub enum Error<T> {71		TestPalletDisabled,72		TriggerRollback,73	}7475	#[pallet::call]76	impl<T: Config> Pallet<T> {77		#[pallet::call_index(0)]78		#[pallet::weight(10_000)]79		pub fn enable(origin: OriginFor<T>) -> DispatchResult {80			ensure_root(origin)?;81			<Enabled<T>>::set(true);8283			Ok(())84		}8586		#[pallet::call_index(1)]87		#[pallet::weight(10_000)]88		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {89			Self::ensure_origin_and_enabled(origin)?;9091			<TestValue<T>>::put(value);9293			Self::deposit_event(Event::ValueIsSet);9495			Ok(())96		}9798		#[pallet::call_index(2)]99		#[pallet::weight(10_000)]100		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {101			Self::set_test_value(origin, value)?;102103			Self::deposit_event(Event::ShouldRollback);104105			Err(<Error<T>>::TriggerRollback.into())106		}107108		#[pallet::call_index(3)]109		#[pallet::weight(10_000)]110		pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {111			Self::set_test_value(origin, <TestValue<T>>::get() + 1)112		}113114		// #[pallet::weight(10_000)]115		// pub fn self_canceling_inc(116		// 	origin: OriginFor<T>,117		// 	id: TaskName,118		// 	max_test_value: u32,119		// ) -> DispatchResult {120		// 	Self::ensure_origin_and_enabled(origin.clone())?;121		// 	Self::inc_test_value(origin.clone())?;122123		// 	if <TestValue<T>>::get() == max_test_value {124		// 		SchedulerPallet::<T>::cancel_named(origin, id)?;125		// 	}126127		// 	Ok(())128		// }129130		#[pallet::call_index(4)]131		#[pallet::weight(100_000_000)]132		pub fn just_take_fee(origin: OriginFor<T>) -> DispatchResult {133			Self::ensure_origin_and_enabled(origin)?;134			Ok(())135		}136137		#[pallet::call_index(5)]138		#[pallet::weight(10_000)]139		pub fn batch_all(140			origin: OriginFor<T>,141			calls: Vec<<T as Config>::RuntimeCall>,142		) -> DispatchResultWithPostInfo {143			Self::ensure_origin_and_enabled(origin.clone())?;144145			let is_root = ensure_root(origin.clone()).is_ok();146147			for call in calls {148				if is_root {149					call.dispatch_bypass_filter(origin.clone())?;150				} else {151					let mut filtered_origin = origin.clone();152					// Don't allow users to nest `batch_all` calls.153					filtered_origin.add_filter(154						move |c: &<T as frame_system::Config>::RuntimeCall| {155							let c = <T as Config>::RuntimeCall::from_ref(c);156							!matches!(c.is_sub_type(), Some(Call::batch_all { .. }))157						},158					);159					call.dispatch(filtered_origin)?;160				}161			}162163			Self::deposit_event(Event::BatchCompleted);164			Ok(None::<Weight>.into())165		}166	}167}168169impl<T: Config> Pallet<T> {170	fn ensure_origin_and_enabled(origin: OriginFor<T>) -> DispatchResult {171		ensure_signed(origin)?;172		<Enabled<T>>::get()173			.then(|| ())174			.ok_or(<Error<T>>::TestPalletDisabled.into())175	}176}