sovereign-sdk icon indicating copy to clipboard operation
sovereign-sdk copied to clipboard

Add auto-generated key methods for Events

Open cemozerr opened this issue 1 year ago • 1 comments

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.

cemozerr avatar Oct 27 '23 19:10 cemozerr

Codecov Report

Merging #1116 (c711860) into nightly (5d61e35) will increase coverage by 0.0%. The diff coverage is 91.5%.

Files Coverage Δ
full-node/db/sov-db/src/ledger_db/mod.rs 90.8% <ø> (ø)
full-node/db/sov-db/src/schema/tables.rs 85.0% <ø> (ø)
full-node/db/sov-db/src/schema/types.rs 80.7% <100.0%> (ø)
full-node/sov-ledger-rpc/src/client.rs 100.0% <ø> (ø)
...ions/integration-tests/src/nested_modules/tests.rs 100.0% <100.0%> (ø)
...ule-system/sov-modules-api/src/state/scratchpad.rs 88.1% <100.0%> (ø)
module-system/sov-modules-macros/src/lib.rs 100.0% <100.0%> (ø)
...ule-system/sov-modules-macros/src/runtime_event.rs 100.0% <100.0%> (ø)
rollup-interface/src/node/rpc/mod.rs 89.2% <ø> (ø)
rollup-interface/src/state_machine/stf.rs 85.7% <ø> (ø)
... and 4 more

... and 1 file with indirect coverage changes

codecov[bot] avatar Oct 27 '23 19:10 codecov[bot]

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.

CLAassistant avatar Oct 21 '24 21:10 CLAassistant