This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Migrate All Pallets to Attribute Macro #561
Comments
This was referenced Mar 23, 2021
songtianyi
changed the title
feat: Migrate frames to use pallet! procedural macro
Migrate frames to use pallet! procedural macro
Mar 28, 2021
AurevoirXavier
changed the title
Migrate frames to use pallet! procedural macro
Migrate to New Pallet Style
Mar 28, 2021
And I propose this style: // LICENSE
//! # Module Introduction
//(ignore this in real code) does't need to comment on `pub use`
pub use pallet::*;
pub use weights::WeightInfo;
//(ignore this in real code) test module above others
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
#[frame_support::pallet]
pub mod pallet {
//(ignore this in real code) pub mod types go first
pub mod types {
//(ignore this in real code) all import need a comment, easy for code review
// --- darwinia ---
use super::*;
// Simple type
pub type SimpleNum = u128;
// Generic type
pub type AccountId<T> = <T as frame_system::Config>::AccountId;
}
pub use types::*;
//(ignore this in real code) imports go second
//(ignore this in real code) all import need a comment, easy for code review
// --- substrate ---
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
//(ignore this in real code) all import need a comment, easy for code review
// --- darwinia ---
use crate::weights::WeightInfo;
//(ignore this in real code) trait goes third
#[pallet::config]
pub trait Config: frame_system::Config {
//(ignore this in real code) substrate framework types here
// --- substrate ---
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type WeightInfo: WeightInfo;
//(ignore this in real code) custom types here
// --- darwinia ---
#[pallet::constant]
type ModuleId: Get<ModuleId>;
}
//(ignore this in real code) event goes forth
#[pallet::event]
pub enum Event<T: Config> {
//(ignore this in real code) need to place a `\` before the bracket, cause these comment will generate the docs
/// Dummy Event. \[who\]
DummyEvent(AccountId<T>),
}
//(ignore this in real code) error goes fifth
pub enum Error<T> {}
//(ignore this in real code) storages go sixth
//(ignore this in real code) keep visibility simple as `pub` or empty, if necessary then `pub (sup)` or `pub (crate)`
#[pallet::storage]
#[pallet::getter(fn total_mapped_ring)]
pub type DummyStorage<T: Config> = StorageValue<_, SimpleNum>;
//(ignore this in real code) genesis config goes seventh, if this is a complex struct `impl Default` manually
#[cfg_attr(feature = "std", derive(Default))]
#[pallet::genesis_config]
pub struct GenesisConfig {
pub total_mapped_ring: MappedRing,
}
//(ignore this in real code) and I recommend not to leave a empty line between struct and its own impl
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {}
}
//(ignore this in real code) dispatch calls go last
#[pallet::pallet]
pub struct Pallet<T>(_);
//(ignore this in real code) and I recommend not to leave a empty line between struct and its own impl
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
//(ignore this in real code) and I recommend not to leave a empty line between struct and its own impl
#[pallet::call]
impl<T: Config> Pallet<T> {}
} |
This comment has been minimized.
This comment has been minimized.
AurevoirXavier
changed the title
Migrate to New Pallet Style
Migrate All Pallets to Attribute Macro
Apr 27, 2021
Some pallets will be removed later. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Here is the list of pallet and their status, if you want to migrate one you can put your name after it to avoid duplicated work.
some helpful guidelines to do the migration: https://crates.parity.io/frame_support/attr.pallet.html#upgrade-guidelines
some helpful guidelines to review a migration: https://crates.parity.io/frame_support/attr.pallet.html#checking-upgrade-guidelines
balances
to Attribute Macro #593tron-backing
to Attribute Macro #610ethereum-backing
to Attribute Macro #611darwinia-staking
to Attribute Macro #924header-mmr
to Attribute Macro #613dvm-dynamic-fee
to Attribute Macro #644The text was updated successfully, but these errors were encountered: