difftreelog
Scheduler uses default runtime logic when applying call instead dispatch method
in: master
2 files changed
pallets/scheduler/src/lib.rsdiffbeforeafterboth55mod benchmarking;55mod benchmarking;56pub mod weights;56pub mod weights;575758use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};58use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow, cmp};59use codec::{Encode, Decode, Codec};59use codec::{Encode, Decode, Codec};60use sp_runtime::{60use sp_runtime::{61 RuntimeDebug,61 RuntimeDebug,62 traits::{One, BadOrigin, Saturating},62 traits::{Zero, One, BadOrigin, Saturating},63};63};64use frame_support::{64use frame_support::{65 decl_module, decl_storage, decl_event, decl_error,65 decl_module, decl_storage, decl_event, decl_error,74use frame_system::{self as system, ensure_signed};74use frame_system::{self as system, ensure_signed};75pub use weights::WeightInfo;75pub use weights::WeightInfo;76use scale_info::TypeInfo;76use scale_info::TypeInfo;77use sp_runtime::ApplyExtrinsicResult;77use sp_core::{H160};78use sp_runtime::traits::{IdentifyAccount, Verify};78use sp_runtime::transaction_validity::TransactionValidityError;79use sp_runtime::{MultiSignature};79use frame_support::weights::PostDispatchInfo;80use sp_core::{H160};80use sp_runtime::DispatchErrorWithPostInfo;818182pub trait ApplyCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {82pub trait ApplyCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {83 fn apply_call(signer: T::AccountId, function: <T as Config>::Call); //<T as system::Config>83 fn apply_call(84 signer: T::AccountId,85 function: <T as Config>::Call,86 ) -> Result<87 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,88 TransactionValidityError,89 >;84}90}8586/// The address format for describing accounts.87//pub type Signature = MultiSignature;88// pub type Address = sp_runtime::MultiAddress<AccountId, ()>;89//pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;909191/// Our pallet's configuration trait. All our types and constants go in here. If the92/// Our pallet's configuration trait. All our types and constants go in here. If the92/// pallet is dependent on specific other pallets, then their configuration traits93/// pallet is dependent on specific other pallets, then their configuration traits437438438439439 let sender = ensure_signed(origin).unwrap_or_default();440 let sender = ensure_signed(origin).unwrap_or_default();440 T::Executor::apply_call(sender.clone(), s.call.clone());441 let apply_result = T::Executor::apply_call(sender.clone(), s.call.clone());441442442 let maybe_id = s.maybe_id.clone();443 let maybe_id = s.maybe_id.clone();443 if let Some((period, count)) = s.maybe_periodic {444 if let Some((period, count)) = s.maybe_periodic {509 <<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone()).into(),510 <<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone()).into(),510 )511 )511 .unwrap_or_default();512 .unwrap_or_default();512 let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender);513 //let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender);514 //let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));515 //let r = call.clone().dispatch(sponsor.into());516517 //let sender = ensure_signed(origin).unwrap_or_default();513 let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));518 let apply_result = T::Executor::apply_call(sender.clone(), call.clone());519520 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call521522 // sanitize maybe_periodic514 let r = call.clone().dispatch(sponsor.into());523 let maybe_periodic = maybe_periodic515524 .filter(|p| p.1 > 1 && !p.0.is_zero())516 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call525 // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.517526 .map(|(p, c)| (p, cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));518 // sanitize maybe_periodic519 let maybe_periodic = None;520 // let maybe_periodic = maybe_periodic521 // .filter(|p| p.1 > 1 && !p.0.is_zero())522 // // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.523 // .map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));524527525 let s = Some(Scheduled {528 let s = Some(Scheduled {526 maybe_id,529 maybe_id,578 if let Some(s) = scheduled {581 if let Some(s) = scheduled {579 if let Some(id) = s.maybe_id {582 if let Some(id) = s.maybe_id {580 Lookup::<T>::remove(id);583 Lookup::<T>::remove(id);584 // todo add back money / displace to another function for consistency581 }585 }582 Self::deposit_event(RawEvent::Canceled(when, index));586 Self::deposit_event(RawEvent::Canceled(when, index));583 Ok(())587 Ok(())runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -74,7 +74,9 @@
use sp_core::crypto::Public;
use sp_runtime::{
traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},
+ generic::Era,
transaction_validity::TransactionValidityError,
+ DispatchErrorWithPostInfo,
};
// pub use pallet_timestamp::Call as TimestampCall;
@@ -826,11 +828,25 @@
type ScheduleOrigin = EnsureSigned<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
- type Executor = Executor;
+ type Executor = SchedulerPaymentExecutor;
}
-pub struct Executor;
-impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo> ApplyCall<T, SelfContainedSignedInfo> for Executor
+fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {
+ (
+ frame_system::CheckSpecVersion::<Runtime>::new(),
+ frame_system::CheckGenesis::<Runtime>::new(),
+ frame_system::CheckEra::<Runtime>::from(Era::Immortal),
+ frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(
+ from,
+ )),
+ frame_system::CheckWeight::<Runtime>::new(),
+ pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
+ )
+}
+
+pub struct SchedulerPaymentExecutor;
+impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo>
+ ApplyCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor
where
<T as frame_system::Config>::Call: Member
+ Dispatchable<Origin = Origin, Info = DispatchInfo>
@@ -838,9 +854,18 @@
+ GetDispatchInfo
+ From<frame_system::Call<Runtime>>,
SelfContainedSignedInfo: Send + Sync + 'static,
- Call: From<<T as frame_system::Config>::Call> + From<<T as pallet_unq_scheduler::Config>::Call> + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>
+ Call: From<<T as frame_system::Config>::Call>
+ + From<<T as pallet_unq_scheduler::Config>::Call>
+ + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,
+ sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,
{
- fn apply_call(signer: <T as frame_system::Config>::AccountId, call: <T as pallet_unq_scheduler::Config>::Call) {
+ fn apply_call(
+ signer: <T as frame_system::Config>::AccountId,
+ call: <T as pallet_unq_scheduler::Config>::Call,
+ ) -> Result<
+ Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
+ TransactionValidityError,
+ > {
let dispatch_info = call.get_dispatch_info();
let extrinsic = fp_self_contained::CheckedExtrinsic::<
AccountId,
@@ -848,11 +873,14 @@
SignedExtra,
SelfContainedSignedInfo,
> {
- signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Unsigned, // change to signer
+ signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(
+ signer.clone().into(),
+ get_signed_extras(signer.into()),
+ ),
function: call.into(),
};
- extrinsic.apply::<Runtime>(&dispatch_info, 0);
+ extrinsic.apply::<Runtime>(&dispatch_info, 0)
}
}