Hooks example pallet: ``` //! - Pallet hooks to implement some logic to be executed at the start and end of block execution //! (see: [`frame_support::traits::Hooks`]) // This pallet implements the [`frame_support::traits::Hooks`] trait to demonstrate how we could // define some logic to execute in some context. #[pallet::hooks] impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { // `on_initialize` is executed at the beginning of the block before any extrinsics are // dispatched. // // This function must return the weight consumed by `on_initialize` and `on_finalize`. fn on_initialize(_n: BlockNumberFor<T>) -> Weight { // Anything that needs to be done at the start of the block. // We don't do anything here. Weight::zero() } // `on_finalize` is executed at the end of block after all extrinsics are dispatched. fn on_finalize(_n: BlockNumberFor<T>) { // Perform necessary data/state clean up here. } } ```