git.delta.rocks / unique-network / refs/commits / 90587283b7f1

difftreelog

fix cargo fmt

Daniel Shiposha2022-10-25parent: #829f2bc.patch.diff
in: master

4 files changed

modifiedpallets/scheduler-v2/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/lib.rs
+++ b/pallets/scheduler-v2/src/lib.rs
@@ -77,13 +77,16 @@
 
 use codec::{Codec, Decode, Encode, MaxEncodedLen};
 use frame_support::{
-	dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, PostDispatchInfo},
+	dispatch::{
+		DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, PostDispatchInfo,
+	},
 	traits::{
 		schedule::{self, DispatchTime, LOWEST_PRIORITY},
 		EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,
 		ConstU32, UnfilteredDispatchable,
 	},
-	weights::Weight, unsigned::TransactionValidityError,
+	weights::Weight,
+	unsigned::TransactionValidityError,
 };
 
 use frame_system::{self as system};
@@ -318,8 +321,10 @@
 
 		/// The aggregated call type.
 		type RuntimeCall: Parameter
-			+ Dispatchable<RuntimeOrigin = <Self as Config>::RuntimeOrigin, PostInfo = PostDispatchInfo>
-			+ UnfilteredDispatchable<RuntimeOrigin = <Self as system::Config>::RuntimeOrigin>
+			+ Dispatchable<
+				RuntimeOrigin = <Self as Config>::RuntimeOrigin,
+				PostInfo = PostDispatchInfo,
+			> + UnfilteredDispatchable<RuntimeOrigin = <Self as system::Config>::RuntimeOrigin>
 			+ GetDispatchInfo
 			+ From<system::Call<Self>>;
 
@@ -940,7 +945,7 @@
 				}
 
 				return Err((Unavailable, Some(task)));
-			},
+			}
 		};
 
 		weight.check_accrue(T::WeightInfo::service_task(
@@ -979,7 +984,7 @@
 			Err(Overweight) => {
 				// Preserve Lookup -- the task will be postponed.
 				Err((Overweight, Some(task)))
-			},
+			}
 			Ok(result) => {
 				Self::deposit_event(Event::Dispatched {
 					task: (when, agenda_index),
@@ -987,7 +992,9 @@
 					result,
 				});
 
-				let is_canceled = task.maybe_id.as_ref()
+				let is_canceled = task
+					.maybe_id
+					.as_ref()
 					.map(|id| !Lookup::<T>::contains_key(id))
 					.unwrap_or(false);
 
@@ -1011,14 +1018,14 @@
 								});
 							}
 						}
-					},
+					}
 					_ => {
 						if let Some(ref id) = task.maybe_id {
 							Lookup::<T>::remove(id);
 						}
 
 						T::Preimages::drop(&task.call)
-					},
+					}
 				}
 				Ok(())
 			}
@@ -1056,12 +1063,12 @@
 		let r = match ensured_origin {
 			Ok(ScheduledEnsureOriginSuccess::Root) => {
 				Ok(call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()))
-			},
+			}
 			Ok(ScheduledEnsureOriginSuccess::Signed(sender)) => {
 				// Execute transaction via chain default pipeline
 				// That means dispatch will be processed like any user's extrinsic e.g. transaction fees will be taken
 				T::CallExecutor::dispatch_call(Some(sender), call.clone())
-			},
+			}
 			Ok(ScheduledEnsureOriginSuccess::Unsigned) => {
 				// Unsigned version of the above
 				T::CallExecutor::dispatch_call(None, call.clone())
modifiedpallets/scheduler-v2/src/mock.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/mock.rs
+++ b/pallets/scheduler-v2/src/mock.rs
@@ -39,9 +39,7 @@
 use crate as scheduler;
 use frame_support::{
 	ord_parameter_types, parameter_types,
-	traits::{
-		ConstU32, ConstU64, Contains, EqualPrivilegeOnly, OnFinalize, OnInitialize,
-	},
+	traits::{ConstU32, ConstU64, Contains, EqualPrivilegeOnly, OnFinalize, OnInitialize},
 	weights::constants::RocksDbWeight,
 };
 use frame_system::{EnsureRoot, RawOrigin};
@@ -136,7 +134,7 @@
 	pub BlockWeights: frame_system::limits::BlockWeights =
 		frame_system::limits::BlockWeights::simple_max(
 			Weight::from_ref_time(2_000_000_000_000)
-            // .set_proof_size(u64::MAX),
+			// .set_proof_size(u64::MAX),
 		);
 }
 impl system::Config for Test {
@@ -210,9 +208,9 @@
 	fn cancel_named(_s: u32) -> Weight {
 		Weight::from_ref_time(50)
 	}
-    fn change_named_priority(_s: u32, ) -> Weight {
-        Weight::from_ref_time(50)
-    }
+	fn change_named_priority(_s: u32) -> Weight {
+		Weight::from_ref_time(50)
+	}
 }
 parameter_types! {
 	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
@@ -220,8 +218,8 @@
 }
 
 pub struct EnsureSignedOneOrRoot;
