git.delta.rocks / unique-network / refs/commits / 448629b28a12

difftreelog

source

runtime/common/scheduler.rs3.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},19};20use sp_runtime::{21	traits::{Dispatchable, Applyable, Member},22	transaction_validity::TransactionValidityError,23	DispatchErrorWithPostInfo,24};25use codec::Encode;26use crate::{Runtime, RuntimeCall, RuntimeOrigin, maintenance};27use up_common::types::AccountId;28use fp_self_contained::SelfContainedCall;29use pallet_unique_scheduler_v2::DispatchCall;30use pallet_transaction_payment::ChargeTransactionPayment;3132/// The SignedExtension to the basic transaction logic.33pub type SignedExtraScheduler = (34	frame_system::CheckWeight<Runtime>,35	maintenance::CheckMaintenance,36	ChargeTransactionPayment<Runtime>,37);3839fn get_signed_extras() -> SignedExtraScheduler {40	(41		frame_system::CheckWeight::<Runtime>::new(),42		maintenance::CheckMaintenance,43		ChargeTransactionPayment::<Runtime>::from(0),44	)45}4647pub struct SchedulerPaymentExecutor;4849impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>50	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor51where52	<T as frame_system::Config>::RuntimeCall: Member53		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>54		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>55		+ GetDispatchInfo56		+ From<frame_system::Call<Runtime>>,57	SelfContainedSignedInfo: Send + Sync + 'static,58	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>59		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>60		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,61	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,62{63	fn dispatch_call(64		signer: Option<<T as frame_system::Config>::AccountId>,65		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,66	) -> Result<67		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,68		TransactionValidityError,69	> {70		let dispatch_info = call.get_dispatch_info();71		let len = call.encoded_size();7273		let signed = match signer {74			Some(signer) => fp_self_contained::CheckedSignature::Signed(75				signer.clone().into(),76				get_signed_extras(),77			),78			None => fp_self_contained::CheckedSignature::Unsigned,79		};8081		let extrinsic = fp_self_contained::CheckedExtrinsic::<82			AccountId,83			RuntimeCall,84			SignedExtraScheduler,85			SelfContainedSignedInfo,86		> {87			signed,88			function: call.into(),89		};9091		extrinsic.apply::<Runtime>(&dispatch_info, len)92	}93}