Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Migrate All Pallets to Attribute Macro #561

Closed
11 of 14 tasks
songtianyi opened this issue Mar 23, 2021 · 3 comments
Closed
11 of 14 tasks

Migrate All Pallets to Attribute Macro #561

songtianyi opened this issue Mar 23, 2021 · 3 comments

Comments

@songtianyi
Copy link
Contributor

songtianyi commented Mar 23, 2021

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

@songtianyi songtianyi changed the title feat: Migrate frames to use pallet! procedural macro Migrate frames to use pallet! procedural macro Mar 28, 2021
@AurevoirXavier AurevoirXavier changed the title Migrate frames to use pallet! procedural macro Migrate to New Pallet Style Mar 28, 2021
@AurevoirXavier
Copy link
Member

AurevoirXavier commented 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> {}
}

@hackfisher hackfisher pinned this issue Mar 29, 2021
@hackfisher

This comment has been minimized.

@hackfisher hackfisher unpinned this issue Apr 21, 2021
@AurevoirXavier AurevoirXavier changed the title Migrate to New Pallet Style Migrate All Pallets to Attribute Macro Apr 27, 2021
@AurevoirXavier AurevoirXavier pinned this issue May 26, 2021
@AurevoirXavier
Copy link
Member

Some pallets will be removed later.

@AurevoirXavier AurevoirXavier unpinned this issue Jul 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants