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.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::{traits::{PrivilegeCmp, EnsureOrigin}, weights::Weight, parameter_types};18use frame_system::{EnsureRoot, RawOrigin};19use sp_runtime::Perbill;20use core::cmp::Ordering;21use codec::Decode;22use crate::{23 runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},24 Runtime, Call, Event, Origin, OriginCaller, Balances,25};26use pallet_unique_scheduler::ScheduledEnsureOriginSuccess;27use up_common::types::AccountId;2829parameter_types! {30 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *31 RuntimeBlockWeights::get().max_block;32 pub const MaxScheduledPerBlock: u32 = 50;3334 pub const NoPreimagePostponement: Option<u32> = Some(10);35 pub const Preimage: Option<u32> = Some(10);36}3738pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);39impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>40 EnsureOrigin<O> for EnsureSignedOrRoot<AccountId> {41 type Success = ScheduledEnsureOriginSuccess<AccountId>;42 fn try_origin(o: O) -> Result<Self::Success, O> {43 o.into().and_then(|o| match o {44 RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),45 RawOrigin::Signed(who) => Ok(ScheduledEnsureOriginSuccess::Signed(who)),46 r => Err(O::from(r)),47 })48 }49}5051pub struct EqualOrRootOnly;52impl PrivilegeCmp<OriginCaller> for EqualOrRootOnly {53 fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {54 use RawOrigin::*;5556 let left = left.clone().try_into().ok()?;57 let right = right.clone().try_into().ok()?;5859 match (left, right) {60 (Root, Root) => Some(Ordering::Equal),61 (Root, _) => Some(Ordering::Greater),62 (_, Root) => Some(Ordering::Less),63 lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal)64 }65 }66}6768impl pallet_unique_scheduler::Config for Runtime {69 type RuntimeEvent = RuntimeEvent;70 type RuntimeOrigin = RuntimeOrigin;71 type Currency = Balances;72 type PalletsOrigin = OriginCaller;73 type RuntimeCall = RuntimeCall;74 type MaximumWeight = MaximumSchedulerWeight;75 type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;76 type PrioritySetOrigin = EnsureRoot<AccountId>;77 type MaxScheduledPerBlock = MaxScheduledPerBlock;78 type WeightInfo = ();79 type CallExecutor = SchedulerPaymentExecutor;80 type OriginPrivilegeCmp = EqualOrRootOnly;81 type PreimageProvider = ();82 type NoPreimagePostponement = NoPreimagePostponement;83}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::{PrivilegeCmp, EnsureOrigin},19 weights::Weight,20 parameter_types,21};22use frame_system::{EnsureRoot, RawOrigin};23use sp_runtime::Perbill;24use core::cmp::Ordering;25use codec::Decode;26use crate::{27 runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},28 Runtime, Call, Event, Origin, OriginCaller, Balances,29};30use pallet_unique_scheduler::ScheduledEnsureOriginSuccess;31use up_common::types::AccountId;3233parameter_types! {34 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *35 RuntimeBlockWeights::get().max_block;36 pub const MaxScheduledPerBlock: u32 = 50;3738 pub const NoPreimagePostponement: Option<u32> = Some(10);39 pub const Preimage: Option<u32> = Some(10);40}4142pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);43impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>44 EnsureOrigin<O> for EnsureSignedOrRoot<AccountId>45{46 type Success = ScheduledEnsureOriginSuccess<AccountId>;47 fn try_origin(o: O) -> Result<Self::Success, O> {48 o.into().and_then(|o| match o {49 RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),50 RawOrigin::Signed(who) => Ok(ScheduledEnsureOriginSuccess::Signed(who)),51 r => Err(O::from(r)),52 })53 }54}5556pub struct EqualOrRootOnly;57impl PrivilegeCmp<OriginCaller> for EqualOrRootOnly {58 fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {59 use RawOrigin::*;6061 let left = left.clone().try_into().ok()?;62 let right = right.clone().try_into().ok()?;6364 match (left, right) {65 (Root, Root) => Some(Ordering::Equal),66 (Root, _) => Some(Ordering::Greater),67 (_, Root) => Some(Ordering::Less),68 lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal),69 }70 }71}7273impl pallet_unique_scheduler::Config for Runtime {74 type RuntimeEvent = RuntimeEvent;75 type RuntimeOrigin = RuntimeOrigin;76 type Currency = Balances;77 type PalletsOrigin = OriginCaller;78 type RuntimeCall = RuntimeCall;79 type MaximumWeight = MaximumSchedulerWeight;80 type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;81 type PrioritySetOrigin = EnsureRoot<AccountId>;82 type MaxScheduledPerBlock = MaxScheduledPerBlock;83 type WeightInfo = ();84 type CallExecutor = SchedulerPaymentExecutor;85 type OriginPrivilegeCmp = EqualOrRootOnly;86 type PreimageProvider = ();87 type NoPreimagePostponement = NoPreimagePostponement;88}runtime/common/scheduler.rsdiffbeforeafterboth--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -84,10 +84,13 @@
let len = call.encoded_size();
let signed = match signer {
- Some(signer) => fp_self_contained::CheckedSignature::Signed(signer.clone().into(), get_signed_extras(signer.into())),
+ Some(signer) => fp_self_contained::CheckedSignature::Signed(
+ signer.clone().into(),
+ get_signed_extras(signer.into()),
+ ),
None => fp_self_contained::CheckedSignature::Unsigned,
};
-
+
let extrinsic = fp_self_contained::CheckedExtrinsic::<
AccountId,
Call,