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:
Qinxuan Chen
2021-11-19 06:08:17 +08:00
committed by GitHub
parent 78e60cbc4f
commit 69478639b3
23 changed files with 265 additions and 191 deletions
+20 -12
View File
@@ -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(())
}
}
}
```
+20 -19
View File
@@ -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)]