-impl<O: Into<Result<RawOrigin<u64>, O>> + From<RawOrigin<u64>>>
-	EnsureOrigin<O> for EnsureSignedOneOrRoot
+impl<O: Into<Result<RawOrigin<u64>, O>> + From<RawOrigin<u64>>> EnsureOrigin<O>
+	for EnsureSignedOneOrRoot
 {
 	type Success = ScheduledEnsureOriginSuccess<u64>;
 	fn try_origin(o: O) -> Result<Self::Success, O> {
@@ -235,19 +233,19 @@
 
 pub struct Executor;
 impl DispatchCall<Test, sp_core::H160> for Executor {
-    fn dispatch_call(
-        signer: Option<u64>,
-        function: RuntimeCall,
-    ) -> Result<
-        Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
-        TransactionValidityError,
-    > {
-        let origin = match signer {
-            Some(who) => RuntimeOrigin::signed(who),
-            None => RuntimeOrigin::none(),
-        };
-        Ok(function.dispatch(origin))
-    }
+	fn dispatch_call(
+		signer: Option<u64>,
+		function: RuntimeCall,
+	) -> Result<
+		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
+		TransactionValidityError,
+	> {
+		let origin = match signer {
+			Some(who) => RuntimeOrigin::signed(who),
+			None => RuntimeOrigin::none(),
+		};
+		Ok(function.dispatch(origin))
+	}
 }
 
 impl Config for Test {
@@ -261,14 +259,16 @@
 	type WeightInfo = TestWeightInfo;
 	type OriginPrivilegeCmp = EqualPrivilegeOnly;
 	type Preimages = ();
-    type PrioritySetOrigin = EnsureRoot<u64>;
-    type CallExecutor = Executor;
+	type PrioritySetOrigin = EnsureRoot<u64>;
+	type CallExecutor = Executor;
 }
 
 pub type LoggerCall = logger::Call<Test>;
 
 pub fn new_test_ext() -> sp_io::TestExternalities {
-	let t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
+	let t = system::GenesisConfig::default()
+		.build_storage::<Test>()
+		.unwrap();
 	t.into()
 }
 
modifiedpallets/scheduler-v2/src/tests.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/tests.rs
+++ b/pallets/scheduler-v2/src/tests.rs
@@ -46,15 +46,19 @@
 #[test]
 fn basic_scheduling_works() {
 	new_test_ext().execute_with(|| {
-		let call =
-			RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
-		assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: Weight::from_ref_time(10),
+		});
+		assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(
+			&call
+		));
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
 			127,
 			root(),
-            <ScheduledCall<Test>>::new(call).unwrap(),
+			<ScheduledCall<Test>>::new(call).unwrap(),
 		));
 		run_to_block(3);
 		assert!(logger::log().is_empty());
@@ -69,9 +73,13 @@
 fn schedule_after_works() {
 	new_test_ext().execute_with(|| {
 		run_to_block(2);
-		let call =
-			RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
-		assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: Weight::from_ref_time(10),
+		});
+		assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(
+			&call
+		));
 		// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::After(3),
