git.delta.rocks / unique-network / refs/commits / 829f2bcebad6

difftreelog

source

runtime/common/scheduler.rs6.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	traits::NamedReservableCurrency,19	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},20};21use sp_runtime::{22	traits::{Dispatchable, Applyable, Member},23	generic::Era,24	transaction_validity::TransactionValidityError,25	DispatchErrorWithPostInfo, DispatchError,26};27use codec::Encode;28use crate::{Runtime, RuntimeCall, RuntimeOrigin, Balances};29use up_common::types::{AccountId, Balance};30use fp_self_contained::SelfContainedCall;31use pallet_unique_scheduler_v2::DispatchCall;32use pallet_transaction_payment::ChargeTransactionPayment;3334// type SponsorshipChargeTransactionPayment =35// 	pallet_charge_transaction::ChargeTransactionPayment<Runtime>;3637/// The SignedExtension to the basic transaction logic.38pub type SignedExtraScheduler = (39	frame_system::CheckSpecVersion<Runtime>,40	frame_system::CheckGenesis<Runtime>,41	frame_system::CheckEra<Runtime>,42	frame_system::CheckNonce<Runtime>,43	frame_system::CheckWeight<Runtime>,44	ChargeTransactionPayment<Runtime>,45);4647fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {48	(49		frame_system::CheckSpecVersion::<Runtime>::new(),50		frame_system::CheckGenesis::<Runtime>::new(),51		frame_system::CheckEra::<Runtime>::from(Era::Immortal),52		frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(53			from,54		)),55		frame_system::CheckWeight::<Runtime>::new(),56		ChargeTransactionPayment::<Runtime>::from(0),57	)58}5960pub struct SchedulerPaymentExecutor;6162impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>63	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor64where65	<T as frame_system::Config>::RuntimeCall: Member66		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>67		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>68		+ GetDispatchInfo69		+ From<frame_system::Call<Runtime>>,70	SelfContainedSignedInfo: Send + Sync + 'static,71	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>72		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>73		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,74	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,75{76	fn dispatch_call(77		signer: Option<<T as frame_system::Config>::AccountId>,78		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,79	) -> Result<80		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,81		TransactionValidityError,82	> {83		let dispatch_info = call.get_dispatch_info();84		let len = call.encoded_size();8586		let signed = match signer {87			Some(signer) => fp_self_contained::CheckedSignature::Signed(88				signer.clone().into(),89				get_signed_extras(signer.into()),90			),91			None => fp_self_contained::CheckedSignature::Unsigned,92		};9394		let extrinsic = fp_self_contained::CheckedExtrinsic::<95			AccountId,96			RuntimeCall,97			SignedExtraScheduler,98			SelfContainedSignedInfo,99		> {100			signed,101			function: call.into(),102		};103104		extrinsic.apply::<Runtime>(&dispatch_info, len)105	}106}107108109// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>110// 	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor111// where112// 	<T as frame_system::Config>::Call: Member113// 		+ Dispatchable<Origin = Origin, Info = DispatchInfo>114// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>115// 		+ GetDispatchInfo116// 		+ From<frame_system::Call<Runtime>>,117// 	SelfContainedSignedInfo: Send + Sync + 'static,118// 	Call: From<<T as frame_system::Config>::Call>119// 		+ From<<T as pallet_unique_scheduler::Config>::Call>120// 		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,121// 	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,122// {123// 	fn dispatch_call(124// 		signer: Option<<T as frame_system::Config>::AccountId>,125// 		call: <T as pallet_unique_scheduler::Config>::Call,126// 	) -> Result<127// 		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,128// 		TransactionValidityError,129// 	> {130// 		let dispatch_info = call.get_dispatch_info();131// 		let len = call.encoded_size();132133// 		let signed = match signer {134// 			Some(signer) => fp_self_contained::CheckedSignature::Signed(135// 				signer.clone().into(),136// 				get_signed_extras(signer.into()),137// 			),138// 			None => fp_self_contained::CheckedSignature::Unsigned,139// 		};140141// 		let extrinsic = fp_self_contained::CheckedExtrinsic::<142// 			AccountId,143// 			Call,144// 			SignedExtraScheduler,145// 			SelfContainedSignedInfo,146// 		> {147// 			signed,148// 			function: call.into(),149// 		};150151// 		extrinsic.apply::<Runtime>(&dispatch_info, len)152// 	}153154// 	fn reserve_balance(155// 		id: [u8; 16],156// 		sponsor: <T as frame_system::Config>::AccountId,157// 		call: <T as pallet_unique_scheduler::Config>::Call,158// 		count: u32,159// 	) -> Result<(), DispatchError> {160// 		let dispatch_info = call.get_dispatch_info();161// 		let weight: Balance =162// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)163// 				.saturating_mul(count.into());164165// 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(166// 			&id,167// 			&(sponsor.into()),168// 			weight,169// 		)170// 	}171172// 	fn pay_for_call(173// 		id: [u8; 16],174// 		sponsor: <T as frame_system::Config>::AccountId,175// 		call: <T as pallet_unique_scheduler::Config>::Call,176// 	) -> Result<u128, DispatchError> {177// 		let dispatch_info = call.get_dispatch_info();178// 		let weight: Balance =179// 			SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);180// 		Ok(181// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(182// 				&id,183// 				&(sponsor.into()),184// 				weight,185// 			),186// 		)187// 	}188189// 	fn cancel_reserve(190// 		id: [u8; 16],191// 		sponsor: <T as frame_system::Config>::AccountId,192// 	) -> Result<u128, DispatchError> {193// 		Ok(194// 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(195// 				&id,196// 				&(sponsor.into()),197// 				u128::MAX,198// 			),199// 		)200// 	}201// }