From 1c23d3abc9fc33a0216eea0ad5260e5d2d79af15 Mon Sep 17 00:00:00 2001 From: str-mv Date: Wed, 09 Feb 2022 16:15:26 +0000 Subject: [PATCH] Call executor added to scheduler pallet --- --- 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 = [ --- 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 { - fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult; +pub trait ApplyCall { + 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<::Call>; + /// A type that allows you to use SignedExtra additional logic when dispatching call + type Executor: ApplyCall<::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 = <::Origin as From>::from( - // s.origin.clone() - // ).into(); + let origin = <::Origin as From>::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 { --- 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; 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 ApplyExtrinsic 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 ApplyExtrinsic for Executor +where + C: Member + + Dispatchable + + SelfContainedCall + + GetDispatchInfo + + From>, + SelfContainedSignedInfo: Send + Sync + 'static, + Call: From + SelfContainedCall, +{ + 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::::Unsigned, // change to signer + function: call.into(), + }; - Executive::apply_extrinsic(extrinsic) + extrinsic.apply::(&dispatch_info, 0); } } -- gitstuff