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
before · pallets/scheduler/Cargo.toml
1[package]2name = "pallet-unq-scheduler"3version = "0.1.0"4authors = ["Unique Network <support@uniquenetwork.io>"]5edition = "2021"6license = "All Rights Reserved"7homepage = "https://unique.network"8repository = "https://github.com/UniqueNetwork/unique-chain"9description = "Unique Scheduler pallet"10readme = "README.md"1112[dependencies]13serde = { version = "1.0.130", default-features = false }14codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false }15scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }16frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }17frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }18sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }19sp-std = { 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' }2223up-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 }2526[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' }2930[features]31default = ["std"]32std = [33	"codec/std",34	"sp-runtime/std",35	"frame-benchmarking/std",36	"frame-support/std",37	"frame-system/std",38	"up-sponsorship/std",39	"sp-io/std",40	"sp-std/std",41	"log/std",42]43runtime-benchmarks = [44	"frame-benchmarking",45	"frame-support/runtime-benchmarks",46	"frame-system/runtime-benchmarks",47]48#try-runtime = ["frame-support/try-runtime"]
after · pallets/scheduler/Cargo.toml
1[package]2name = "pallet-unq-scheduler"3version = "0.1.0"4authors = ["Unique Network <support@uniquenetwork.io>"]5edition = "2021"6license = "All Rights Reserved"7homepage = "https://unique.network"8repository = "https://github.com/UniqueNetwork/unique-chain"9description = "Unique Scheduler pallet"10readme = "README.md"1112[dependencies]13serde = { version = "1.0.130", default-features = false }14codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false }15scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }16frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }17frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }18sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }19sp-std = { 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' }2223sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', 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' }25log = { version = "0.4.14", default-features = false }2627[dev-dependencies]28substrate-test-utils = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.14' }2930[features]31default = ["std"]32std = [33	"codec/std",34	"sp-runtime/std",35	"frame-benchmarking/std",36	"frame-support/std",37	"frame-system/std",38	"up-sponsorship/std",39	"sp-io/std",40	"sp-std/std",41	"sp-core/std",42	"log/std",43]44runtime-benchmarks = [45	"frame-benchmarking",46	"frame-support/runtime-benchmarks",47	"frame-system/runtime-benchmarks",48]49#try-runtime = ["frame-support/try-runtime"]
modifiedpallets/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 {
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);
 	}
 }