git.delta.rocks / unique-network / refs/commits / 4ad9af73665a

difftreelog

source

runtime/common/scheduler.rs3.6 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::CheckSpecVersion<Runtime>,36	frame_system::CheckGenesis<Runtime>,37	frame_system::CheckEra<Runtime>,38	frame_system::CheckNonce<Runtime>,39	frame_system::CheckWeight<Runtime>,40	maintenance::CheckMaintenance,41	ChargeTransactionPayment<Runtime>,42);4344fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {45	(46		frame_system::CheckSpecVersion::<Runtime>::new(),47		frame_system::CheckGenesis::<Runtime>::new(),48		frame_system::CheckEra::<Runtime>::from(Era::Immortal),49		frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(50			from,51		)),52		frame_system::CheckWeight::<Runtime>::new(),53		maintenance::CheckMaintenance,54		ChargeTransactionPayment::<Runtime>::from(0),55	)56}5758pub struct SchedulerPaymentExecutor;5960impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>61	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor62where63	<T as frame_system::Config>::RuntimeCall: Member64		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>65		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>66		+ GetDispatchInfo67		+ From<frame_system::Call<Runtime>>,68	SelfContainedSignedInfo: Send + Sync + 'static,69	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>70		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>71		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,72	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,73{74	fn dispatch_call(75		signer: Option<<T as frame_system::Config>::AccountId>,76		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,77	) -> Result<78		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,79		TransactionValidityError,80	> {81		let dispatch_info = call.get_dispatch_info();82		let len = call.encoded_size();8384		let signed = match signer {85			Some(signer) => fp_self_contained::CheckedSignature::Signed(86				signer.clone().into(),87				get_signed_extras(signer.into()),88			),89			None => fp_self_contained::CheckedSignature::Unsigned,90		};9192		let extrinsic = fp_self_contained::CheckedExtrinsic::<93			AccountId,94			RuntimeCall,95			SignedExtraScheduler,96			SelfContainedSignedInfo,97		> {98			signed,99			function: call.into(),100		};101102		extrinsic.apply::<Runtime>(&dispatch_info, len)103	}104}