Trait frame_support::traits::Hooks
source · [−]pub trait Hooks<BlockNumber> {
fn on_finalize(_n: BlockNumber) { ... }
fn on_initialize(_n: BlockNumber) -> Weight { ... }
fn on_runtime_upgrade() -> Weight { ... }
fn offchain_worker(_n: BlockNumber) { ... }
fn integrity_test() { ... }
}
Expand description
The pallet hooks trait. Implementing this lets you express some logic to execute.
Provided methods
fn on_finalize(_n: BlockNumber)
fn on_finalize(_n: BlockNumber)
The block is being finalized. Implement to have something happen.
fn on_initialize(_n: BlockNumber) -> Weight
fn on_initialize(_n: BlockNumber) -> Weight
The block is being initialized. Implement to have something happen.
Return the non-negotiable weight consumed in the block.
fn on_runtime_upgrade() -> Weight
fn on_runtime_upgrade() -> Weight
Perform a module upgrade.
NOTE: this doesn’t include all pallet logic triggered on runtime upgrade. For instance it
doesn’t include the write of the pallet version in storage. The final complete logic
triggered on runtime upgrade is given by implementation of OnRuntimeUpgrade
trait by
Pallet
.
Warning
This function will be called before we initialized any runtime state, aka on_initialize
wasn’t called yet. So, information like the block number and any other
block local data are not accessible.
Return the non-negotiable weight consumed for runtime upgrade.
fn offchain_worker(_n: BlockNumber)
fn offchain_worker(_n: BlockNumber)
Implementing this function on a module allows you to perform long-running tasks that make (by default) validators generate transactions that feed results of those long-running computations back on chain.
NOTE: This function runs off-chain, so it can access the block state, but cannot preform any alterations. More specifically alterations are not forbidden, but they are not persisted in any way after the worker has finished.
This function is being called after every block import (when fully synced).
Implement this and use any of the Offchain
sp_io
set of APIs
to perform off-chain computations, calls and submit transactions
with results to trigger any on-chain changes.
Any state alterations are lost and are not persisted.
fn integrity_test()
fn integrity_test()
Run integrity test.
The test is not executed in a externalities provided environment.