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
+16 -8
View File
@@ -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(())
}
}