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.
- 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
- An attribute macro used to declare a benchmark within a benchmarking module. Must be attached to a function definition containing an
#[extrinsic_call]
or#[block]
attribute. - An attribute macro that can be attached to a (non-empty) module declaration. Doing so will designate that module as a benchmarking module.
- An attribute macro used to specify that a block should be the measured portion of the enclosing benchmark function, This attribute is also used as a boundary designating where the benchmark setup code ends, and the benchmark verification code begins.
- 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
#[pallet::composite_enum]
attribute allows you to define an enum that gets composed as an aggregate enum byconstruct_runtime
. This is similar in principle with#[pallet::event]
and#[pallet::error]
. - 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.: - This attribute can be used to derive a full implementation of a trait based on a local partial impl and an external impl containing defaults that can be overriden in the local impl.
- 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.
- An attribute macro used to specify the extrinsic call inside a benchmark function, and also used as a boundary designating where the benchmark setup code ends, and the benchmark verification code begins.
- The attribute
#[pallet::generate_deposit($visibility fn deposit_event)]
generates a helper function onPallet
that handles deposit events. - 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. - An attribute macro that can be attached to a module declaration. Doing so will Imports the contents of the specified external pallet section that was defined previously using
#[pallet_section]
. - 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. - An attribute macro that can be attached to a (non-empty) module declaration. Doing so will designate that module as an instance benchmarking module.
- The optional attribute
#[pallet::no_default]
can be attached to trait items within aConfig
trait impl that has#[pallet::config(with_default)]
attached. - The optional attribute
#[pallet::no_default_bounds]
can be attached to trait items within aConfig
trait impl that has#[pallet::config(with_default)]
attached. - 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. - Can be attached to a module. Doing so will declare that module as importable into a pallet via
#[import_section]
. - Attach this attribute to an impl statement that you want to use with
#[derive_impl(..)]
. - 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"<wasm:stripped>"
. This behaviour is useful to prevent bloating the runtime WASM blob from unneeded code.