Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-generated key methods for Events #1116

Open
wants to merge 15 commits into
base: nightly
Choose a base branch
from

Conversation

cemozerr
Copy link
Member

@cemozerr cemozerr commented Oct 27, 2023

Description

We want to use typed objects instead of the handwritten events in the codebase so that the event processes are less error-prone, and its easer/ more obvious for users to index these events.

For this purpose, in this PR, we:

  • Added an Event trait with methods an event_key(), which returns a given Event object's key, and get_all_event_keys(), which returns all possible event keys for a module, and put this trait as a trait bound on the Event associated type on the Module trait.
  • Added an Event macro that derives the Event trait methods for a given enum.
  • Renamed the original Event macro that creates an enum that represents all possible events from all the modules to RuntimeEvent.
  • Added a get_key_string method to the <runtime>Event enum generated by the (now called) RuntimeEvent macro, which returns a given <Runtime>Event's key.
  • Added a get_all_key_strings method to the <runtime>Event enum, which returns the key strings for all events in the runtime, spanning across all modules.
  • Renamed the legacy Event type from rollup_interface to LegacyEvent to fix name clashing. The LegacyEvent will be completely removed in an upcoming PR as we move to a simpler Event flow.

The diffs for the macro files are unfortunately bigger than necessary as the name event.rs was more appropriate for the new macro than the previous RuntimeEvent macro.

@codecov
Copy link

codecov bot commented Oct 27, 2023

Copy link
Member

@preston-evans98 preston-evans98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except for the create_get_key_string_impl body. Just need to replace the format!("{:?}", inner) call with inner.event_key() and we should be good to go

@cemozerr cemozerr changed the title Add the Event trait and corresponding derive macro Add get_key_string method to the `<runtime>Event via an Event trait Oct 30, 2023
@cemozerr cemozerr changed the title Add get_key_string method to the `<runtime>Event via an Event trait Add get_key_string method to the <runtime>Event Oct 30, 2023
@cemozerr cemozerr changed the title Add get_key_string method to the <runtime>Event Add auto-generated key methods for Events Oct 31, 2023
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants