Event

kitchen/modules/simple-event, kitchen/modules/generic-event

In Substrate, transaction finality does not guarantee the execution of functions dependent on the given transaction. To verify that functions have executed successfully, emit an event at the bottom of the function body.

Events notify the off-chain world of successful state transitions

To declare an event, use the decl_event macro.

Simple Event

The simplest example of an event uses the following syntax


# #![allow(unused_variables)]
#fn main() {
decl_event!(
    pub enum Event {
        EmitInput(u32),
    }
);
#}

The event is emitted at the bottom of the do_something function body:


# #![allow(unused_variables)]
#fn main() {
Self::deposit_event(Event::EmitInput(new_number));
#}

Events with Module Types

Sometimes events might emit types from the module Trait. When the event uses types from the module, it is necessary to specify additional syntax


# #![allow(unused_variables)]
#fn main() {
decl_event!(
    pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
        EmitInput(AccountId, u32),
    }
);
#}

The syntax for deposit_event now takes the RawEvent type because it is generic over the module Trait


# #![allow(unused_variables)]
#fn main() {
Self::deposit_event(RawEvent::EmitInput(user, new_number));
#}

See the next example to use the simple event syntax in the context of verifying successful execution of an adding machine