Expand description

Contains macro stubs for all of the pallet:: macros

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 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.:
  • 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.
  • 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.
  • 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.
  • Can be attached to a module. Doing so will declare that module as importable into a pallet via #[import_section].
  • 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:
  • 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.