difftreelog
Call executor added to scheduler pallet
in: master
3 files changed
pallets/scheduler/Cargo.tomldiffbeforeafterboth20sp-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' }222223sp-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 }252626[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' }292930[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 = [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.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -17,6 +17,8 @@
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};
use sp_runtime::DispatchError;
+use fp_self_contained::*;
+use sp_runtime::traits::{Applyable, Member};
// #[cfg(any(feature = "std", test))]
// pub use sp_runtime::BuildStorage;
@@ -824,22 +826,33 @@
type ScheduleOrigin = EnsureSigned<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
- type Executor = Ex;
+ type Executor = Executor;
}
-// 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 {
- fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult {
- let extrinsic = sign(fp_self_contained::CheckedExtrinsic {
- signed: fp_self_contained::CheckedSignature::SelfContained(None),
- function: function,
- });
+pub struct Executor;
+impl<C, SelfContainedSignedInfo> ApplyExtrinsic<C, SelfContainedSignedInfo> for Executor
+where
+ C: Member
+ + Dispatchable<Origin = Origin, Info = DispatchInfo>
+ + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>
+ + GetDispatchInfo
+ + From<frame_system::Call<Runtime>>,
+ SelfContainedSignedInfo: Send + Sync + 'static,
+ Call: From<C> + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,
+{
+ fn apply_call(signer: Address, call: C) {
+ let dispatch_info = call.get_dispatch_info();
+ let extrinsic = fp_self_contained::CheckedExtrinsic::<
+ AccountId,
+ Call,
+ SignedExtra,
+ SelfContainedSignedInfo,
+ > {
+ signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Unsigned, // change to signer
+ function: call.into(),
+ };
- Executive::apply_extrinsic(extrinsic)
+ extrinsic.apply::<Runtime>(&dispatch_info, 0);
}
}