Crate frame_support_procedural
source ·Expand description
Proc macro of Support code for the runtime.
Macros
- Internal macro used by
frame_support
to create tt-call-compliant macros - Internal macro use by frame_support to generate dummy part checker for old pallet declaration
- Construct a runtime, with the given name and the given pallets.
- Declares strongly-typed wrappers around codec-compatible types in storage.
- This macro is meant to be used by frame-support only. It implements the trait
HasKeyPrefix
andHasReversibleKeyPrefix
for tuple ofKey
. - Macro that inserts some tokens after the first match of some pattern.
Attribute Macros
- Each dispatchable may also be annotated with the
#[pallet::call_index($idx)]
attribute, which explicitly defines the codec index for the dispatchable function in theCall
enum. - Compact encoding for arguments can be achieved via
#[pallet::compact]
. The function must return aDispatchResultWithPostInfo
orDispatchResult
. - The mandatory attribute
#[pallet::config]
defines the configurable options for the pallet. - The
#[pallet::constant]
attribute can be used to add an associated type trait bounded byGet
frompallet::config
into metadata, e.g.: - To bypass the
frame_system::Config
supertrait check, use the attributepallet::disable_frame_system_supertrait_check
, e.g.: - The
#[pallet::error]
attribute allows you to define an error enum that will be returned from the dispatchable when an error occurs. The information for this error type is then stored in metadata. - The
#[pallet::event]
attribute allows you to define pallet events. Pallet events are stored under thesystem
/events
key when the block is applied (and then replaced when the next block writes it’s events). - Allows you to define some extra constants to be added into constant metadata.
- The attribute
#[pallet::generate_deposit($visibility fn deposit_event)]
generates a helper function onPallet
that handles deposit events. - To generate the full storage info (used for PoV calculation) use the attribute
#[pallet::generate_storage_info]
, e.g.: - To generate a
Store
trait associating all storages, annotate yourPallet
struct with the attribute#[pallet::generate_store($vis trait Store)]
, e.g.: - The
#[pallet::genesis_build]
attribute allows you to define howgenesis_configuration
is built. This takes as input theGenesisConfig
type (asself
) and constructs the pallet’s initial state. - The
#[pallet::genesis_config]
attribute allows you to define the genesis configuration for the pallet. - The optional attribute
#[pallet::getter(fn $my_getter_fn_name)]
allows you to define a getter function onPallet
. - The
#[pallet::hooks]
attribute allows you to specify aHooks
implementation forPallet
that specifies pallet-specific logic. - The
#[pallet::inherent]
attribute allows the pallet to provide some inherent. An inherent is some piece of data that is inserted by a block authoring node at block creation time and can either be accepted or rejected by validators based on whether the data falls within an acceptable range. - The
#[pallet::origin]
attribute allows you to define some origin for the pallet. - The pallet struct placeholder
#[pallet::pallet]
is mandatory and allows you to specify pallet information. - The
#[pallet::storage]
attribute lets you define some abstract storage inside of runtime storage and also set its metadata. This attribute can be used multiple times. - The optional attribute
#[pallet::storage_prefix = "SomeName"]
allows you to define the storage prefix to use. This is helpful if you wish to rename the storage field but don’t want to perform a migration. - Because the
pallet::pallet
macro implementsGetStorageVersion
, the current storage version needs to be communicated to the macro. This can be done by using thepallet::storage_version
attribute: - Execute the annotated function in a new storage transaction.
- The
#[pallet::type_value]
attribute lets you define a struct implementing theGet
trait to ease the use of storage types. This attribute is meant to be used alongside#[pallet::storage]
to define a storage’s default value. This attribute can be used multiple times. - The optional attribute
#[pallet::unbounded]
declares the storage as unbounded. When implementating the storage info (when#[pallet::generate_storage_info]
is specified on the pallet struct placeholder), the size of the storage will be declared as unbounded. This can be useful for storage which can never go into PoV (Proof of Validity). - The
#[pallet::validate_unsigned]
attribute allows the pallet to validate some unsigned transaction: - Each dispatchable needs to define a weight with
#[pallet::weight($expr)]
attribute, the first argument must beorigin: OriginFor<T>
. - The optional attribute
#[pallet::whitelist_storage]
will declare the storage as whitelisted from benchmarking. Doing so will exclude reads of that value’s storage key from counting towards weight calculations during benchmarking.
Derive Macros
- Derive
Clone
but do not bound any generic. Docs are atframe_support::CloneNoBound
. - Derive
Debug
but do not bound any generics. Docs are atframe_support::DebugNoBound
. - derive
Default
but do no bound any generic. Docs are atframe_support::DefaultNoBound
. - derive Eq but do no bound any generic. Docs are at
frame_support::EqNoBound
. - Derive
PartialEq
but do not bound any generic. Docs are atframe_support::PartialEqNoBound
. - Derive
Debug
, ifstd
is enabled it usesframe_support::DebugNoBound
, ifstd
is not enabled it just returns"<stripped>"
. This behaviour is useful to prevent bloating the runtime WASM blob from unneeded code.