-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add event support via #[event]
and #[indexed]
attributes
#7158
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
Draft
tritao
wants to merge
3
commits into
FuelLabs:master
Choose a base branch
from
tritao:indexed-events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c4c05c2
to
2aa6290
Compare
2aa6290
to
c520e49
Compare
c520e49
to
1e3136d
Compare
CodSpeed Performance ReportMerging #7158 will not alter performanceComparing Summary
|
1e3136d
to
56c1d7b
Compare
56c1d7b
to
6bdb27c
Compare
This adds two new attributes: `#[event]` and `#[indexed]`. The `#[event]` attribute marks a struct or enum as an event that can be emitted by a contract. The `#[indexed]` attribute can be applied to fields within structs that are attributed with `#[event]`. This is particularly useful for event structs, allowing for efficient filtering and searching of emitted events based on the values of these fields. When using this attribute, the indexed fields must be applied sequentially to the initial set of fields in a struct. This attribute can only be applied to fields whose type is an exact size ABI type. The exact size ABI types include: - `bool` - `u8`, `u16`, `u32`, `u64`, `u256` - `numeric` - `b256` - `str[N]` - Tuples containing only exact size types - Structs containing only exact size types - Arrays of exact size types with a literal length - Type aliases to exact size types Additionally it causes the event types to be included in the JSON ABI representation for the contract. ```sway struct MyEventStruct { #[indexed] id: u64, sender: Identity, } enum MyEventEnum { A: (), B: (), } ``` Additionally this updates the JSON ABI to emit an `offset` for indexed fields.
6bdb27c
to
f3875f2
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler
General compiler. Should eventually become more specific as the issue is triaged
enhancement
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds two new attributes:
#[event]
and#[indexed]
.The
#[event]
attribute marks a struct or enum as an event that can be emitted by a contract.The
#[indexed]
attribute can be applied to fields within structs that are attributed with#[event]
. This is particularly useful for event structs, allowing for efficient filtering and searching of emitted events based on the values of these fields.When using this attribute, the indexed fields must be applied sequentially to the initial set of fields in a struct.
This attribute can only be applied to fields whose type is an exact size ABI type. The exact size ABI types include:
bool
u8
,u16
,u32
,u64
,u256
numeric
b256
str[N]
Additionally it causes the event types to be included in the JSON ABI representation for the contract and emits an
offset
for indexed fields.