mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Migrate all doc to new pallet macro (#10187)
* Migrate all doc to new pallet macro Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix indent Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix format Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
@@ -16,7 +16,7 @@ mod benchmarking;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
/// Configure the pallet by specifying the parameters and types on which it depends.
|
||||
|
||||
@@ -69,35 +69,43 @@ Import the Assets module and types and derive your runtime's configuration trait
|
||||
|
||||
```rust
|
||||
use pallet_assets as assets;
|
||||
use frame_support::{decl_module, dispatch, ensure};
|
||||
use frame_system::ensure_signed;
|
||||
use sp_runtime::ArithmeticError;
|
||||
|
||||
pub trait Config: assets::Config { }
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
pub fn issue_token_airdrop(origin) -> dispatch::DispatchResult {
|
||||
let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
const ACCOUNT_ALICE: u64 = 1;
|
||||
const ACCOUNT_BOB: u64 = 2;
|
||||
const COUNT_AIRDROP_RECIPIENTS: u64 = 2;
|
||||
const TOKENS_FIXED_SUPPLY: u64 = 100;
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + assets::Config {}
|
||||
|
||||
ensure!(!COUNT_AIRDROP_RECIPIENTS.is_zero(), ArithmeticError::DivisionByZero);
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub fn issue_token_airdrop(origin: OriginFor<T>) -> DispatchResult {
|
||||
let sender = ensure_signed(origin)?;
|
||||
|
||||
let asset_id = Self::next_asset_id();
|
||||
const ACCOUNT_ALICE: u64 = 1;
|
||||
const ACCOUNT_BOB: u64 = 2;
|
||||
const COUNT_AIRDROP_RECIPIENTS: u64 = 2;
|
||||
const TOKENS_FIXED_SUPPLY: u64 = 100;
|
||||
|
||||
<NextAssetId<T>>::mutate(|asset_id| *asset_id += 1);
|
||||
<Balances<T>>::insert((asset_id, &ACCOUNT_ALICE), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
|
||||
<Balances<T>>::insert((asset_id, &ACCOUNT_BOB), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
|
||||
<TotalSupply<T>>::insert(asset_id, TOKENS_FIXED_SUPPLY);
|
||||
ensure!(!COUNT_AIRDROP_RECIPIENTS.is_zero(), ArithmeticError::DivisionByZero);
|
||||
|
||||
Self::deposit_event(RawEvent::Issued(asset_id, sender, TOKENS_FIXED_SUPPLY));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
let asset_id = Self::next_asset_id();
|
||||
|
||||
<NextAssetId<T>>::mutate(|asset_id| *asset_id += 1);
|
||||
<Balances<T>>::insert((asset_id, &ACCOUNT_ALICE), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
|
||||
<Balances<T>>::insert((asset_id, &ACCOUNT_BOB), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
|
||||
<TotalSupply<T>>::insert(asset_id, TOKENS_FIXED_SUPPLY);
|
||||
|
||||
Self::deposit_event(Event::Issued(asset_id, sender, TOKENS_FIXED_SUPPLY));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -140,6 +140,15 @@ mod types;
|
||||
pub use types::*;
|
||||
|
||||
use codec::HasCompact;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{
|
||||
AtLeast32BitUnsigned, Bounded, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero,
|
||||
},
|
||||
ArithmeticError, TokenError,
|
||||
};
|
||||
use sp_std::{borrow::Borrow, convert::TryInto, prelude::*};
|
||||
|
||||
use frame_support::{
|
||||
dispatch::{DispatchError, DispatchResult},
|
||||
ensure,
|
||||
@@ -151,16 +160,6 @@ use frame_support::{
|
||||
},
|
||||
};
|
||||
use frame_system::Config as SystemConfig;
|
||||
use sp_runtime::{
|
||||
traits::{
|
||||
AtLeast32BitUnsigned, Bounded, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero,
|
||||
},
|
||||
ArithmeticError, TokenError,
|
||||
};
|
||||
use sp_std::{borrow::Borrow, prelude::*};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use frame_support::traits::GenesisBuild;
|
||||
|
||||
pub use pallet::*;
|
||||
pub use weights::WeightInfo;
|
||||
@@ -168,7 +167,7 @@ pub use weights::WeightInfo;
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use super::*;
|
||||
use crate as pallet_assets;
|
||||
|
||||
use frame_support::{construct_runtime, parameter_types};
|
||||
use frame_support::{construct_runtime, parameter_types, traits::GenesisBuild};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
|
||||
@@ -52,9 +52,8 @@ mod mock_democracy {
|
||||
pub use pallet::*;
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use frame_support::{pallet_prelude::*, traits::EnsureOrigin};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use sp_runtime::DispatchResult;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
|
||||
@@ -240,16 +240,9 @@ enum Releases {
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{
|
||||
dispatch::DispatchResultWithPostInfo,
|
||||
pallet_prelude::*,
|
||||
traits::EnsureOrigin,
|
||||
weights::{DispatchClass, Pays},
|
||||
Parameter,
|
||||
};
|
||||
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};
|
||||
use sp_runtime::DispatchResult;
|
||||
use super::{DispatchResult, *};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
|
||||
@@ -26,21 +26,29 @@ It is submitted as an Unsigned Transaction via off-chain workers.
|
||||
## Usage
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch};
|
||||
use frame_system::ensure_signed;
|
||||
use pallet_im_online::{self as im_online};
|
||||
|
||||
pub trait Config: im_online::Config {}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[weight = 0]
|
||||
pub fn is_online(origin, authority_index: u32) -> dispatch::DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
let _is_online = <im_online::Module<T>>::is_online(authority_index);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + im_online::Config {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn is_online(origin: OriginFor<T>, authority_index: u32) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
let _is_online = <im_online::Pallet<T>>::is_online(authority_index);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
//! # I'm online Pallet
|
||||
//!
|
||||
//! If the local node is a validator (i.e. contains an authority key), this module
|
||||
//! If the local node is a validator (i.e. contains an authority key), this pallet
|
||||
//! gossips a heartbeat transaction with each new session. The heartbeat functions
|
||||
//! as a simple mechanism to signal that the node is online in the current era.
|
||||
//!
|
||||
//! Received heartbeats are tracked for one era and reset with each new era. The
|
||||
//! module exposes two public functions to query if a heartbeat has been received
|
||||
//! pallet exposes two public functions to query if a heartbeat has been received
|
||||
//! in the current era or session.
|
||||
//!
|
||||
//! The heartbeat is a signed transaction, which was signed using the session key
|
||||
@@ -43,16 +43,24 @@
|
||||
//! ## Usage
|
||||
//!
|
||||
//! ```
|
||||
//! use frame_support::{decl_module, dispatch};
|
||||
//! use frame_system::ensure_signed;
|
||||
//! use pallet_im_online::{self as im_online};
|
||||
//!
|
||||
//! pub trait Config: im_online::Config {}
|
||||
//! #[frame_support::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use super::*;
|
||||
//! use frame_support::pallet_prelude::*;
|
||||
//! use frame_system::pallet_prelude::*;
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
//! #[weight = 0]
|
||||
//! pub fn is_online(origin, authority_index: u32) -> dispatch::DispatchResult {
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//!
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config + im_online::Config {}
|
||||
//!
|
||||
//! #[pallet::call]
|
||||
//! impl<T: Config> Pallet<T> {
|
||||
//! #[pallet::weight(0)]
|
||||
//! pub fn is_online(origin: OriginFor<T>, authority_index: u32) -> DispatchResult {
|
||||
//! let _sender = ensure_signed(origin)?;
|
||||
//! let _is_online = <im_online::Pallet<T>>::is_online(authority_index);
|
||||
//! Ok(())
|
||||
@@ -64,7 +72,7 @@
|
||||
//!
|
||||
//! ## Dependencies
|
||||
//!
|
||||
//! This module depends on the [Session module](../pallet_session/index.html).
|
||||
//! This pallet depends on the [Session pallet](../pallet_session/index.html).
|
||||
|
||||
// Ensure we're `no_std` when compiling for Wasm.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
@@ -302,15 +310,8 @@ type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Config>::B
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{pallet_prelude::*, traits::Get, Parameter};
|
||||
use frame_system::{ensure_none, pallet_prelude::*};
|
||||
use sp_runtime::{
|
||||
traits::{MaybeSerializeDeserialize, Member},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
|
||||
ValidTransaction,
|
||||
},
|
||||
};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
|
||||
@@ -115,8 +115,8 @@ impl<T: Config> ValidateCall<T> for Pallet<T> {
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{pallet_prelude::*, traits::EnsureOrigin, weights::Weight, Parameter};
|
||||
use frame_system::{ensure_signed, pallet_prelude::*};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
|
||||
@@ -52,12 +52,8 @@ type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{
|
||||
ensure,
|
||||
pallet_prelude::*,
|
||||
traits::{EnsureOrigin, Get},
|
||||
};
|
||||
use frame_system::{ensure_signed, pallet_prelude::*};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
|
||||
@@ -52,7 +52,7 @@ pub use weights::WeightInfo;
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
|
||||
@@ -20,18 +20,28 @@ the system trait.
|
||||
### Example - Get random seed for the current block
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch, traits::Randomness};
|
||||
use frame_support::traits::Randomness;
|
||||
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[weight = 0]
|
||||
pub fn random_module_example(origin) -> dispatch::DispatchResult {
|
||||
let _random_value = <pallet_randomness_collective_flip::Module<T>>::random(&b"my context"[..]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + pallet_randomness_collective_flip::Config {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn random_module_example(origin: OriginFor<T>) -> DispatchResult {
|
||||
let _random_value = <pallet_randomness_collective_flip::Pallet<T>>::random(&b"my context"[..]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # Randomness Module
|
||||
//! # Randomness Pallet
|
||||
//!
|
||||
//! The Randomness Collective Flip module provides a [`random`](./struct.Module.html#method.random)
|
||||
//! The Randomness Collective Flip pallet provides a [`random`](./struct.Module.html#method.random)
|
||||
//! function that generates low-influence random values based on the block hashes from the previous
|
||||
//! `81` blocks. Low-influence randomness can be useful when defending against relatively weak
|
||||
//! adversaries. Using this pallet as a randomness source is advisable primarily in low-security
|
||||
@@ -31,7 +31,7 @@
|
||||
//!
|
||||
//! ### Prerequisites
|
||||
//!
|
||||
//! Import the Randomness Collective Flip module and derive your module's configuration trait from
|
||||
//! Import the Randomness Collective Flip pallet and derive your pallet's configuration trait from
|
||||
//! the system trait.
|
||||
//!
|
||||
//! ### Example - Get random seed for the current block
|
||||
@@ -41,9 +41,9 @@
|
||||
//!
|
||||
//! #[frame_support::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use super::*;
|
||||
//! use frame_support::pallet_prelude::*;
|
||||
//! use frame_system::pallet_prelude::*;
|
||||
//! use super::*;
|
||||
//!
|
||||
//! #[pallet::pallet]
|
||||
//! #[pallet::generate_store(pub(super) trait Store)]
|
||||
|
||||
@@ -206,8 +206,8 @@ pub struct RecoveryConfig<BlockNumber, Balance, AccountId> {
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{ensure, pallet_prelude::*, traits::Get, Parameter};
|
||||
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use sp_runtime::ArithmeticError;
|
||||
|
||||
#[pallet::pallet]
|
||||
|
||||
@@ -37,26 +37,33 @@ by the next highest scoring candidate in the pool, if available.
|
||||
## Usage
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch};
|
||||
use frame_system::ensure_signed;
|
||||
use pallet_scored_pool::{self as scored_pool};
|
||||
|
||||
pub trait Config: scored_pool::Config {}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[weight = 0]
|
||||
pub fn candidate(origin) -> dispatch::DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
let _ = <scored_pool::Module<T>>::submit_candidacy(
|
||||
T::Origin::from(Some(who.clone()).into())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + scored_pool::Config {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn candidate(origin: OriginFor<T>) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
let _ = <scored_pool::Pallet<T>>::submit_candidacy(
|
||||
T::Origin::from(Some(who.clone()).into())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
@@ -54,16 +54,24 @@
|
||||
//! ## Usage
|
||||
//!
|
||||
//! ```
|
||||
//! use frame_support::{decl_module, dispatch};
|
||||
//! use frame_system::ensure_signed;
|
||||
//! use pallet_scored_pool::{self as scored_pool};
|
||||
//!
|
||||
//! pub trait Config: scored_pool::Config {}
|
||||
//! #[frame_support::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use super::*;
|
||||
//! use frame_support::pallet_prelude::*;
|
||||
//! use frame_system::pallet_prelude::*;
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
//! #[weight = 0]
|
||||
//! pub fn candidate(origin) -> dispatch::DispatchResult {
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//!
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config + scored_pool::Config {}
|
||||
//!
|
||||
//! #[pallet::call]
|
||||
//! impl<T: Config> Pallet<T> {
|
||||
//! #[pallet::weight(0)]
|
||||
//! pub fn candidate(origin: OriginFor<T>) -> DispatchResult {
|
||||
//! let who = ensure_signed(origin)?;
|
||||
//!
|
||||
//! let _ = <scored_pool::Pallet<T>>::submit_candidacy(
|
||||
@@ -116,9 +124,8 @@ enum ChangeReceiver {
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{pallet_prelude::*, traits::EnsureOrigin, weights::Weight};
|
||||
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};
|
||||
use sp_runtime::traits::MaybeSerializeDeserialize;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
|
||||
@@ -133,19 +133,27 @@ The Staking module contains many public storage items and (im)mutable functions.
|
||||
### Example: Rewarding a validator by id.
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch};
|
||||
use frame_system::ensure_signed;
|
||||
use pallet_staking::{self as staking};
|
||||
|
||||
pub trait Config: staking::Config {}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + staking::Config {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Reward a validator.
|
||||
#[weight = 0]
|
||||
pub fn reward_myself(origin) -> dispatch::DispatchResult {
|
||||
#[pallet::weight(0)]
|
||||
pub fn reward_myself(origin: OriginFor<T>) -> DispatchResult {
|
||||
let reported = ensure_signed(origin)?;
|
||||
<staking::Module<T>>::reward_by_ids(vec![(reported, 10)]);
|
||||
<staking::Pallet<T>>::reward_by_ids(vec![(reported, 10)]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,17 +157,25 @@
|
||||
//! ### Example: Rewarding a validator by id.
|
||||
//!
|
||||
//! ```
|
||||
//! use frame_support::{decl_module, dispatch};
|
||||
//! use frame_system::ensure_signed;
|
||||
//! use pallet_staking::{self as staking};
|
||||
//!
|
||||
//! pub trait Config: staking::Config {}
|
||||
//! #[frame_support::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use super::*;
|
||||
//! use frame_support::pallet_prelude::*;
|
||||
//! use frame_system::pallet_prelude::*;
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//!
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config + staking::Config {}
|
||||
//!
|
||||
//! #[pallet::call]
|
||||
//! impl<T: Config> Pallet<T> {
|
||||
//! /// Reward a validator.
|
||||
//! #[weight = 0]
|
||||
//! pub fn reward_myself(origin) -> dispatch::DispatchResult {
|
||||
//! #[pallet::weight(0)]
|
||||
//! pub fn reward_myself(origin: OriginFor<T>) -> DispatchResult {
|
||||
//! let reported = ensure_signed(origin)?;
|
||||
//! <staking::Pallet<T>>::reward_by_ids(vec![(reported, 10)]);
|
||||
//! Ok(())
|
||||
|
||||
@@ -35,15 +35,22 @@ Learn more about privileged functions and `Root` origin in the [`Origin`] type d
|
||||
This is an example of a module that exposes a privileged function:
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch};
|
||||
use frame_system::ensure_root;
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[weight = 0]
|
||||
pub fn privileged_function(origin) -> dispatch::DispatchResult {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn privileged_function(origin: OriginFor<T>) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
|
||||
// do something...
|
||||
|
||||
@@ -52,28 +52,27 @@
|
||||
//! This is an example of a pallet that exposes a privileged function:
|
||||
//!
|
||||
//! ```
|
||||
//!
|
||||
//! #[frame_support::pallet]
|
||||
//! pub mod logger {
|
||||
//! pub mod pallet {
|
||||
//! use super::*;
|
||||
//! use frame_support::pallet_prelude::*;
|
||||
//! use frame_system::pallet_prelude::*;
|
||||
//! use super::*;
|
||||
//!
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//!
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config {}
|
||||
//!
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(PhantomData<T>);
|
||||
//!
|
||||
//! #[pallet::call]
|
||||
//! impl<T: Config> Pallet<T> {
|
||||
//! #[pallet::weight(0)]
|
||||
//! pub fn privileged_function(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
//! pub fn privileged_function(origin: OriginFor<T>) -> DispatchResult {
|
||||
//! ensure_root(origin)?;
|
||||
//!
|
||||
//! // do something...
|
||||
//!
|
||||
//! Ok(().into())
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
|
||||
@@ -54,21 +54,28 @@ Import the System module and derive your module's configuration trait from the s
|
||||
### Example - Get extrinsic count and parent hash for the current block
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
pub trait Config: system::Config {}
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[weight = 0]
|
||||
pub fn system_module_example(origin) -> dispatch::DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
let _extrinsic_count = <system::Pallet<T>>::extrinsic_count();
|
||||
let _parent_hash = <system::Pallet<T>>::parent_hash();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn system_module_example(origin: OriginFor<T>) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
let _extrinsic_count = <system::Pallet<T>>::extrinsic_count();
|
||||
let _parent_hash = <system::Pallet<T>>::parent_hash();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -45,20 +45,29 @@ trait from the timestamp trait.
|
||||
### Get current timestamp
|
||||
|
||||
```rust
|
||||
use frame_support::{decl_module, dispatch};
|
||||
use frame_system::ensure_signed;
|
||||
use pallet_timestamp::{self as timestamp};
|
||||
|
||||
pub trait Config: timestamp::Config {}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
#[weight = 0]
|
||||
pub fn get_time(origin) -> dispatch::DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
let _now = <timestamp::Module<T>>::get();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + timestamp::Config {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn get_time(origin: OriginFor<T>) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
let _now = <timestamp::Pallet<T>>::get();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -64,18 +64,26 @@
|
||||
//! ### Get current timestamp
|
||||
//!
|
||||
//! ```
|
||||
//! use frame_support::{decl_module, dispatch};
|
||||
//! # use pallet_timestamp as timestamp;
|
||||
//! use frame_system::ensure_signed;
|
||||
//! use pallet_timestamp::{self as timestamp};
|
||||
//!
|
||||
//! pub trait Config: timestamp::Config {}
|
||||
//! #[frame_support::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use super::*;
|
||||
//! use frame_support::pallet_prelude::*;
|
||||
//! use frame_system::pallet_prelude::*;
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
||||
//! #[weight = 0]
|
||||
//! pub fn get_time(origin) -> dispatch::DispatchResult {
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//!
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config + timestamp::Config {}
|
||||
//!
|
||||
//! #[pallet::call]
|
||||
//! impl<T: Config> Pallet<T> {
|
||||
//! #[pallet::weight(0)]
|
||||
//! pub fn get_time(origin: OriginFor<T>) -> DispatchResult {
|
||||
//! let _sender = ensure_signed(origin)?;
|
||||
//! let _now = <timestamp::Module<T>>::get();
|
||||
//! let _now = <timestamp::Pallet<T>>::get();
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! }
|
||||
|
||||
Reference in New Issue
Block a user