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, maintenance};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 maintenance::CheckMaintenance,45 ChargeTransactionPayment<Runtime>,46);4748fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {49 (50 frame_system::CheckSpecVersion::<Runtime>::new(),51 frame_system::CheckGenesis::<Runtime>::new(),52 frame_system::CheckEra::<Runtime>::from(Era::Immortal),53 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(54 from,55 )),56 frame_system::CheckWeight::<Runtime>::new(),57 maintenance::CheckMaintenance,58 ChargeTransactionPayment::<Runtime>::from(0),59 )60}6162pub struct SchedulerPaymentExecutor;6364impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>65 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor66where67 <T as frame_system::Config>::RuntimeCall: Member68 + Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>69 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>70 + GetDispatchInfo71 + From<frame_system::Call<Runtime>>,72 SelfContainedSignedInfo: Send + Sync + 'static,73 RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>74 + From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>75 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,76 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,77{78 fn dispatch_call(79 signer: Option<<T as frame_system::Config>::AccountId>,80 call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,81 ) -> Result<82 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,83 TransactionValidityError,84 > {85 let dispatch_info = call.get_dispatch_info();86 let len = call.encoded_size();8788 let signed = match signer {89 Some(signer) => fp_self_contained::CheckedSignature::Signed(90 signer.clone().into(),91 get_signed_extras(signer.into()),92 ),93 None => fp_self_contained::CheckedSignature::Unsigned,94 };9596 let extrinsic = fp_self_contained::CheckedExtrinsic::<97 AccountId,98 RuntimeCall,99 SignedExtraScheduler,100 SelfContainedSignedInfo,101 > {102 signed,103 function: call.into(),104 };105106 extrinsic.apply::<Runtime>(&dispatch_info, len)107 }108}109110// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>111// DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor112// where113// <T as frame_system::Config>::Call: Member114// + Dispatchable<Origin = Origin, Info = DispatchInfo>115// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>116// + GetDispatchInfo117// + From<frame_system::Call<Runtime>>,118// SelfContainedSignedInfo: Send + Sync + 'static,119// Call: From<<T as frame_system::Config>::Call>120// + From<<T as pallet_unique_scheduler::Config>::Call>121// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,122// sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,123// {124// fn dispatch_call(125// signer: Option<<T as frame_system::Config>::AccountId>,126// call: <T as pallet_unique_scheduler::Config>::Call,127// ) -> Result<128// Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,129// TransactionValidityError,130// > {131// let dispatch_info = call.get_dispatch_info();132// let len = call.encoded_size();133134// let signed = match signer {135// Some(signer) => fp_self_contained::CheckedSignature::Signed(136// signer.clone().into(),137// get_signed_extras(signer.into()),138// ),139// None => fp_self_contained::CheckedSignature::Unsigned,140// };141142// let extrinsic = fp_self_contained::CheckedExtrinsic::<143// AccountId,144// Call,145// SignedExtraScheduler,146// SelfContainedSignedInfo,147// > {148// signed,149// function: call.into(),150// };151152// extrinsic.apply::<Runtime>(&dispatch_info, len)153// }154155// fn reserve_balance(156// id: [u8; 16],157// sponsor: <T as frame_system::Config>::AccountId,158// call: <T as pallet_unique_scheduler::Config>::Call,159// count: u32,160// ) -> Result<(), DispatchError> {161// let dispatch_info = call.get_dispatch_info();162// let weight: Balance =163// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)164// .saturating_mul(count.into());165166// <Balances as NamedReservableCurrency<AccountId>>::reserve_named(167// &id,168// &(sponsor.into()),169// weight,170// )171// }172173// fn pay_for_call(174// id: [u8; 16],175// sponsor: <T as frame_system::Config>::AccountId,176// call: <T as pallet_unique_scheduler::Config>::Call,177// ) -> Result<u128, DispatchError> {178// let dispatch_info = call.get_dispatch_info();179// let weight: Balance =180// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);181// Ok(182// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(183// &id,184// &(sponsor.into()),185// weight,186// ),187// )188// }189190// fn cancel_reserve(191// id: [u8; 16],192// sponsor: <T as frame_system::Config>::AccountId,193// ) -> Result<u128, DispatchError> {194// Ok(195// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(196// &id,197// &(sponsor.into()),198// u128::MAX,199// ),200// )201// }202// }difftreelog
source
runtime/common/scheduler.rs6.6 KiBsourcehistory