@@ -93,9 +101,13 @@
 fn schedule_after_zero_works() {
 	new_test_ext().execute_with(|| {
 		run_to_block(2);
-		let call =
-			RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
-		assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: Weight::from_ref_time(10),
+		});
+		assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(
+			&call
+		));
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::After(0),
 			None,
@@ -120,7 +132,7 @@
 			Some((3, 3)),
 			127,
 			root(),
-            <ScheduledCall<Test>>::new(RuntimeCall::Logger(logger::Call::log {
+			<ScheduledCall<Test>>::new(RuntimeCall::Logger(logger::Call::log {
 				i: 42,
 				weight: Weight::from_ref_time(10)
 			}))
@@ -137,9 +149,15 @@
 		run_to_block(9);
 		assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
 		run_to_block(10);
-		assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
+		assert_eq!(
+			logger::log(),
+			vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
+		);
 		run_to_block(100);
-		assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
+		assert_eq!(
+			logger::log(),
+			vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
+		);
 	});
 }
 
@@ -241,7 +259,10 @@
 fn scheduler_respects_weight_limits() {
 	let max_weight: Weight = <Test as Config>::MaximumWeight::get();
 	new_test_ext().execute_with(|| {
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 3 * 2 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: max_weight / 3 * 2,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -249,7 +270,10 @@
 			root(),
 			<ScheduledCall<Test>>::new(call).unwrap(),
 		));
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 3 * 2 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 69,
+			weight: max_weight / 3 * 2,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -270,7 +294,10 @@
 fn scheduler_does_not_delete_permanently_overweight_call() {
 	let max_weight: Weight = <Test as Config>::MaximumWeight::get();
 	new_test_ext().execute_with(|| {
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: max_weight,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -285,7 +312,11 @@
 		// Assert the `PermanentlyOverweight` event.
 		assert_eq!(
 			System::events().last().unwrap().event,
-			crate::Event::PermanentlyOverweight { task: (4, 0), id: None }.into(),
+			crate::Event::PermanentlyOverweight {
+				task: (4, 0),
+				id: None
+			}
+			.into(),
 		);
 		// The call is still in the agenda.
 		assert!(Agenda::<Test>::get(4)[0].is_some());
@@ -298,7 +329,10 @@
 	let max_per_block = <Test as Config>::MaxScheduledPerBlock::get();
 
 	new_test_ext().execute_with(|| {
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: (max_weight / 3) * 2 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: (max_weight / 3) * 2,
+		});
 		let call = <ScheduledCall<Test>>::new(call).unwrap();
 
 		assert_ok!(Scheduler::do_schedule(
@@ -329,7 +363,11 @@
 
 		assert_eq!(
 			System::events().last().unwrap().event,
-			crate::Event::PeriodicFailed { task: (24, 0), id: None }.into(),
+			crate::Event::PeriodicFailed {
+				task: (24, 0),
+				id: None
+			}
+			.into(),
 		);
 	});
 }
@@ -338,7 +376,10 @@
 fn scheduler_respects_priority_ordering() {
 	let max_weight: Weight = <Test as Config>::MaximumWeight::get();
 	new_test_ext().execute_with(|| {
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 3 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: max_weight / 3,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -346,7 +387,10 @@
 			root(),
 			<ScheduledCall<Test>>::new(call).unwrap(),
 		));
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 3 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 69,
+			weight: max_weight / 3,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -363,7 +407,10 @@
 fn scheduler_respects_priority_ordering_with_soft_deadlines() {
 	new_test_ext().execute_with(|| {
 		let max_weight: Weight = <Test as Config>::MaximumWeight::get();
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 5 * 2 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: max_weight / 5 * 2,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -371,7 +418,10 @@
 			root(),
 			<ScheduledCall<Test>>::new(call).unwrap(),
 		));
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 5 * 2 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 69,
+			weight: max_weight / 5 * 2,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -379,7 +429,10 @@
 			root(),
 			<ScheduledCall<Test>>::new(call).unwrap(),
 		));
-		let call = RuntimeCall::Logger(LoggerCall::log { i: 2600, weight: max_weight / 5 * 4 });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 2600,
+			weight: max_weight / 5 * 4,
+		});
 		assert_ok!(Scheduler::do_schedule(
 			DispatchTime::At(4),
 			None,
@@ -393,7 +446,10 @@
 		assert_eq!(logger::log(), vec![(root(), 2600u32)]);
 		// 69 and 42 fit together
 		run_to_block(5);
-		assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
+		assert_eq!(
+			logger::log(),
+			vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]
+		);
 	});
 }
 
