Attribute Macro frame_support_procedural::pallet
source · #[pallet]Expand description
The pallet struct placeholder #[pallet::pallet] is mandatory and allows you to specify
pallet information.
The struct must be defined as follows:
#[pallet::pallet]
pub struct Pallet<T>(_);I.e. a regular struct definition named Pallet, with generic T and no where clause.
Macro expansion:
The macro adds this attribute to the struct definition:
#[derive(
frame_support::CloneNoBound,
frame_support::EqNoBound,
frame_support::PartialEqNoBound,
frame_support::RuntimeDebugNoBound,
)]and replaces the type _ with PhantomData<T>. It also implements on the pallet:
GetStorageVersionOnGenesis: contains some logic to write the pallet version into storage.PalletErrorTypeInfo: provides the type information for the pallet error, if defined.
It declares type Module type alias for Pallet, used by construct_runtime.
It implements PalletInfoAccess on Pallet to ease access to pallet information given by
frame_support::traits::PalletInfo. (The implementation uses the associated type
frame_system::Config::PalletInfo).
It implements StorageInfoTrait on Pallet which give information about all storages.
If the attribute generate_store is set then the macro creates the trait Store and
implements it on Pallet.
If the attribute set_storage_max_encoded_len is set then the macro calls
StorageInfoTrait for each storage in the implementation of StorageInfoTrait for the
pallet. Otherwise it implements StorageInfoTrait for the pallet using the
PartialStorageInfoTrait implementation of storages.
Dev Mode (#[pallet(dev_mode)])
Specifying the argument dev_mode will allow you to enable dev mode for a pallet. The aim
of dev mode is to loosen some of the restrictions and requirements placed on production
pallets for easy tinkering and development. Dev mode pallets should not be used in
production. Enabling dev mode has the following effects:
- Weights no longer need to be specified on every
#[pallet::call]declaration. By default, dev mode pallets will assume a weight of zero (0) if a weight is not specified. This is equivalent to specifying#[weight(0)]on all calls that do not specify a weight. - All storages are marked as unbounded, meaning you do not need to implement
MaxEncodedLenon storage types. This is equivalent to specifying#[pallet::unbounded]on all storage type definitions.
Note that the dev_mode argument can only be supplied to the #[pallet] or
#[frame_support::pallet] attribute macro that encloses your pallet module. This argument
cannot be specified anywhere else, including but not limited to the #[pallet::pallet]
attribute macro.
WARNING: You should not deploy or use dev mode pallets in production. Doing so can break your chain and therefore should never be done. Once you are done tinkering, you should remove the 'dev_mode' argument from your #[pallet] declaration and fix any compile errors before attempting to use your pallet in a production scenario.
See frame_support::pallet docs for more info.