-
Notifications
You must be signed in to change notification settings - Fork 382
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
feat(gnovm, tm2): implement event emission with std.Emit
#1653
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1653 +/- ##
==========================================
+ Coverage 46.64% 46.72% +0.08%
==========================================
Files 492 492
Lines 69624 69762 +138
==========================================
+ Hits 32476 32597 +121
- Misses 34442 34454 +12
- Partials 2706 2711 +5 ☔ View full report in Codecov by Sentry. |
Will take a look at this and give feedback 🙏 |
Thank you @zivkovicmilos! I'm still trying to understand most things, every feedback would be greatly helpful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly believe this is the way to go 💯
The solution proposed here is simple, elegant, minimal.
It doesn't force us to modify the transaction result in order to accommodate event data, which I see as a huge plus -- it's completely backwards compatible.
We just need to figure out how to pipe the event emissions from the Gno code (and what the API should be, I'm hoping something within std
), and we should be good to go 🚀
- it just prints event(s) for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, again, because the changes are solid
Please check the leftover comments, but don't resolve them on the GitHub UI 🙏
Let the comment author / core team resolve the comment after you reply / ping them as soon as the fix has been pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take into account my previous comment.
) # Description Succeed in my predecessor's legacy. I have implemented the output to show the path where the event occurred, as discussed in gnolang#1833. Also made it print the timestamp or block height together. ## Key Changes In this change, event emission functionality has been added to the Gno. The main changes include: 1. Introducing of the `emitEvent` function: - The `emitEvent` function emits an event based on the given type and attributes - Attributes are passed as an even-length of array key-value pairs - When emitting an event, the current _package path_, _timestamp_, and _block height_ information are recorded along with the event(discussed in gnolang#1833). This metadata provides additional context about where the event occured. 2. Additional of event-related types and functions in the `sdk` packages: - `NewEvent` creates a new `Event` object based on the provided information. - `ArributedEvent` struct contains informations such as event type, package path, block height, timestamp and attributes. But I'm not sure how to utilize the `eventType` yet. So, I've just put it as a placeholder which will be a disscussion for another time. - `EventArribute` represents an attribute of an event and consists of a key-value pair - `NewEventArribute` creates a new `EventAttribute` object based on the given key-value pair. ## Example ```go package ee import ( "std" ) const ( EventSender = "sender" EventReceiver = "receiver" ) func Sender(){ SubSender() SubReceiver() } func SubSender() { std.Emit( EventSender, "key1", "value1", "key2", "value2", "key3", "value3", ) } func SubReceiver() { std.Emit( EventReceiver, "bar", "baz", ) } func Receiver() { std.Emit( EventReceiver, "foo", "bar", ) } ``` ### Result ```json [ "{\"type\":\"sender\",\"pkg_path\":\"gno.land/r/demo/ee\",\"identifier\":\"SubSender\",\"timestamp\":1713846501,\"attributes\":[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"},{\"key\":\"key3\",\"value\":\"value3\"}]}", "{\"type\":\"receiver\",\"pkg_path\":\"gno.land/r/demo/ee\",\"identifier\":\"SubReceiver\",\"timestamp\":1713846501,\"attributes\":[{\"key\":\"bar\",\"value\":\"baz\"}]}" ] ``` ## Related Issue/PR gnolang#575 emit & event built-in functions (@r3v4s) gnolang#853 feat: event & emit in gno (@anarcher) <- previous work. gnolang#975 [META] Gno Wishlist / Feature Request Dump (@zivkovicmilos) --------- Co-authored-by: n3wbie <[email protected]> Co-authored-by: Manfred Touron <[email protected]>
FYI, for everyone who has been in this PR |
Description
Succeed in my predecessor's legacy.
I have implemented the output to show the path where the event occurred, as discussed in #1833. Also made it print the timestamp or block height together.
Key Changes
In this change, event emission functionality has been added to the Gno. The main changes include:
Introducing of the
emitEvent
function:emitEvent
function emits an event based on the given type and attributesAdditional of event-related types and functions in the
sdk
packages:NewEvent
creates a newEvent
object based on the provided information.ArributedEvent
struct contains informations such as event type, package path, block height, timestamp and attributes. But I'm not sure how to utilize theeventType
yet. So, I've just put it as a placeholder which will be a disscussion for another time.EventArribute
represents an attribute of an event and consists of a key-value pairNewEventArribute
creates a newEventAttribute
object based on the given key-value pair.Example
Result
Related Issue/PR
#575 emit & event built-in functions (@r3v4s)
#853 feat: event & emit in gno (@anarcher) <- previous work.
#975 [META] Gno Wishlist / Feature Request Dump (@zivkovicmilos)