--- a/pallets/scheduler/src/lib.rs +++ b/pallets/scheduler/src/lib.rs @@ -59,7 +59,7 @@ use codec::{Encode, Decode, Codec}; use sp_runtime::{ RuntimeDebug, - traits::{Zero, One, BadOrigin, Saturating, SignedExtension}, + traits::{One, BadOrigin, Saturating}, }; use frame_support::{ decl_module, decl_storage, decl_event, decl_error, @@ -73,8 +73,19 @@ }; use frame_system::{self as system, ensure_signed}; pub use weights::WeightInfo; -use up_sponsorship::SponsorshipHandler; use scale_info::TypeInfo; +use sp_runtime::ApplyExtrinsicResult; +use sp_runtime::traits::{IdentifyAccount, Verify}; +use sp_runtime::{MultiSignature}; + +pub trait ApplyExtrinsic { + fn apply_extrinsic(signer: Address, function: C) -> ApplyExtrinsicResult; +} + +/// The address format for describing accounts. +pub type Signature = MultiSignature; +pub type Address = sp_runtime::MultiAddress; +pub type AccountId = <::Signer as IdentifyAccount>::AccountId; /// Our pallet's configuration trait. All our types and constants go in here. If the /// pallet is dependent on specific other pallets, then their configuration traits @@ -110,15 +121,11 @@ /// The maximum number of scheduled calls in the queue for a single block. /// Not strictly enforced, but used for weight estimation. type MaxScheduledPerBlock: Get; - - /// Sponsoring function - type SponsorshipHandler: SponsorshipHandler::Call>; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; - /// Unchecked extrinsic type as expected by the runtime that uses this pallet. - type PaymentHandler: SignedExtension; + type Executor: ApplyExtrinsic<::Call>; } pub const MAX_TASK_ID_LENGTH_IN_BYTES: u8 = 16; @@ -492,20 +499,22 @@ let when = Self::resolve_time(when)?; let sender = ensure_signed( - <::Origin as From>::from(origin.clone()).into() - ).unwrap_or_default(); - let who_will_pay = T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender); + <::Origin as From>::from(origin.clone()).into(), + ) + .unwrap_or_default(); + let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender); let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay)); let r = call.clone().dispatch(sponsor.into()); //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call // sanitize maybe_periodic - let maybe_periodic = maybe_periodic - .filter(|p| p.1 > 1 && !p.0.is_zero()) - // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now. - .map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1)); - + let maybe_periodic = None; + // let maybe_periodic = maybe_periodic + // .filter(|p| p.1 > 1 && !p.0.is_zero()) + // // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now. + // .map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1)); + let s = Some(Scheduled { maybe_id, priority, @@ -609,7 +618,14 @@ return Err(Error::::FailedToSchedule.into()); } - let address = Self::do_schedule(Some(id.clone()), when, maybe_periodic, priority, origin, call)?; + let address = Self::do_schedule( + Some(id.clone()), + when, + maybe_periodic, + priority, + origin, + call, + )?; let (when, index) = address; Lookup::::insert(&id, &address); --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -54,6 +54,7 @@ WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, }, }; +use pallet_unq_scheduler::ApplyExtrinsic; use up_data_structs::*; // use pallet_contracts::weights::WeightInfo; // #[cfg(any(feature = "std", test))] @@ -822,9 +823,24 @@ type MaximumWeight = MaximumSchedulerWeight; type ScheduleOrigin = EnsureSigned; type MaxScheduledPerBlock = MaxScheduledPerBlock; - type SponsorshipHandler = SponsorshipHandler; type WeightInfo = (); - type PaymentHandler = pallet_charge_transaction::ChargeTransactionPayment; + type Executor = Ex; +} + +// 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, + }); + + Executive::apply_extrinsic(extrinsic) + } } impl pallet_evm_transaction_payment::Config for Runtime {