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

VIP: Modify event declaration syntax to resemble that of struct #1864

Closed
iamdefinitelyahuman opened this issue Feb 28, 2020 · 6 comments · Fixed by #2044
Closed

VIP: Modify event declaration syntax to resemble that of struct #1864

iamdefinitelyahuman opened this issue Feb 28, 2020 · 6 comments · Fixed by #2044
Assignees
Labels
VIP: Approved VIP Approved

Comments

@iamdefinitelyahuman
Copy link
Contributor

Simple Summary

Change this:

Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})

to this:

event Transfer:
    _from: indexed(address)
    _to: indexed(address)
    _value: uint256

Motivation

The current approach to declaring an event reads as though there is a variable being created, with it's type defined from the result of a call to an event function. This is misleading because:

  1. The created event is not a variable. You cannot assign to it during declaration, or reference it except as a callable member of log.
  2. event, though appearing to be a function, is not a function. And type annotations are not typically declared as the result of a function call.
  3. The reliance on the ordering of dictionary keys inside event is not a standard python behavior until version 3.7. Declaring the fields in this way does not intuitively read as though they are sequenced.

By instead using the struct-style declaration, we make it more clear that this not a simple variable, and that the members inside are sequenced.

Backwards Compatibility

This will be a rather large breaking change, we should definitely discuss it at length. If it is approved, it probably belongs in the 1.0rc release.

Copyright

Copyright and related rights waived via CC0

@fubuloubu fubuloubu added the VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting label Feb 28, 2020
@fubuloubu fubuloubu mentioned this issue Feb 28, 2020
3 tasks
@fubuloubu
Copy link
Member

fubuloubu commented Feb 28, 2020

Should changing the way logs are emitted also be a part of this proposal?

(From log.<EventName>({...}) to log(EventName({...})))

Example:

event MyEvent:
    arg1: indexed(address)
    arg2: uint256
...
log(MyEvent({msg.sender, msg.value}))
...
# Extended lines...
log(MyEvent({
    msg.sender,
    msg.value,
}))

@jacqueswww
Copy link
Contributor

Approved; makes to align the syntax with struct.

@jacqueswww jacqueswww added the VIP: Approved VIP Approved label Mar 2, 2020
@fubuloubu fubuloubu removed the VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting label Mar 2, 2020
@fubuloubu
Copy link
Member

@iamdefinitelyahuman Let's make this happen with 0.2.0?

@iamdefinitelyahuman
Copy link
Contributor Author

For an event without any arguments:

event Foo: pass

@iamdefinitelyahuman
Copy link
Contributor Author

for emitting events, i think log is better as a statement. Also, I don't like the use of curly brackets inside the call, I don't think they serve any purpose.

To me the ideal syntax would be:

log MyEvent(msg.sender, msg.value)

@fubuloubu
Copy link
Member

🚢 🚢 🚢

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

Successfully merging a pull request may close this issue.

3 participants