6

I noticed that every pallet (that i've checked) that has any events uses the following line in the pallets config trait:

type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;

Given the use of From i'm guessing the Runtime has one huge Event Enum that contains all pallet Event Enums. Is this the case? If so where is this declared in the Runtime as i cannot find it in the node implementation (if done by a Macro, can you provide some background info).

2 Answers 2

7

Yes, you are right that every runtime has Event declaration that combines all the events of each pallet. It looks roughly like this:

enum Event {
   System(frame_system::Event),
   Balances(pallet_balances::Event),
   ..
}

This "overarching" event is generated by the construct_runtime! macro.

You will find this concept of "overarching" types quite a lot in Substrate. Another good example is the Call enum that is doing the same as the Event enum.

When you for example send an event from your custom pallet, it will be first converted to the overarching Event of the runtime. This is the reason for the From implementation you mentioned above. After that conversion the event is passed to frame-system to be stored in a Vec<Event> where Event is the overarching Event of the runtime.

0

BTW, you can retrieve Events by querying system.events storage with specified blockhash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.