Expand description

Contains macro stubs for all of the pallet:: macros

Attribute Macros§

  • Allows a pallet to declare a set of functions as a dispatchable extrinsic. In slightly simplified terms, this macro declares the set of “transactions” of a pallet.
  • Enforce the index of a variant in the generated enum Call. See call for more information.
  • Declares the arguments of a call function to be encoded using codec::Compact. This will results in smaller extrinsic encoding.
  • 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.
  • 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.
  • Each dispatchable may be annotated with the #[pallet::feeless_if($closure)] attribute, which explicitly defines the condition for the dispatchable to be feeless.
  • 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.:
  • Allows you to define how the state of your pallet at genesis is built. This takes as input the GenesisConfig type (as self) and constructs the pallet’s initial state.
  • 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].
  • Declares a type alias as a storage item. Storage items are pointers to data stored on-chain (the blockchain state), under a specific key. The exact key is dependent on the type of the storage.
  • 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:
  • This attribute is attached to a function inside an impl block annoated with pallet::tasks_experimental to define the conditions for a given work item to be valid.
  • This attribute is attached to a function inside an impl block annoated with pallet::tasks_experimental to define the index of a given work item.
  • This attribute is attached to a function inside an impl block annoated with pallet::tasks_experimental to define an iterator over the available work items for a task.
  • This attribute is attached to a function inside an impl block annoated with pallet::tasks_experimental define the weight of a given work item.
  • Allows you to define some service work that can be recognized by a script or an off-chain worker. Such a script can then create and submit all such work items at any given time.
  • 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.