Attribute Macro frame_support::pallet_macros::event
source · #[event]Expand description
Allows defining 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).
The Event enum can be defined as follows:
#[frame_support::pallet(dev_mode)]
mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::event]
#[pallet::generate_deposit(fn deposit_event)] // Optional
pub enum Event<T> {
/// SomeEvent doc
SomeEvent(u16, u32), // SomeEvent with two fields
}
#[pallet::config]
pub trait Config: frame_system::Config {
/// The overarching runtime event type.
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
}I.e. an enum (with named or unnamed fields variant), named Event, with generic: none
or T or T: Config, and optional w here clause.
RuntimeEvent must be defined in the Config, as shown in the example.
Each field must implement Clone, Eq, PartialEq, codec::Encode,
codec::Decode, and Debug (on std only). For ease of use, bound by the trait
Member, available in frame_support::pallet_prelude.
§Note on deprecation of Events
- Usage of
deprecatedattribute will propagate deprecation information to the pallet metadata where the item was declared. - For general usage examples of
deprecatedattribute please refer to https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-deprecated-attribute - It’s possible to deprecated either certain variants inside the
Eventor the wholeEventitself. If both theEventand its variants are deprecated a compile error will be returned.
Documentation for this macro can be found at frame_support::pallet_macros::event.