difftreelog
fix cargo fmt
in: master
2 files changed
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -456,8 +456,7 @@
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());
+ let ensured_origin = T::ScheduleOrigin::ensure_origin(scheduled_origin.into());
let r = match ensured_origin {
Ok(ScheduledEnsureOriginSuccess::Root) => {
@@ -471,7 +470,7 @@
Ok(ScheduledEnsureOriginSuccess::Unsigned) => {
// Unsigned version of the above
T::CallExecutor::dispatch_call(None, call.clone())
- },
+ }
Err(e) => Ok(Err(e.into())),
};
test-pallets/utils/src/lib.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;20use frame_support::pallet_prelude::*;21use frame_system::pallet_prelude::*;2223#[frame_support::pallet]24pub mod pallet {25 use frame_support::pallet_prelude::*;26 use frame_system::pallet_prelude::*;27 use pallet_unique_scheduler::{ScheduledId, Pallet as SchedulerPallet};2829 #[pallet::config]30 pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {31 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;32 }3334 #[pallet::event]35 #[pallet::generate_deposit(pub(super) fn deposit_event)]36 pub enum Event<T: Config> {37 ValueIsSet,38 ShouldRollback,39 }4041 #[pallet::pallet]42 #[pallet::generate_store(pub(super) trait Store)]43 pub struct Pallet<T>(_);4445 #[pallet::storage]46 #[pallet::getter(fn is_enabled)]47 pub type Enabled<T> = StorageValue<_, bool, ValueQuery>;4849 #[pallet::storage]50 #[pallet::getter(fn test_value)]51 pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;5253 #[pallet::error]54 pub enum Error<T> {55 TestPalletDisabled,56 TriggerRollback,57 }5859 #[pallet::call]60 impl<T: Config> Pallet<T> {61 #[pallet::weight(10_000)]62 pub fn enable(origin: OriginFor<T>) -> DispatchResult {63 ensure_root(origin)?;64 <Enabled<T>>::set(true);6566 Ok(())67 }6869 #[pallet::weight(10_000)]70 pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {71 Self::ensure_origin_and_enabled(origin)?;7273 <TestValue<T>>::put(value);7475 Self::deposit_event(Event::ValueIsSet);7677 Ok(())78 }7980 #[pallet::weight(10_000)]81 pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {82 Self::set_test_value(origin, value)?;8384 Self::deposit_event(Event::ShouldRollback);8586 Err(<Error<T>>::TriggerRollback.into())87 }8889 #[pallet::weight(10_000)]90 pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {91 Self::set_test_value(origin, <TestValue<T>>::get() + 1)92 }9394 #[pallet::weight(10_000)]95 pub fn self_canceling_inc(96 origin: OriginFor<T>,97 id: ScheduledId,98 max_test_value: u32,99 ) -> DispatchResult {100 Self::ensure_origin_and_enabled(origin.clone())?;101102 if <TestValue<T>>::get() < max_test_value {103 Self::inc_test_value(origin)?;104 } else {105 SchedulerPallet::<T>::cancel_named(origin, id)?;106 }107108 Ok(())109 }110111 #[pallet::weight(100_000_000)]112 pub fn just_take_fee(origin: OriginFor<T>) -> DispatchResult {113 Self::ensure_origin_and_enabled(origin)?;114 Ok(())115 }116 }117}118119impl<T: Config> Pallet<T> {120 fn ensure_origin_and_enabled(origin: OriginFor<T>) -> DispatchResult {121 ensure_signed(origin)?;122 <Enabled<T>>::get().then(|| ()).ok_or(<Error<T>>::TestPalletDisabled.into())123 }124}