Properly handle events defined outside of contract
- Dominant language
- Rust
- Stars
- 1.7k
- Forks
- 218
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
### What is wrong?
Currently, events defined outside of a contract are not included in abi.
Code:
```python
use std::context::Context
contract FOO:
pub fn foo(ctx: Context):
emit MyEvent(ctx, x:1)
event MyEvent:
x: i32
```
ABI:
```json
[
{
"name": "foo",
"type": "function",
"inputs": [],
"outputs": []
}
]
```
The problem here is not merely that they are not included in the abi, but that there can be name collisions when events is used through path(currently this is forbidden though).
e.g.,
```python
# foo.fe.
pub event MyEvent:
x: i32
# main.fe
use foo
event MyEvent:
x: i32
contract Main:
fn emit_foo_event():
emit foo::MyEvent(x: 1)
fn emit2_main_event():
emit MyEvent(x: 1)
```
I'm not sure whether we should allow using event through path, but I feel it'd be reasonable.
If we allow that, we should handle the situation.
One possible solution would be to disallow event definition inside a contract and allow event alias definition instead.
e.g.,
Code:
```python
contract Main:
event MainMyEvent = MyEvent
event FooMyEvent = foo::MyEvent
fn emit_foo_event():
emi Self::FooMyEvent(x: 1)
fn emit2_main_event():
emit Self::MyEvent(x: 1)
```
ABI:
```json
[
{
"name": "MainMyEvent",
"type": "event",
"inputs": [
{
"name": "x",
"type": "int32",
"indexed": false
}
],
"anonymous": false
},
{
"name": "FooMyEvent",
"type": "event",
"inputs": [
{
"name": "x",
"type": "int32",
"indexed": false
}
],
"anonymous": false
},
...
]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing how event definitions and contract ABI generation represent events declared outside a contract, then examine the shown path-based event examples and the proposed alias design. Decide which event forms and name-collision rules are intended, and consider the ABI examples the issue provides as the completion criteria; the issue names no source files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- blockchain, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100