difftreelog
fix cargo fmt
in: master
3 files changed
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -197,7 +197,10 @@
use frame_support::{
dispatch::PostDispatchInfo,
pallet_prelude::*,
- traits::{schedule::{LookupError, LOWEST_PRIORITY}, PreimageProvider},
+ traits::{
+ schedule::{LookupError, LOWEST_PRIORITY},
+ PreimageProvider,
+ },
};
use frame_system::pallet_prelude::*;
@@ -239,7 +242,10 @@
type MaximumWeight: Get<Weight>;
/// Required origin to schedule or cancel calls.
- type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::RuntimeOrigin, Success = ScheduledEnsureOriginSuccess<Self::AccountId>>;
+ type ScheduleOrigin: EnsureOrigin<
+ <Self as system::Config>::RuntimeOrigin,
+ Success = ScheduledEnsureOriginSuccess<Self::AccountId>,
+ >;
/// Required origin to set/change calls' priority.
type PrioritySetOrigin: EnsureOrigin<<Self as system::Config>::RuntimeOrigin>;
@@ -326,7 +332,7 @@
/// Canceled some task.
Canceled { when: T::BlockNumber, index: u32 },
/// Scheduled task's priority has changed
- PriorityChanged {
+ PriorityChanged {
when: T::BlockNumber,
index: u32,
priority: schedule::Priority,
@@ -446,19 +452,21 @@
continue;
}
- let scheduled_origin = <<T as Config>::RuntimeOrigin as From<T::PalletsOrigin>>::from(s.origin.clone());
- let ensured_origin = T::ScheduleOrigin::ensure_origin(scheduled_origin.into()).unwrap();
+ let scheduled_origin =
+ <<T as Config>::RuntimeOrigin as From<T::PalletsOrigin>>::from(s.origin.clone());
+ let ensured_origin =
+ T::ScheduleOrigin::ensure_origin(scheduled_origin.into()).unwrap();
let r;
match ensured_origin {
ScheduledEnsureOriginSuccess::Root => {
r = Ok(call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()));
- },
+ }
ScheduledEnsureOriginSuccess::Signed(sender) => {
// Execute transaction via chain default pipeline
// That means dispatch will be processed like any user's extrinsic e.g. transaction fees will be taken
r = T::CallExecutor::dispatch_call(Some(sender), call.clone());
- },
+ }
ScheduledEnsureOriginSuccess::Unsigned => {
// Unsigned version of the above
r = T::CallExecutor::dispatch_call(None, call.clone());
@@ -776,12 +784,16 @@
}
s.priority = priority;
- Self::deposit_event(Event::PriorityChanged { when, index, priority });
+ Self::deposit_event(Event::PriorityChanged {
+ when,
+ index,
+ priority,
+ });
}
Ok(())
})
- },
- None => Err(Error::<T>::NotFound.into())
+ }
+ None => Err(Error::<T>::NotFound.into()),
}
}
}
runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -14,7 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{traits::{PrivilegeCmp, EnsureOrigin}, weights::Weight, parameter_types};
+use frame_support::{
+ traits::{PrivilegeCmp, EnsureOrigin},
+ weights::Weight,
+ parameter_types,
+};
use frame_system::{EnsureRoot, RawOrigin};
use sp_runtime::Perbill;
use core::cmp::Ordering;
@@ -37,7 +41,8 @@
pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);
impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>
- EnsureOrigin<O> for EnsureSignedOrRoot<AccountId> {
+ EnsureOrigin<O> for EnsureSignedOrRoot<AccountId>
+{
type Success = ScheduledEnsureOriginSuccess<AccountId>;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
@@ -60,7 +65,7 @@
(Root, Root) => Some(Ordering::Equal),
(Root, _) => Some(Ordering::Greater),
(_, Root) => Some(Ordering::Less),
- lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal)
+ lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal),
}
}
}
runtime/common/scheduler.rsdiffbeforeafterboth1// 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 weights::{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, Call, Origin, Balances};29use up_common::types::{AccountId, Balance};30use fp_self_contained::SelfContainedCall;31use pallet_unique_scheduler::DispatchCall;32use pallet_transaction_payment::ChargeTransactionPayment;3334type 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::Config, SelfContainedSignedInfo>63 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor64where65 <T as frame_system::Config>::Call: Member66 + Dispatchable<Origin = Origin, Info = DispatchInfo>67 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>68 + GetDispatchInfo69 + From<frame_system::Call<Runtime>>,70 SelfContainedSignedInfo: Send + Sync + 'static,71 Call: From<<T as frame_system::Config>::Call>72 + From<<T as pallet_unique_scheduler::Config>::Call>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::Config>::Call,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(signer.clone().into(), get_signed_extras(signer.into())),88 None => fp_self_contained::CheckedSignature::Unsigned,89 };90 91 let extrinsic = fp_self_contained::CheckedExtrinsic::<92 AccountId,93 Call,94 SignedExtraScheduler,95 SelfContainedSignedInfo,96 > {97 signed,98 function: call.into(),99 };100101 extrinsic.apply::<Runtime>(&dispatch_info, len)102 }103104 fn reserve_balance(105 id: [u8; 16],106 sponsor: <T as frame_system::Config>::AccountId,107 call: <T as pallet_unique_scheduler::Config>::Call,108 count: u32,109 ) -> Result<(), DispatchError> {110 let dispatch_info = call.get_dispatch_info();111 let weight: Balance =112 SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)113 .saturating_mul(count.into());114115 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(116 &id,117 &(sponsor.into()),118 weight,119 )120 }121122 fn pay_for_call(123 id: [u8; 16],124 sponsor: <T as frame_system::Config>::AccountId,125 call: <T as pallet_unique_scheduler::Config>::Call,126 ) -> Result<u128, DispatchError> {127 let dispatch_info = call.get_dispatch_info();128 let weight: Balance =129 SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);130 Ok(131 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(132 &id,133 &(sponsor.into()),134 weight,135 ),136 )137 }138139 fn cancel_reserve(140 id: [u8; 16],141 sponsor: <T as frame_system::Config>::AccountId,142 ) -> Result<u128, DispatchError> {143 Ok(144 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(145 &id,146 &(sponsor.into()),147 u128::MAX,148 ),149 )150 }151}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 weights::{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, Call, Origin, Balances};29use up_common::types::{AccountId, Balance};30use fp_self_contained::SelfContainedCall;31use pallet_unique_scheduler::DispatchCall;32use pallet_transaction_payment::ChargeTransactionPayment;3334type 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::Config, SelfContainedSignedInfo>63 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor64where65 <T as frame_system::Config>::Call: Member66 + Dispatchable<Origin = Origin, Info = DispatchInfo>67 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>68 + GetDispatchInfo69 + From<frame_system::Call<Runtime>>,70 SelfContainedSignedInfo: Send + Sync + 'static,71 Call: From<<T as frame_system::Config>::Call>72 + From<<T as pallet_unique_scheduler::Config>::Call>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::Config>::Call,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 Call,97 SignedExtraScheduler,98 SelfContainedSignedInfo,99 > {100 signed,101 function: call.into(),102 };103104 extrinsic.apply::<Runtime>(&dispatch_info, len)105 }106107 fn reserve_balance(108 id: [u8; 16],109 sponsor: <T as frame_system::Config>::AccountId,110 call: <T as pallet_unique_scheduler::Config>::Call,111 count: u32,112 ) -> Result<(), DispatchError> {113 let dispatch_info = call.get_dispatch_info();114 let weight: Balance =115 SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)116 .saturating_mul(count.into());117118 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(119 &id,120 &(sponsor.into()),121 weight,122 )123 }124125 fn pay_for_call(126 id: [u8; 16],127 sponsor: <T as frame_system::Config>::AccountId,128 call: <T as pallet_unique_scheduler::Config>::Call,129 ) -> Result<u128, DispatchError> {130 let dispatch_info = call.get_dispatch_info();131 let weight: Balance =132 SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);133 Ok(134 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(135 &id,136 &(sponsor.into()),137 weight,138 ),139 )140 }141142 fn cancel_reserve(143 id: [u8; 16],144 sponsor: <T as frame_system::Config>::AccountId,145 ) -> Result<u128, DispatchError> {146 Ok(147 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(148 &id,149 &(sponsor.into()),150 u128::MAX,151 ),152 )153 }154}