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
55mod benchmarking;55mod benchmarking;
56pub mod weights;56pub mod weights;
5757
58use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};58use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow, cmp};
59use codec::{Encode, Decode, Codec};59use codec::{Encode, Decode, Codec};
60use sp_runtime::{60use sp_runtime::{
61 RuntimeDebug,61 RuntimeDebug,
62 traits::{One, BadOrigin, Saturating},62 traits::{Zero, One, BadOrigin, Saturating},
63};63};
64use frame_support::{64use frame_support::{
65 decl_module, decl_storage, decl_event, decl_error,65 decl_module, decl_storage, decl_event, decl_error,
506 let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));505 let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
507 let r = call.clone().dispatch(sponsor.into());506 let r = call.clone().dispatch(sponsor.into());
508507
508 //T::PaymentHandler::apply();
509 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call509 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch extrinsic here
510510
511 // sanitize maybe_periodic511 // sanitize maybe_periodic
512 let maybe_periodic = None;512 let maybe_periodic = maybe_periodic
513 // let maybe_periodic = maybe_periodic513 .filter(|p| p.1 > 1 && !p.0.is_zero())
514 // .filter(|p| p.1 > 1 && !p.0.is_zero())514 // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
515 // // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.515 .map(|(p, c)| (p, cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
516 // .map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
517516
518 let s = Some(Scheduled {517 let s = Some(Scheduled {
519 maybe_id,518 maybe_id,
571 if let Some(s) = scheduled {570 if let Some(s) = scheduled {
572 if let Some(id) = s.maybe_id {571 if let Some(id) = s.maybe_id {
573 Lookup::<T>::remove(id);572 Lookup::<T>::remove(id);
573 // todo add back money / displace to another function for consistency
574 }574 }
575 Self::deposit_event(RawEvent::Canceled(when, index));575 Self::deposit_event(RawEvent::Canceled(when, index));
576 Ok(())576 Ok(())
648 }648 }
649 Ok(())649 Ok(())
650 })?;650 })?;
651 // todo add money back / displace to another function
651 Self::deposit_event(RawEvent::Canceled(when, index));652 Self::deposit_event(RawEvent::Canceled(when, index));
652 Ok(())653 Ok(())
653 } else {654 } else {
841 }842 }
842 }843 }
844
845 pub struct DummyExecutor; // todo do something with naming and function body
846 impl<C: Dispatchable> ApplyExtrinsic<C> for DummyExecutor {
847 fn apply_extrinsic(_signer: Address, _function: C) -> ApplyExtrinsicResult {
848 todo!()
849 }
850 }
843851
844 parameter_types! {852 parameter_types! {
845 pub const BlockHashCount: u64 = 250;853 pub const BlockHashCount: u64 = 250;
891 type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;899 type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
892 type MaxScheduledPerBlock = MaxScheduledPerBlock;900 type MaxScheduledPerBlock = MaxScheduledPerBlock;
893 type WeightInfo = ();901 type WeightInfo = ();
894 type SponsorshipHandler = ();902 type Executor = DummyExecutor;
895 type PaymentHandler = ();
896 }903 }
897}904}
898905
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -815,34 +815,35 @@
 	pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,
 );
 
-impl pallet_unq_scheduler::Config for Runtime {
-	type Event = Event;
-	type Origin = Origin;
-	type PalletsOrigin = OriginCaller;
-	type Call = Call;
-	type MaximumWeight = MaximumSchedulerWeight;
-	type ScheduleOrigin = EnsureSigned<AccountId>;
-	type MaxScheduledPerBlock = MaxScheduledPerBlock;
-	type WeightInfo = ();
-	type Executor = Ex;
-}
-
 // pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
 // 	node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)
 // }
 
-struct Ex;
-impl<C: Dispatchable> ApplyExtrinsic<C> for Ex {
+pub struct SchedulerPaymentExecutor;
+impl<C: Dispatchable> ApplyExtrinsic<C> for SchedulerPaymentExecutor {
 	fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult {
-		let extrinsic = sign(fp_self_contained::CheckedExtrinsic {
+		/*let extrinsic = sign(fp_self_contained::CheckedExtrinsic {
 			signed: fp_self_contained::CheckedSignature::SelfContained(None),
-			function: function,
+			function,
 		});
 
-		Executive::apply_extrinsic(extrinsic)
+		Executive::apply_extrinsic(extrinsic)*/
+		todo!()
 	}
 }
 
+impl pallet_unq_scheduler::Config for Runtime {
+	type Event = Event;
+	type Origin = Origin;
+	type PalletsOrigin = OriginCaller;
+	type Call = Call;
+	type MaximumWeight = MaximumSchedulerWeight;
+	type ScheduleOrigin = EnsureSigned<AccountId>;
+	type MaxScheduledPerBlock = MaxScheduledPerBlock;
+	type WeightInfo = ();
+	type Executor = SchedulerPaymentExecutor;
+}
+
 impl pallet_evm_transaction_payment::Config for Runtime {
 	type EvmSponsorshipHandler = EvmSponsorshipHandler;
 	type Currency = Balances;