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

difftreelog

Call executor added to scheduler pallet

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

3 files changed

modifiedpallets/scheduler/Cargo.tomldiffbeforeafterboth
20sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }20sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
21frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }21frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
2222
23sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
23up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring", branch = 'polkadot-v0.9.14' }24up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring", branch = 'polkadot-v0.9.14' }
24log = { version = "0.4.14", default-features = false }25log = { version = "0.4.14", default-features = false }
2526
26[dev-dependencies]27[dev-dependencies]
27sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
28substrate-test-utils = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }28substrate-test-utils = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
2929
30[features]30[features]
38 "up-sponsorship/std",38 "up-sponsorship/std",
39 "sp-io/std",39 "sp-io/std",
40 "sp-std/std",40 "sp-std/std",
41 "sp-core/std",
41 "log/std",42 "log/std",
42]43]
43runtime-benchmarks = [44runtime-benchmarks = [
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
77use sp_runtime::ApplyExtrinsicResult;77use sp_runtime::ApplyExtrinsicResult;
78use sp_runtime::traits::{IdentifyAccount, Verify};78use sp_runtime::traits::{IdentifyAccount, Verify};
79use sp_runtime::{MultiSignature};79use sp_runtime::{MultiSignature};
80use sp_core::{H160};
8081
81pub trait ApplyExtrinsic<C: Dispatchable> {82pub trait ApplyCall<C: Dispatchable, SelfContainedSignedInfo> {
82 fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult;83 fn apply_call(signer: Address, function: C);
83}84}
8485
85/// The address format for describing accounts.86/// The address format for describing accounts.
125 /// Weight information for extrinsics in this pallet.126 /// Weight information for extrinsics in this pallet.
126 type WeightInfo: WeightInfo;127 type WeightInfo: WeightInfo;
127128
129 /// A type that allows you to use SignedExtra additional logic when dispatching call
128 type Executor: ApplyExtrinsic<<Self as Config>::Call>;130 type Executor: ApplyCall<<Self as system::Config>::Call, H160>;
129}131}
130132
131pub const MAX_TASK_ID_LENGTH_IN_BYTES: u8 = 16;133pub const MAX_TASK_ID_LENGTH_IN_BYTES: u8 = 16;
425 // - It is the first item in the schedule427 // - It is the first item in the schedule
426 if s.priority <= schedule::HARD_DEADLINE || cumulative_weight <= limit || order == 0 {428 if s.priority <= schedule::HARD_DEADLINE || cumulative_weight <= limit || order == 0 {
427429
428 // let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(430 let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(
429 // s.origin.clone()431 s.origin.clone()
430 // ).into();432 ).into();
431 // let sender = ensure_signed(origin).unwrap_or_default();433 // let sender = ensure_signed(origin).unwrap_or_default();
432 // let who_will_pay = T::SponsorshipHandler::get_sponsor(&sender, &s.call).unwrap_or(sender);434 // let who_will_pay = T::SponsorshipHandler::get_sponsor(&sender, &s.call).unwrap_or(sender);
433 // let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));435 // let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
434 // let r = s.call.clone().dispatch(sponsor.into());436 // let r = s.call.clone().dispatch(sponsor.into());
437
438
439 let sender = ensure_signed(origin).unwrap_or_default();
440 T::Executor::apply_call(sender.clone(), s.call.clone());
441
435 let maybe_id = s.maybe_id.clone();442 let maybe_id = s.maybe_id.clone();
436 if let Some((period, count)) = s.maybe_periodic {443 if let Some((period, count)) = s.maybe_periodic {
modifiedruntime/src/lib.rsdiffbeforeafterboth
17use sp_api::impl_runtime_apis;17use sp_api::impl_runtime_apis;
18use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};18use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};
19use sp_runtime::DispatchError;19use sp_runtime::DispatchError;
20use fp_self_contained::*;
21use sp_runtime::traits::{Applyable, Member};
20// #[cfg(any(feature = "std", test))]22// #[cfg(any(feature = "std", test))]
21// pub use sp_runtime::BuildStorage;23// pub use sp_runtime::BuildStorage;
2224
824 type ScheduleOrigin = EnsureSigned<AccountId>;826 type ScheduleOrigin = EnsureSigned<AccountId>;
825 type MaxScheduledPerBlock = MaxScheduledPerBlock;827 type MaxScheduledPerBlock = MaxScheduledPerBlock;
826 type WeightInfo = ();828 type WeightInfo = ();
827 type Executor = Ex;829 type Executor = Executor;
828}830}
829
830// pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
831// node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)
832// }
833831
834struct Ex;832pub struct Executor;
835impl<C: Dispatchable> ApplyExtrinsic<C> for Ex {833impl<C, SelfContainedSignedInfo> ApplyExtrinsic<C, SelfContainedSignedInfo> for Executor
834where
835 C: Member
836 + Dispatchable<Origin = Origin, Info = DispatchInfo>
837 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>
838 + GetDispatchInfo
839 + From<frame_system::Call<Runtime>>,
840 SelfContainedSignedInfo: Send + Sync + 'static,
841 Call: From<C> + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,
842{
836 fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult {843 fn apply_call(signer: Address, call: C) {
844 let dispatch_info = call.get_dispatch_info();
837 let extrinsic = sign(fp_self_contained::CheckedExtrinsic {845 let extrinsic = fp_self_contained::CheckedExtrinsic::<
846 AccountId,
847 Call,
848 SignedExtra,
849 SelfContainedSignedInfo,
850 > {
838 signed: fp_self_contained::CheckedSignature::SelfContained(None),851 signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Unsigned, // change to signer
839 function: function,852 function: call.into(),
840 });853 };
841854
842 Executive::apply_extrinsic(extrinsic)855 extrinsic.apply::<Runtime>(&dispatch_info, 0);
843 }856 }
844}857}
845858