mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 07:37:57 +00:00
2009821cde
* Remove use of trait Store from staking pallet * Remove use of trait Store from bounties pallet * Remove use of trait Store from collective pallet * Remove use of trait Store from babe pallet * Remove use of trait Store from assets pallet * Remove use of trait Store from grandpa pallet * Remove use of trait Store from balances pallet * Remove use of trait Store from authorship pallet * Remove use of trait Store from authority-discovery pallet * Remove use of trait Store from atomic-swap pallet * Remove use of trait Store from sudo pallet * Remove use of trait Store from scheduler pallet * Remove use of trait Store from scored-pool pallet * Remove use of trait Store from society pallet * Remove use of trait Store from lottery pallet * Remove use of trait Store from executive pallet * Remove use of trait Store from democracy pallet * Remove use of trait Store from elections-phragmen pallet * Remove use of trait Store from indices pallet * Remove use of trait Store from identity pallet * Remove use of trait Store from multisig pallet * Remove use of trait Store from merkle-mountain-range pallet * Remove use of trait Store from im-online pallet * Remove use of trait Store from membership pallet * Remove use of trait Store from nicks pallet * Remove use of trait Store from session pallet * Remove use of trait Store from transaction-payment pallet * Remove use of trait Store from utility pallet * Remove use of trait Store from child-bounties pallet * Remove use of trait Store from nis pallet * Remove use of trait Store from nfts pallet * Remove use of trait Store from conviction-voting pallet * Remove use of trait Store from treasury pallet * Remove use of trait Store from vesting pallet * Remove use of trait Store from preimage pallet * Remove use of trait Store from uniques pallet * Remove use of trait Store from ranked-collective pallet * Remove use of trait Store from beefy-mmr pallet * Remove use of trait Store from referenda pallet * Remove use of trait Store from whitelist pallet * Remove use of trait Store from alliance pallet * Remove use of trait Store from nomination-pools pallet * Remove use of trait Store from state-trie-migration pallet * Remove use of trait Store from message-queue pallet * Remove use of trait Store from root-offences pallet * Remove use of trait Store from root-testing pallet * Remove use of trait Store from timestamps pallet * Remove use of trait Store from system pallet * Remove use of trait Store from offences pallet * Remove use of trait Store from recovery pallet * Remove use of trait Store from node-authorization pallet * Remove use of trait Store from proxy pallet * Remove use of trait Store from benchmarking pallet * Remove use of trait Store from bags-list pallet * Add deprecated warning in store_trait * Change warning message * Run cargo fmt * Fix warning and update tests * Remove unnecessary allow deprecated * Remove use of trait Store * Fix mismatch in expected output * Minor update to warning message for deprecation of generate_store with Store trait attribute * Fixes as per review comments * Fixes as per review suggestions * Remove use of Store trait from core-fellowship pallet * Fix type in store_trait.rs * Fixes as pre review comment
104 lines
3.7 KiB
Rust
104 lines
3.7 KiB
Rust
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
/// Edit this file to define custom logic or remove it if it is not needed.
|
|
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
|
|
/// <https://docs.substrate.io/reference/frame-pallets/>
|
|
pub use pallet::*;
|
|
|
|
#[cfg(test)]
|
|
mod mock;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
mod benchmarking;
|
|
|
|
#[frame_support::pallet]
|
|
pub mod pallet {
|
|
use frame_support::pallet_prelude::*;
|
|
use frame_system::pallet_prelude::*;
|
|
|
|
#[pallet::pallet]
|
|
pub struct Pallet<T>(_);
|
|
|
|
/// Configure the pallet by specifying the parameters and types on which it depends.
|
|
#[pallet::config]
|
|
pub trait Config: frame_system::Config {
|
|
/// Because this pallet emits events, it depends on the runtime's definition of an event.
|
|
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
|
}
|
|
|
|
// The pallet's runtime storage items.
|
|
// https://docs.substrate.io/main-docs/build/runtime-storage/
|
|
#[pallet::storage]
|
|
#[pallet::getter(fn something)]
|
|
// Learn more about declaring storage items:
|
|
// https://docs.substrate.io/main-docs/build/runtime-storage/#declaring-storage-items
|
|
pub type Something<T> = StorageValue<_, u32>;
|
|
|
|
// Pallets use events to inform users when important changes are made.
|
|
// https://docs.substrate.io/main-docs/build/events-errors/
|
|
#[pallet::event]
|
|
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
|
pub enum Event<T: Config> {
|
|
/// Event documentation should end with an array that provides descriptive names for event
|
|
/// parameters. [something, who]
|
|
SomethingStored { something: u32, who: T::AccountId },
|
|
}
|
|
|
|
// Errors inform users that something went wrong.
|
|
#[pallet::error]
|
|
pub enum Error<T> {
|
|
/// Error names should be descriptive.
|
|
NoneValue,
|
|
/// Errors should have helpful documentation associated with them.
|
|
StorageOverflow,
|
|
}
|
|
|
|
// Dispatchable functions allows users to interact with the pallet and invoke state changes.
|
|
// These functions materialize as "extrinsics", which are often compared to transactions.
|
|
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
|
|
#[pallet::call]
|
|
impl<T: Config> Pallet<T> {
|
|
/// An example dispatchable that takes a singles value as a parameter, writes the value to
|
|
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
|
|
#[pallet::call_index(0)]
|
|
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
|
|
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
|
|
// Check that the extrinsic was signed and get the signer.
|
|
// This function will return an error if the extrinsic is not signed.
|
|
// https://docs.substrate.io/main-docs/build/origins/
|
|
let who = ensure_signed(origin)?;
|
|
|
|
// Update storage.
|
|
<Something<T>>::put(something);
|
|
|
|
// Emit an event.
|
|
Self::deposit_event(Event::SomethingStored { something, who });
|
|
// Return a successful DispatchResultWithPostInfo
|
|
Ok(())
|
|
}
|
|
|
|
/// An example dispatchable that may throw a custom error.
|
|
#[pallet::call_index(1)]
|
|
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
|
|
pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
|
|
let _who = ensure_signed(origin)?;
|
|
|
|
// Read a value from storage.
|
|
match <Something<T>>::get() {
|
|
// Return an error if the value has not been set.
|
|
None => return Err(Error::<T>::NoneValue.into()),
|
|
Some(old) => {
|
|
// Increment the value read from storage; will error in the event of overflow.
|
|
let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;
|
|
// Update the value in storage with the incremented result.
|
|
<Something<T>>::put(new);
|
|
Ok(())
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|