@@ -456,11 +512,11 @@
 		// Will include the named periodic only
 		assert_eq!(
 			Scheduler::on_initialize(1),
-			TestWeightInfo::service_agendas_base() +
-				TestWeightInfo::service_agenda_base(1) +
-				<TestWeightInfo as MarginalWeightInfo>::service_task(None, true, true) +
-				TestWeightInfo::execute_dispatch_unsigned() +
-				call_weight + Weight::from_ref_time(4)
+			TestWeightInfo::service_agendas_base()
+				+ TestWeightInfo::service_agenda_base(1)
+				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, true)
+				+ TestWeightInfo::execute_dispatch_unsigned()
+				+ call_weight + Weight::from_ref_time(4)
 		);
 		assert_eq!(IncompleteSince::<Test>::get(), None);
 		assert_eq!(logger::log(), vec![(root(), 2600u32)]);
@@ -468,31 +524,39 @@
 		// Will include anon and anon periodic
 		assert_eq!(
 			Scheduler::on_initialize(2),
-			TestWeightInfo::service_agendas_base() +
-				TestWeightInfo::service_agenda_base(2) +
-				<TestWeightInfo as MarginalWeightInfo>::service_task(None, false, true) +
-				TestWeightInfo::execute_dispatch_unsigned() +
-				call_weight + Weight::from_ref_time(3) +
-				<TestWeightInfo as MarginalWeightInfo>::service_task(None, false, false) +
-				TestWeightInfo::execute_dispatch_unsigned() +
-				call_weight + Weight::from_ref_time(2)
+			TestWeightInfo::service_agendas_base()
+				+ TestWeightInfo::service_agenda_base(2)
+				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, true)
+				+ TestWeightInfo::execute_dispatch_unsigned()
+				+ call_weight + Weight::from_ref_time(3)
+				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, false)
+				+ TestWeightInfo::execute_dispatch_unsigned()
+				+ call_weight + Weight::from_ref_time(2)
 		);
 		assert_eq!(IncompleteSince::<Test>::get(), None);
-		assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
+		assert_eq!(
+			logger::log(),
+			vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]
+		);
 
 		// Will include named only
 		assert_eq!(
 			Scheduler::on_initialize(3),
-			TestWeightInfo::service_agendas_base() +
-				TestWeightInfo::service_agenda_base(1) +
-				<TestWeightInfo as MarginalWeightInfo>::service_task(None, true, false) +
-				TestWeightInfo::execute_dispatch_unsigned() +
-				call_weight + Weight::from_ref_time(1)
+			TestWeightInfo::service_agendas_base()
+				+ TestWeightInfo::service_agenda_base(1)
+				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, false)
+				+ TestWeightInfo::execute_dispatch_unsigned()
+				+ call_weight + Weight::from_ref_time(1)
 		);
 		assert_eq!(IncompleteSince::<Test>::get(), None);
 		assert_eq!(
 			logger::log(),
-			vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32), (root(), 3u32)]
+			vec![
+				(root(), 2600u32),
+				(root(), 69u32),
+				(root(), 42u32),
+				(root(), 3u32)
+			]
 		);
 
 		// Will contain none
@@ -515,10 +579,21 @@
 			i: 42,
 			weight: Weight::from_ref_time(10),
 		}));
-		assert_ok!(
-			Scheduler::schedule_named(RuntimeOrigin::root(), [1u8; 32], 4, None, Some(127), call,)
-		);
-		assert_ok!(Scheduler::schedule(RuntimeOrigin::root(), 4, None, Some(127), call2));
+		assert_ok!(Scheduler::schedule_named(
+			RuntimeOrigin::root(),
+			[1u8; 32],
+			4,
+			None,
+			Some(127),
+			call,
+		));
+		assert_ok!(Scheduler::schedule(
+			RuntimeOrigin::root(),
+			4,
+			None,
+			Some(127),
+			call2
+		));
 		run_to_block(3);
 		// Scheduled calls are in the agenda.
 		assert_eq!(Agenda::<Test>::get(4).len(), 2);
