Expand description

Proc macro of Support code for the runtime.

Macros

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 the Call enum.
  • Compact encoding for arguments can be achieved via #[pallet::compact]. The function must return a DispatchResultWithPostInfo or DispatchResult.
  • The #[pallet::composite_enum] attribute allows you to define an enum that gets composed as an aggregate enum by construct_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 by Get from pallet::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 attribute pallet::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 the system / 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 on Pallet that handles deposit events.
  • To generate a Store trait associating all storages, annotate your Pallet struct with the attribute #[pallet::generate_store($vis trait Store)], e.g.:
  • The #[pallet::genesis_build] attribute allows you to define how genesis_configuration is built. This takes as input the GenesisConfig type (as self) 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 on Pallet.
  • The #[pallet::hooks] attribute allows you to specify a Hooks implementation for Pallet 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 a Config trait impl that has #[pallet::config(with_default)] attached.
  • The optional attribute #[pallet::no_default_bounds] can be attached to trait items within a Config 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 implements GetStorageVersion, the current storage version needs to be communicated to the macro. This can be done by using the pallet::storage_version attribute:
  • Execute the annotated function in a new storage transaction.
  • The #[pallet::type_value] attribute lets you define a struct implementing the Get 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 be origin: 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 at frame_support::CloneNoBound.
  • Derive Debug but do not bound any generics. Docs are at frame_support::DebugNoBound.
  • derive Default but do no bound any generic. Docs are at frame_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 at frame_support::PartialEqNoBound.
  • Derive Debug, if std is enabled it uses frame_support::DebugNoBound, if std is not enabled it just returns "<wasm:stripped>". This behaviour is useful to prevent bloating the runtime WASM blob from unneeded code.