Macro frame_support::decl_event[][src]

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
			)*
		}
	) => { ... };
}
Expand description

Implement the Event for a module.

Simple Event Example:

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

Generic Event Example:

trait Config {
    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::Config>::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::Config>::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::Config>::Balance, <T as super::Config>::Token {
          Message(Balance, Token),
       }
    );
}

The syntax for generic events requires the where.

Generic Event with Instance Example:

trait Config<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 Config>::Balance,
      <T as Config>::Token
   {
      Message(Balance, Token),
   }
);