cadence
cadence copied to clipboard
Event listeners
Issue To Be Solved
Allow contracts to listen to events emitted by other contracts.
Suggested Solution
When an event is emitted from Ping
pub contract Ping {
event Pinged(with: String)
}
Pong's listener would be triggered.
import Ping from 0x01
pub contract Pong {
pub listener PingListener(on: Ping.Pinged, fun(with: String){
log(with)
})
}
Maybe this could be implemented with delegates.
Ping would have a method to register a delegate.
Pong would call a method on Ping to add itself as a delegate. When an event is emitted by Ping all delegates would receive the event.
Which listeners would get invoked? Say a transaction calls into a contract that emits an event – would all listeners on the chain get invoked? What if they fail?
This is not possible I guess
- Technically requires something like nested transactions to work.
- Can create very big performance issues. What if listener also emits an event ?
- Events are in general already messed up: we have big event spam, AN event support is so primitive you should use 3rd party etc
Maybe:
- When event
Eis emitted , all listeners of eventEwould be invoked. - Instead of having sub transactions, when a listener is invoked it could enqueue a new transaction.
- The gas for the execution of the enqueued transaction could be subtracted from the contract that defined the listener.
- 🤔 I'm not sure who the authoriser would be