Attribute Macro frame_support::pallet_macros::hooks
source · #[hooks]
Expand description
The #[pallet::hooks]
attribute allows you to specify a
frame_support::traits::Hooks
implementation for Pallet
that specifies
pallet-specific logic.
The item the attribute attaches to must be defined as follows:
#[frame_support::pallet]
mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
// Implement hooks here
}
}
I.e. a regular trait implementation with generic bound: T: Config
, for the trait
Hooks<BlockNumberFor<T>>
(they are defined in preludes), for the type Pallet<T>
.
Optionally, you could add a where clause.
§Macro expansion
The macro implements the traits
OnInitialize
,
OnIdle
,
OnFinalize
,
OnRuntimeUpgrade
,
OffchainWorker
, and
IntegrityTest
using
the provided Hooks
implementation.
NOTE: OnRuntimeUpgrade
is implemented with Hooks::on_runtime_upgrade
and some
additional logic. E.g. logic to write the pallet version into storage.
NOTE: The macro also adds some tracing logic when implementing the above traits. The
following hooks emit traces: on_initialize
, on_finalize
and on_runtime_upgrade
.
Documentation for this macro can be found at frame_support::pallet_macros::hooks
.