git.delta.rocks / unique-network / refs/commits / f23307ebedee

difftreelog

source

pallets/maintenance/src/lib.rs2.2 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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;2021#[cfg(feature = "runtime-benchmarks")]22pub mod benchmarking;2324pub mod weights;2526#[frame_support::pallet]27pub mod pallet {28	use frame_support::pallet_prelude::*;29	use frame_system::pallet_prelude::*;30	use crate::weights::WeightInfo;3132	#[pallet::config]33	pub trait Config: frame_system::Config {34		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;35		type WeightInfo: WeightInfo;36	}3738	#[pallet::event]39	#[pallet::generate_deposit(pub(super) fn deposit_event)]40	pub enum Event<T: Config> {41		MaintenanceEnabled,42		MaintenanceDisabled,43	}4445	#[pallet::pallet]46	#[pallet::generate_store(pub(super) trait Store)]47	pub struct Pallet<T>(_);4849	#[pallet::storage]50	#[pallet::getter(fn is_enabled)]51	pub type Enabled<T> = StorageValue<_, bool, ValueQuery>;5253	#[pallet::error]54	pub enum Error<T> {}5556	#[pallet::call]57	impl<T: Config> Pallet<T> {58		#[pallet::call_index(0)]59		#[pallet::weight(<T as Config>::WeightInfo::enable())]60		pub fn enable(origin: OriginFor<T>) -> DispatchResult {61			ensure_root(origin)?;6263			<Enabled<T>>::set(true);6465			Self::deposit_event(Event::MaintenanceEnabled);6667			Ok(())68		}6970		#[pallet::call_index(1)]71		#[pallet::weight(<T as Config>::WeightInfo::disable())]72		pub fn disable(origin: OriginFor<T>) -> DispatchResult {73			ensure_root(origin)?;7475			<Enabled<T>>::set(false);7677			Self::deposit_event(Event::MaintenanceDisabled);7879			Ok(())80		}81	}82}