git.delta.rocks / unique-network / refs/commits / 1f0f7134d4a8

difftreelog

feat(Scheduler) scheduler-runtime interface [WIP]

Fahrrader2022-02-09parent: #6f1d842.patch.diff
in: master

3 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6272,6 +6272,7 @@
  "parity-scale-codec",
  "scale-info",
  "serde",
+ "sp-api",
  "sp-core",
  "sp-io",
  "sp-runtime",
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -55,11 +55,11 @@
 mod benchmarking;
 pub mod weights;
 
-use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};
+use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow, cmp};
 use codec::{Encode, Decode, Codec};
 use sp_runtime::{
 	RuntimeDebug,
-	traits::{One, BadOrigin, Saturating},
+	traits::{Zero, One, BadOrigin, Saturating},
 };
 use frame_support::{
 	decl_module, decl_storage, decl_event, decl_error,
@@ -242,7 +242,6 @@
 		type Error = Error<T>;
 		fn deposit_event() = default;
 
-
 		/// Anonymously schedule a task.
 		///
 		/// # <weight>
@@ -506,14 +505,14 @@
 		let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
 		let r = call.clone().dispatch(sponsor.into());
 
-		//T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call
+		//T::PaymentHandler::apply();
+		//T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch extrinsic here
 
 		// sanitize maybe_periodic
-		let maybe_periodic = None;
-		// let maybe_periodic = maybe_periodic
-		// 	.filter(|p| p.1 > 1 && !p.0.is_zero())
-		// 	// Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
-		// 	.map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
+		let maybe_periodic = maybe_periodic
+			.filter(|p| p.1 > 1 && !p.0.is_zero())
+			// Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
+			.map(|(p, c)| (p, cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
 
 		let s = Some(Scheduled {
 			maybe_id,
@@ -571,6 +570,7 @@
 		if let Some(s) = scheduled {
 			if let Some(id) = s.maybe_id {
 				Lookup::<T>::remove(id);
+				// todo add back money / displace to another function for consistency
 			}
 			Self::deposit_event(RawEvent::Canceled(when, index));
 			Ok(())
@@ -648,6 +648,7 @@
 					}
 					Ok(())
 				})?;
+				// todo add money back / displace to another function
 				Self::deposit_event(RawEvent::Canceled(when, index));
 				Ok(())
 			} else {
@@ -795,7 +796,7 @@
 			pub struct Module<T: Config> for enum Call
 			where
 				origin: <T as system::Config>::Origin,
-				<T as system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>
+					<T as system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>
 			{
 				fn deposit_event() = default;
 
@@ -841,6 +842,13 @@
 		}
 	}
 
+	pub struct DummyExecutor; // todo do something with naming and function body
+	impl<C: Dispatchable> ApplyExtrinsic<C> for DummyExecutor {
+		fn apply_extrinsic(_signer: Address, _function: C) -> ApplyExtrinsicResult {
+			todo!()
+		}
+	}
+
 	parameter_types! {
 		pub const BlockHashCount: u64 = 250;
 		pub BlockWeights: frame_system::limits::BlockWeights =
@@ -891,7 +899,6 @@
 		type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
 		type MaxScheduledPerBlock = MaxScheduledPerBlock;
 		type WeightInfo = ();
-		type SponsorshipHandler = ();
-		type PaymentHandler = ();
+		type Executor = DummyExecutor;
 	}
 }
modifiedruntime/src/lib.rsdiffbeforeafterboth
815 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,815 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,
816);816);
817
818// pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
819// node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)
820// }
821
822pub struct SchedulerPaymentExecutor;
823impl<C: Dispatchable> ApplyExtrinsic<C> for SchedulerPaymentExecutor {
824 fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult {
825 /*let extrinsic = sign(fp_self_contained::CheckedExtrinsic {
826 signed: fp_self_contained::CheckedSignature::SelfContained(None),
827 function,
828 });
829
830 Executive::apply_extrinsic(extrinsic)*/
831 todo!()
832 }
833}
817834
818impl pallet_unq_scheduler::Config for Runtime {835impl pallet_unq_scheduler::Config for Runtime {
819 type Event = Event;836 type Event = Event;
824 type ScheduleOrigin = EnsureSigned<AccountId>;841 type ScheduleOrigin = EnsureSigned<AccountId>;
825 type MaxScheduledPerBlock = MaxScheduledPerBlock;842 type MaxScheduledPerBlock = MaxScheduledPerBlock;
826 type WeightInfo = ();843 type WeightInfo = ();
827 type Executor = Ex;844 type Executor = SchedulerPaymentExecutor;
828}845}
829
830// pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
831// node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)
832// }
833
834struct Ex;
835impl<C: Dispatchable> ApplyExtrinsic<C> for Ex {
836 fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult {
837 let extrinsic = sign(fp_self_contained::CheckedExtrinsic {
838 signed: fp_self_contained::CheckedSignature::SelfContained(None),
839 function: function,
840 });
841
842 Executive::apply_extrinsic(extrinsic)
843 }
844}
845846
846impl pallet_evm_transaction_payment::Config for Runtime {847impl pallet_evm_transaction_payment::Config for Runtime {
847 type EvmSponsorshipHandler = EvmSponsorshipHandler;848 type EvmSponsorshipHandler = EvmSponsorshipHandler;