Vyper: VIP: Modify event declaration syntax to resemble that of struct

Created on 28 Feb 2020  路  6Comments  路  Source: vyperlang/vyper

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

Approved

All 6 comments

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,
}))

Approved; makes to align the syntax with struct.

@iamdefinitelyahuman Let's make this happen with 0.2.0?

For an event without any arguments:

event Foo: pass

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)

:ship: :ship: :ship:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakerockland picture jakerockland  路  4Comments

travs picture travs  路  3Comments

ben-kaufman picture ben-kaufman  路  4Comments

jacqueswww picture jacqueswww  路  3Comments

jacqueswww picture jacqueswww  路  4Comments