git.delta.rocks / unique-network / refs/commits / 5a3fe2c70832

difftreelog

source

runtime/common/scheduler.rs6.5 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::dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo};18use sp_runtime::{19	traits::{Dispatchable, Applyable, Member},20	generic::Era,21	transaction_validity::TransactionValidityError,22	DispatchErrorWithPostInfo,23};24use codec::Encode;25use crate::{Runtime, RuntimeCall, RuntimeOrigin};26use up_common::types::AccountId;27use fp_self_contained::SelfContainedCall;28use pallet_unique_scheduler_v2::DispatchCall;29use pallet_transaction_payment::ChargeTransactionPayment;3031// type SponsorshipChargeTransactionPayment =32// 	pallet_charge_transaction::ChargeTransactionPayment<Runtime>;3334/// The SignedExtension to the basic transaction logic.35pub type SignedExtraScheduler = (36	frame_system::CheckSpecVersion<Runtime>,37	frame_system::CheckGenesis<Runtime>,38	frame_system::CheckEra<Runtime>,39	frame_system::CheckNonce<Runtime>,40	frame_system::CheckWeight<Runtime>,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		ChargeTransactionPayment::<Runtime>::from(0),54	)55}5657pub struct SchedulerPaymentExecutor;5859impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>60	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor61where62	<T as frame_system::Config>::RuntimeCall: Member63		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>64		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>65		+ GetDispatchInfo66		+ From<frame_system::Call<Runtime>>,67	SelfContainedSignedInfo: Send + Sync + 'static,68	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>69		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>70		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,71	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,72{73	fn dispatch_call(74		signer: Option<<T as frame_system::Config>::AccountId>,75		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,76	) -> Result<77		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,78		TransactionValidityError,79	> {80		let dispatch_info = call.get_dispatch_info();81		let len = call.encoded_size();8283		let signed = match signer {84			Some(signer) => fp_self_contained::CheckedSignature::Signed(85				signer.clone().into(),86				get_signed_extras(signer.into()),87			),88			None => fp_self_contained::CheckedSignature::Unsigned,89		};9091		let extrinsic = fp_self_contained::CheckedExtrinsic::<92			AccountId,93			RuntimeCall,94			SignedExtraScheduler,95			SelfContainedSignedInfo,96		> {97			signed,98			function: call.into(),99		};100101		extrinsic.apply::<Runtime>(&dispatch_info, len)102	}103}104105// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>106// 	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor107// where108// 	<T as frame_system::Config>::Call: Member109// 		+ Dispatchable<Origin = Origin, Info = DispatchInfo>110// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>111// 		+ GetDispatchInfo112// 		+ From<frame_system::Call<Runtime>>,113// 	SelfContainedSignedInfo: Send + Sync + 'static,114// 	Call: From<<T as frame_system::Config>::Call>115// 		+ From<<T as pallet_unique_scheduler::Config>::Call>116// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,117// 	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,118// {119// 	fn dispatch_call(120// 		signer: Option<<T as frame_system::Config>::AccountId>,121// 		call: <T as pallet_unique_scheduler::Config>::Call,122// 	) -> Result<123// 		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,124// 		TransactionValidityError,125// 	> {126// 		let dispatch_info = call.get_dispatch_info();127// 		let len = call.encoded_size();128129// 		let signed = match signer {130// 			Some(signer) => fp_self_contained::CheckedSignature::Signed(131// 				signer.clone().into(),132// 				get_signed_extras(signer.into()),133// 			),134// 			None => fp_self_contained::CheckedSignature::Unsigned,135// 		};136137// 		let extrinsic = fp_self_contained::CheckedExtrinsic::<138// 			AccountId,139// 			Call,140// 			SignedExtraScheduler,141// 			SelfContainedSignedInfo,142// 		> {143// 			signed,144// 			function: call.into(),145// 		};146147// 		extrinsic.apply::<Runtime>(&dispatch_info, len)148// 	}149150// 	fn reserve_balance(151// 		id: [u8; 16],152// 		sponsor: <T as frame_system::Config>::AccountId,153// 		call: <T as pallet_unique_scheduler::Config>::Call,154// 		count: u32,155// 	) -> Result<(), DispatchError> {156// 		let dispatch_info = call.get_dispatch_info();157// 		let weight: Balance =158// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)159// 				.saturating_mul(count.into());160161// 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(162// 			&id,163// 			&(sponsor.into()),164// 			weight,165// 		)166// 	}167168// 	fn pay_for_call(169// 		id: [u8; 16],170// 		sponsor: <T as frame_system::Config>::AccountId,171// 		call: <T as pallet_unique_scheduler::Config>::Call,172// 	) -> Result<u128, DispatchError> {173// 		let dispatch_info = call.get_dispatch_info();174// 		let weight: Balance =175// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);176// 		Ok(177// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(178// 				&id,179// 				&(sponsor.into()),180// 				weight,181// 			),182// 		)183// 	}184185// 	fn cancel_reserve(186// 		id: [u8; 16],187// 		sponsor: <T as frame_system::Config>::AccountId,188// 	) -> Result<u128, DispatchError> {189// 		Ok(190// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(191// 				&id,192// 				&(sponsor.into()),193// 				u128::MAX,194// 			),195// 		)196// 	}197// }