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
--- 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 = [
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
--- 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);
 	}
 }