difftreelog
feat(Scheduler) scheduler-runtime interface [WIP]
in: master
3 files changed
Cargo.lockdiffbeforeafterboth6272 "parity-scale-codec",6272 "parity-scale-codec",6273 "scale-info",6273 "scale-info",6274 "serde",6274 "serde",6275 "sp-api",6275 "sp-core",6276 "sp-core",6276 "sp-io",6277 "sp-io",6277 "sp-runtime",6278 "sp-runtime",pallets/scheduler/src/lib.rsdiffbeforeafterboth55mod benchmarking;55mod benchmarking;56pub mod weights;56pub mod weights;575758use 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());508507508 //T::PaymentHandler::apply();509 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call509 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch extrinsic here510510511 // sanitize maybe_periodic511 // sanitize maybe_periodic512 let maybe_periodic = None;512 let maybe_periodic = maybe_periodic513 // 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));517516518 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 consistency574 }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 function651 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 }844845 pub struct DummyExecutor; // todo do something with naming and function body846 impl<C: Dispatchable> ApplyExtrinsic<C> for DummyExecutor {847 fn apply_extrinsic(_signer: Address, _function: C) -> ApplyExtrinsicResult {848 todo!()849 }850 }843851844 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}898905runtime/src/lib.rsdiffbeforeafterboth815 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,815 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,816);816);817818// pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {819// node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)820// }821822pub 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 });829830 Executive::apply_extrinsic(extrinsic)*/831 todo!()832 }833}817834818impl 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}829830// pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {831// node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)832// }833834struct 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 });841842 Executive::apply_extrinsic(extrinsic)843 }844}845846846impl pallet_evm_transaction_payment::Config for Runtime {847impl pallet_evm_transaction_payment::Config for Runtime {847 type EvmSponsorshipHandler = EvmSponsorshipHandler;848 type EvmSponsorshipHandler = EvmSponsorshipHandler;