git.delta.rocks / unique-network / refs/commits / e2ee5ffc10f8

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 fp_self_contained::SelfContainedCall;18use frame_support::dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo};19use pallet_transaction_payment::ChargeTransactionPayment;20use pallet_unique_scheduler_v2::DispatchCall;21use parity_scale_codec::Encode;22use sp_runtime::{23	traits::{Applyable, Dispatchable, Member},24	transaction_validity::TransactionValidityError,25	DispatchErrorWithPostInfo,26};27use up_common::types::AccountId;2829use crate::{maintenance, Runtime, RuntimeCall, RuntimeOrigin};3031/// The SignedExtension to the basic transaction logic.32pub type SignedExtraScheduler = (33	frame_system::CheckWeight<Runtime>,34	maintenance::CheckMaintenance,35	ChargeTransactionPayment<Runtime>,36);3738fn get_signed_extras() -> SignedExtraScheduler {39	(40		frame_system::CheckWeight::<Runtime>::new(),41		maintenance::CheckMaintenance,42		ChargeTransactionPayment::<Runtime>::from(0),43	)44}4546pub struct SchedulerPaymentExecutor;4748impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>49	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor50where51	<T as frame_system::Config>::RuntimeCall: Member52		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>53		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>54		+ GetDispatchInfo55		+ From<frame_system::Call<Runtime>>,56	SelfContainedSignedInfo: Send + Sync + 'static,57	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>58		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>59		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,60	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,61{62	fn dispatch_call(63		signer: Option<<T as frame_system::Config>::AccountId>,64		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,65	) -> Result<66		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,67		TransactionValidityError,68	> {69		let dispatch_info = call.get_dispatch_info();70		let len = call.encoded_size();7172		let signed = match signer {73			Some(signer) => fp_self_contained::CheckedSignature::Signed(74				signer.clone().into(),75				get_signed_extras(),76			),77			None => fp_self_contained::CheckedSignature::Unsigned,78		};7980		let extrinsic = fp_self_contained::CheckedExtrinsic::<81			AccountId,82			RuntimeCall,83			SignedExtraScheduler,84			SelfContainedSignedInfo,85		> {86			signed,87			function: call.into(),88		};8990		extrinsic.apply::<Runtime>(&dispatch_info, len)91	}92}