@@ -585,12 +660,21 @@
 			None,
 			call,
 		));
-		assert_ok!(Scheduler::schedule(system::RawOrigin::Signed(1).into(), 4, None, None, call2,));
+		assert_ok!(Scheduler::schedule(
+			system::RawOrigin::Signed(1).into(),
+			4,
+			None,
+			None,
+			call2,
+		));
 		run_to_block(3);
 		// Scheduled calls are in the agenda.
 		assert_eq!(Agenda::<Test>::get(4).len(), 2);
 		assert!(logger::log().is_empty());
-		assert_ok!(Scheduler::cancel_named(system::RawOrigin::Signed(1).into(), [1u8; 32]));
+		assert_ok!(Scheduler::cancel_named(
+			system::RawOrigin::Signed(1).into(),
+			[1u8; 32]
+		));
 		assert_ok!(Scheduler::cancel(system::RawOrigin::Signed(1).into(), 4, 1));
 		// Scheduled calls are made NONE, so should not effect state
 		run_to_block(100);
@@ -646,7 +730,13 @@
 			None,
 			call,
 		));
-		assert_ok!(Scheduler::schedule(system::RawOrigin::Signed(1).into(), 4, None, None, call2,));
+		assert_ok!(Scheduler::schedule(
+			system::RawOrigin::Signed(1).into(),
+			4,
+			None,
+			None,
+			call2,
+		));
 		run_to_block(3);
 		// Scheduled calls are in the agenda.
 		assert_eq!(Agenda::<Test>::get(4).len(), 2);
@@ -655,9 +745,18 @@
 			Scheduler::cancel_named(system::RawOrigin::Signed(2).into(), [1u8; 32]),
 			BadOrigin
 		);
