Imagine you have an outer program A. Program A has no defined events. Program A CPIs to an inner program B that does have events defined on it. If I try to listen to one of B's events on program A, Anchor will fatal:
This is surely because the IDL of program A does not contain the event. When Anchor tries to deserialize the event, it bombs.
This works:
const programB = /* Load B's IDL and `new` up a `Program` */;
programB.addEventListener('SomeEventFromB', (event, slot) => { /* ... */ });
…but the downside is that I have to pull in a ton of program-B-related code to my dApp just to be able to parse its events.
Possible solution (RFC)
What would you think about teaching the Anchor compiler to include the Event definitions from program B's IDL in the IDL of program A, simply by virtue of the fact that there is a CPI to B from A?
Pros:
addEventListener would Just Work™ on events emitted from CPI'd programs.
You pay only part of the cost of program B in your dApp.
Cons:
Namespace conflicts (ie. what if two programs have identically-named events).
Problem statement
Imagine you have an outer program A. Program A has no defined events. Program A CPIs to an inner program B that does have events defined on it. If I try to listen to one of B's events on program A, Anchor will fatal:
This is surely because the IDL of program A does not contain the event. When Anchor tries to deserialize the event, it bombs.
This works:
…but the downside is that I have to pull in a ton of program-B-related code to my dApp just to be able to parse its events.
Possible solution (RFC)
What would you think about teaching the Anchor compiler to include the
Event
definitions from program B's IDL in the IDL of program A, simply by virtue of the fact that there is a CPI to B from A?Pros:
addEventListener
would Just Work™ on events emitted from CPI'd programs.Cons: