difftreelog
Call executor added to scheduler pallet
in: master
3 files changed
pallets/scheduler/Cargo.tomldiffbeforeafterboth--- a/pallets/scheduler/Cargo.toml
+++ b/pallets/scheduler/Cargo.toml
@@ -20,11 +20,11 @@
sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
+sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring", branch = 'polkadot-v0.9.14' }
log = { version = "0.4.14", default-features = false }
[dev-dependencies]
-sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
substrate-test-utils = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }
[features]
@@ -38,6 +38,7 @@
"up-sponsorship/std",
"sp-io/std",
"sp-std/std",
+ "sp-core/std",
"log/std",
]
runtime-benchmarks = [
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -77,9 +77,10 @@
use sp_runtime::ApplyExtrinsicResult;
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_runtime::{MultiSignature};
+use sp_core::{H160};
-pub trait ApplyExtrinsic<C: Dispatchable> {
- fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult;
+pub trait ApplyCall<C: Dispatchable, SelfContainedSignedInfo> {
+ fn apply_call(signer: Address, function: C);
}
/// The address format for describing accounts.
@@ -125,7 +126,8 @@
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
- type Executor: ApplyExtrinsic<<Self as Config>::Call>;
+ /// A type that allows you to use SignedExtra additional logic when dispatching call
+ type Executor: ApplyCall<<Self as system::Config>::Call, H160>;
}
pub const MAX_TASK_ID_LENGTH_IN_BYTES: u8 = 16;
@@ -425,13 +427,18 @@
// - It is the first item in the schedule
if s.priority <= schedule::HARD_DEADLINE || cumulative_weight <= limit || order == 0 {
- // let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(
- // s.origin.clone()
- // ).into();
+ let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(
+ s.origin.clone()
+ ).into();
// let sender = ensure_signed(origin).unwrap_or_default();
// let who_will_pay = T::SponsorshipHandler::get_sponsor(&sender, &s.call).unwrap_or(sender);
// let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
// let r = s.call.clone().dispatch(sponsor.into());
+
+
+ let sender = ensure_signed(origin).unwrap_or_default();
+ T::Executor::apply_call(sender.clone(), s.call.clone());
+
let maybe_id = s.maybe_id.clone();
if let Some((period, count)) = s.maybe_periodic {
if count > 1 {
runtime/src/lib.rsdiffbeforeafterboth17use 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;2224824 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}829830// pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {831// node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)832// }833831834struct Ex;832pub struct Executor;835impl<C: Dispatchable> ApplyExtrinsic<C> for Ex {833impl<C, SelfContainedSignedInfo> ApplyExtrinsic<C, SelfContainedSignedInfo> for Executor834where835 C: Member836 + Dispatchable<Origin = Origin, Info = DispatchInfo>837 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>838 + GetDispatchInfo839 + 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 signer839 function: function,852 function: call.into(),840 });853 };841854842 Executive::apply_extrinsic(extrinsic)855 extrinsic.apply::<Runtime>(&dispatch_info, 0);843 }856 }844}857}845858