git.delta.rocks / unique-network / refs/commits / 96d265cead38

difftreelog

source

runtime/common/scheduler.rs3.2 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	generic::Era,23	transaction_validity::TransactionValidityError,24	DispatchErrorWithPostInfo,25};26use codec::Encode;27use crate::{Runtime, RuntimeCall, RuntimeOrigin, maintenance};28use up_common::types::AccountId;29use fp_self_contained::SelfContainedCall;30use pallet_unique_scheduler_v2::DispatchCall;31use pallet_transaction_payment::ChargeTransactionPayment;3233/// The SignedExtension to the basic transaction logic.34pub type SignedExtraScheduler = (35	frame_system::CheckWeight<Runtime>,36	maintenance::CheckMaintenance,37	ChargeTransactionPayment<Runtime>,38);3940fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {41	(42		frame_system::CheckWeight::<Runtime>::new(),43		maintenance::CheckMaintenance,44		ChargeTransactionPayment::<Runtime>::from(0),45	)46}4748pub struct SchedulerPaymentExecutor;4950impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>51	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor52where53	<T as frame_system::Config>::RuntimeCall: Member54		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>55		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>56		+ GetDispatchInfo57		+ From<frame_system::Call<Runtime>>,58	SelfContainedSignedInfo: Send + Sync + 'static,59	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>60		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>61		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,62	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,63{64	fn dispatch_call(65		signer: Option<<T as frame_system::Config>::AccountId>,66		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,67	) -> Result<68		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,69		TransactionValidityError,70	> {71		let dispatch_info = call.get_dispatch_info();72		let len = call.encoded_size();7374		let signed = match signer {75			Some(signer) => fp_self_contained::CheckedSignature::Signed(76				signer.clone().into(),77				get_signed_extras(signer.into()),78			),79			None => fp_self_contained::CheckedSignature::Unsigned,80		};8182		let extrinsic = fp_self_contained::CheckedExtrinsic::<83			AccountId,84			RuntimeCall,85			SignedExtraScheduler,86			SelfContainedSignedInfo,87		> {88			signed,89			function: call.into(),90		};9192		extrinsic.apply::<Runtime>(&dispatch_info, len)93	}94}