[][src]Macro frame_support::decl_event

macro_rules! decl_event {
    (
		$(#[$attr:meta])*
		pub enum Event<$evt_generic_param:ident $(, $instance:ident $(: $instantiable:ident)? $( = $event_default_instance:path)? )?> where
			$( $tt:tt )*
	) => { ... };
    (
		$(#[$attr:meta])*
		pub enum Event {
			$(
				$events:tt
			)*
		}
	) => { ... };
}

Implement the Event for a module.

Simple Event Example:

frame_support::decl_event!(
   pub enum Event {
      Success,
      Failure(String),
   }
);

Generic Event Example:

trait Trait {
    type Balance;
    type Token;
}

mod event1 {
    // Event that specifies the generic parameter explicitly (`Balance`).
    frame_support::decl_event!(
       pub enum Event<T> where Balance = <T as super::Trait>::Balance {
          Message(Balance),
       }
    );
}

mod event2 {
    // Event that uses the generic parameter `Balance`.
    // If no name for the generic parameter is specified explicitly,
    // the name will be taken from the type name of the trait.
    frame_support::decl_event!(
       pub enum Event<T> where <T as super::Trait>::Balance {
          Message(Balance),
       }
    );
}

mod event3 {
    // And we even support declaring multiple generic parameters!
    frame_support::decl_event!(
       pub enum Event<T> where <T as super::Trait>::Balance, <T as super::Trait>::Token {
          Message(Balance, Token),
       }
    );
}

The syntax for generic events requires the where.

Generic Event with Instance Example:

trait Trait<I: Instance=DefaultInstance> {
    type Balance;
    type Token;
}

// For module with instances, DefaultInstance is optional
frame_support::decl_event!(
   pub enum Event<T, I: Instance = DefaultInstance> where
      <T as Trait>::Balance,
      <T as Trait>::Token
   {
      Message(Balance, Token),
   }
);