-		assert_noop!(Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1), BadOrigin);
-		assert_noop!(Scheduler::cancel_named(system::RawOrigin::Root.into(), [1u8; 32]), BadOrigin);
-		assert_noop!(Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1), BadOrigin);
+		assert_noop!(
+			Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1),
+			BadOrigin
+		);
+		assert_noop!(
+			Scheduler::cancel_named(system::RawOrigin::Root.into(), [1u8; 32]),
+			BadOrigin
+		);
+		assert_noop!(
+			Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1),
+			BadOrigin
+		);
 		run_to_block(5);
 		assert_eq!(
 			logger::log(),
@@ -674,8 +773,10 @@
 #[test]
 fn schedule_does_not_resuse_addr() {
 	new_test_ext().execute_with(|| {
-		let call =
-			RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: Weight::from_ref_time(10),
+		});
 
 		// Schedule both calls.
 		let addr_1 = Scheduler::do_schedule(
@@ -707,20 +808,15 @@
 	let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();
 
 	new_test_ext().execute_with(|| {
-		let call =
-			RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: Weight::from_ref_time(10),
+		});
 		let call = <ScheduledCall<Test>>::new(call).unwrap();
 
 		// Schedule the maximal number allowed per block.
 		for _ in 0..max {
-			Scheduler::do_schedule(
-				DispatchTime::At(4),
-				None,
-				127,
-				root(),
-				call.clone(),
-			)
-			.unwrap();
+			Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone()).unwrap();
 		}
 
 		// One more time and it errors.
@@ -739,25 +835,24 @@
 #[test]
 fn cancel_and_schedule_fills_holes() {
 	let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();
-	assert!(max > 3, "This test only makes sense for MaxScheduledPerBlock > 3");
+	assert!(
+		max > 3,
+		"This test only makes sense for MaxScheduledPerBlock > 3"
+	);
 
 	new_test_ext().execute_with(|| {
-		let call =
-			RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
+		let call = RuntimeCall::Logger(LoggerCall::log {
+			i: 42,
+			weight: Weight::from_ref_time(10),
+		});
 		let call = <ScheduledCall<Test>>::new(call).unwrap();
 		let mut addrs = Vec::<_>::default();
 
 		// Schedule the maximal number allowed per block.
 		for _ in 0..max {
 			addrs.push(
-				Scheduler::do_schedule(
-					DispatchTime::At(4),
-					None,
-					127,
-					root(),
-					call.clone(),
-				)
-				.unwrap(),
+				Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())
+					.unwrap(),
 			);
 		}
 		// Cancel three of them.
@@ -766,14 +861,9 @@
 		}
 		// Schedule three new ones.
 		for i in 0..3 {
-			let (_block, index) = Scheduler::do_schedule(
-				DispatchTime::At(4),
-				None,
-				127,
-				root(),
-				call.clone(),
-			)
-			.unwrap();
+			let (_block, index) =
+				Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())
+					.unwrap();
 			assert_eq!(i, index);
 		}
 
modifiedruntime/common/scheduler.rsdiffbeforeafterboth
before · runtime/common/scheduler.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 frame_support::{18	traits::NamedReservableCurrency,19	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},20};21use sp_runtime::{22	traits::{Dispatchable, Applyable, Member},23	generic::Era,24	transaction_validity::TransactionValidityError,25	DispatchErrorWithPostInfo, DispatchError,26};27use codec::Encode;28use crate::{Runtime, RuntimeCall, RuntimeOrigin, Balances};29use up_common::types::{AccountId, Balance};30use fp_self_contained::SelfContainedCall;31use pallet_unique_scheduler_v2::DispatchCall;32use pallet_transaction_payment::ChargeTransactionPayment;3334// type SponsorshipChargeTransactionPayment =35// 	pallet_charge_transaction::ChargeTransactionPayment<Runtime>;3637/// The SignedExtension to the basic transaction logic.38pub type SignedExtraScheduler = (39	frame_system::CheckSpecVersion<Runtime>,40	frame_system::CheckGenesis<Runtime>,41	frame_system::CheckEra<Runtime>,42	frame_system::CheckNonce<Runtime>,43	frame_system::CheckWeight<Runtime>,44	ChargeTransactionPayment<Runtime>,45);4647fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {48	(49		frame_system::CheckSpecVersion::<Runtime>::new(),50		frame_system::CheckGenesis::<Runtime>::new(),51		frame_system::CheckEra::<Runtime>::from(Era::Immortal),52		frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(53			from,54		)),55		frame_system::CheckWeight::<Runtime>::new(),56		ChargeTransactionPayment::<Runtime>::from(0),57	)58}5960pub struct SchedulerPaymentExecutor;6162impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>63	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor64where65	<T as frame_system::Config>::RuntimeCall: Member66		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>67		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>68		+ GetDispatchInfo69		+ From<frame_system::Call<Runtime>>,70	SelfContainedSignedInfo: Send + Sync + 'static,71	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>72		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>73		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,74	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,75{76	fn dispatch_call(77		signer: Option<<T as frame_system::Config>::AccountId>,78		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,79	) -> Result<80		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,81		TransactionValidityError,82	> {83		let dispatch_info = call.get_dispatch_info();84		let len = call.encoded_size();8586		let signed = match signer {87			Some(signer) => fp_self_contained::CheckedSignature::Signed(88				signer.clone().into(),89				get_signed_extras(signer.into()),90			),91			None => fp_self_contained::CheckedSignature::Unsigned,92		};9394		let extrinsic = fp_self_contained::CheckedExtrinsic::<95			AccountId,96			RuntimeCall,97			SignedExtraScheduler,98			SelfContainedSignedInfo,99		> {100			signed,101			function: call.into(),102		};103104		extrinsic.apply::<Runtime>(&dispatch_info, len)105	}106}107108109// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>110// 	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor111// where112// 	<T as frame_system::Config>::Call: Member113// 		+ Dispatchable<Origin = Origin, Info = DispatchInfo>114// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>115// 		+ GetDispatchInfo116// 		+ From<frame_system::Call<Runtime>>,117// 	SelfContainedSignedInfo: Send + Sync + 'static,118// 	Call: From<<T as frame_system::Config>::Call>119// 		+ From<<T as pallet_unique_scheduler::Config>::Call>120// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,121// 	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,122// {123// 	fn dispatch_call(124// 		signer: Option<<T as frame_system::Config>::AccountId>,125// 		call: <T as pallet_unique_scheduler::Config>::Call,126// 	) -> Result<127// 		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,128// 		TransactionValidityError,129// 	> {130// 		let dispatch_info = call.get_dispatch_info();131// 		let len = call.encoded_size();132133// 		let signed = match signer {134// 			Some(signer) => fp_self_contained::CheckedSignature::Signed(135// 				signer.clone().into(),136// 				get_signed_extras(signer.into()),137// 			),138// 			None => fp_self_contained::CheckedSignature::Unsigned,139// 		};140141// 		let extrinsic = fp_self_contained::CheckedExtrinsic::<142// 			AccountId,143// 			Call,144// 			SignedExtraScheduler,145// 			SelfContainedSignedInfo,146// 		> {147// 			signed,148// 			function: call.into(),149// 		};150151// 		extrinsic.apply::<Runtime>(&dispatch_info, len)152// 	}153154// 	fn reserve_balance(155// 		id: [u8; 16],156// 		sponsor: <T as frame_system::Config>::AccountId,157// 		call: <T as pallet_unique_scheduler::Config>::Call,158// 		count: u32,159// 	) -> Result<(), DispatchError> {160// 		let dispatch_info = call.get_dispatch_info();161// 		let weight: Balance =162// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)163// 				.saturating_mul(count.into());164165// 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(166// 			&id,167// 			&(sponsor.into()),168// 			weight,169// 		)170// 	}171172// 	fn pay_for_call(173// 		id: [u8; 16],174// 		sponsor: <T as frame_system::Config>::AccountId,175// 		call: <T as pallet_unique_scheduler::Config>::Call,176// 	) -> Result<u128, DispatchError> {177// 		let dispatch_info = call.get_dispatch_info();178// 		let weight: Balance =179// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);180// 		Ok(181// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(182// 				&id,183// 				&(sponsor.into()),184// 				weight,185// 			),186// 		)187// 	}188189// 	fn cancel_reserve(190// 		id: [u8; 16],191// 		sponsor: <T as frame_system::Config>::AccountId,192// 	) -> Result<u128, DispatchError> {193// 		Ok(194// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(195// 				&id,196// 				&(sponsor.into()),197// 				u128::MAX,198// 			),199// 		)200// 	}201// }
after · runtime/common/scheduler.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 frame_support::{18	traits::NamedReservableCurrency,19	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},20};21use sp_runtime::{22	traits::{Dispatchable, Applyable, Member},23	generic::Era,24	transaction_validity::TransactionValidityError,25	DispatchErrorWithPostInfo, DispatchError,26};27use codec::Encode;28use crate::{Runtime, RuntimeCall, RuntimeOrigin, Balances};29use up_common::types::{AccountId, Balance};30use fp_self_contained::SelfContainedCall;31use pallet_unique_scheduler_v2::DispatchCall;32use pallet_transaction_payment::ChargeTransactionPayment;3334// type SponsorshipChargeTransactionPayment =35// 	pallet_charge_transaction::ChargeTransactionPayment<Runtime>;3637/// The SignedExtension to the basic transaction logic.38pub type SignedExtraScheduler = (39	frame_system::CheckSpecVersion<Runtime>,40	frame_system::CheckGenesis<Runtime>,41	frame_system::CheckEra<Runtime>,42	frame_system::CheckNonce<Runtime>,43	frame_system::CheckWeight<Runtime>,44	ChargeTransactionPayment<Runtime>,45);4647fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {48	(49		frame_system::CheckSpecVersion::<Runtime>::new(),50		frame_system::CheckGenesis::<Runtime>::new(),51		frame_system::CheckEra::<Runtime>::from(Era::Immortal),52		frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(53			from,54		)),55		frame_system::CheckWeight::<Runtime>::new(),56		ChargeTransactionPayment::<Runtime>::from(0),57	)58}5960pub struct SchedulerPaymentExecutor;6162impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>63	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor64where65	<T as frame_system::Config>::RuntimeCall: Member66		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>67		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>68		+ GetDispatchInfo69		+ From<frame_system::Call<Runtime>>,70	SelfContainedSignedInfo: Send + Sync + 'static,71	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>72		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>73		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,74	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,75{76	fn dispatch_call(77		signer: Option<<T as frame_system::Config>::AccountId>,78		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,79	) -> Result<80		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,81		TransactionValidityError,82	> {83		let dispatch_info = call.get_dispatch_info();84		let len = call.encoded_size();8586		let signed = match signer {87			Some(signer) => fp_self_contained::CheckedSignature::Signed(88				signer.clone().into(),89				get_signed_extras(signer.into()),90			),91			None => fp_self_contained::CheckedSignature::Unsigned,92		};9394		let extrinsic = fp_self_contained::CheckedExtrinsic::<95			AccountId,96			RuntimeCall,97			SignedExtraScheduler,98			SelfContainedSignedInfo,99		> {100			signed,101			function: call.into(),102		};103104		extrinsic.apply::<Runtime>(&dispatch_info, len)105	}106}107108// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>109// 	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor110// where111// 	<T as frame_system::Config>::Call: Member112// 		+ Dispatchable<Origin = Origin, Info = DispatchInfo>113// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>114// 		+ GetDispatchInfo115// 		+ From<frame_system::Call<Runtime>>,116// 	SelfContainedSignedInfo: Send + Sync + 'static,117// 	Call: From<<T as frame_system::Config>::Call>118// 		+ From<<T as pallet_unique_scheduler::Config>::Call>119// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,120// 	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,121// {122// 	fn dispatch_call(123// 		signer: Option<<T as frame_system::Config>::AccountId>,124// 		call: <T as pallet_unique_scheduler::Config>::Call,125// 	) -> Result<126// 		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,127// 		TransactionValidityError,128// 	> {129// 		let dispatch_info = call.get_dispatch_info();130// 		let len = call.encoded_size();131132// 		let signed = match signer {133// 			Some(signer) => fp_self_contained::CheckedSignature::Signed(134// 				signer.clone().into(),135// 				get_signed_extras(signer.into()),136// 			),137// 			None => fp_self_contained::CheckedSignature::Unsigned,138// 		};139140// 		let extrinsic = fp_self_contained::CheckedExtrinsic::<141// 			AccountId,142// 			Call,143// 			SignedExtraScheduler,144// 			SelfContainedSignedInfo,145// 		> {146// 			signed,147// 			function: call.into(),148// 		};149150// 		extrinsic.apply::<Runtime>(&dispatch_info, len)151// 	}152153// 	fn reserve_balance(154// 		id: [u8; 16],155// 		sponsor: <T as frame_system::Config>::AccountId,156// 		call: <T as pallet_unique_scheduler::Config>::Call,157// 		count: u32,158// 	) -> Result<(), DispatchError> {159// 		let dispatch_info = call.get_dispatch_info();160// 		let weight: Balance =161// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)162// 				.saturating_mul(count.into());163164// 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(165// 			&id,166// 			&(sponsor.into()),167// 			weight,168// 		)169// 	}170171// 	fn pay_for_call(172// 		id: [u8; 16],173// 		sponsor: <T as frame_system::Config>::AccountId,174// 		call: <T as pallet_unique_scheduler::Config>::Call,175// 	) -> Result<u128, DispatchError> {176// 		let dispatch_info = call.get_dispatch_info();177// 		let weight: Balance =178// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);179// 		Ok(180// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(181// 				&id,182// 				&(sponsor.into()),183// 				weight,184// 			),185// 		)186// 	}187188// 	fn cancel_reserve(189// 		id: [u8; 16],190// 		sponsor: <T as frame_system::Config>::AccountId,191// 	) -> Result<u128, DispatchError> {192// 		Ok(193// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(194// 				&id,195// 				&(sponsor.into()),196// 				u128::MAX,197// 			),198// 		)199// 	}200// }