anchor
anchor copied to clipboard
No easy way to subscribe to self CPI logs
Looking at the javascript tests for CPI events, it seems that what has been done is that txHash has been used to fetch and decode after making transactions to test the decoding of self-CPI events.
I think it makes sense to add an abstraction like addEventListener for normal program log events to make listening to off-chain events in typescript listeners easier.
Yes, this is because there isn't a great way to subscribe to them since it requires fetching the transaction to get the event data each time meanwhile the regular event method depends on logsSubscribe method.
There is an unstable blockSubscribe method that we could use to subscribe to blocks and filter based on our needs but it would still waste a lot of resources to get what we want.
I think it makes sense to add an abstraction like addEventListener for normal program log events to make listening to off-chain events in typescript listeners easier.
Yes, you are right. We should make it easier to handle this.
Hi. I would be interested if there are some plans around adding the abstraction for the subscription and parsing(!) the cpi events?
I cannot see much more resources on this topic besides the comment at the original feature PR https://github.com/coral-xyz/anchor/pull/2438#issuecomment-1563457398 and then as mentioned here in tests https://github.com/coral-xyz/anchor/blob/v0.29.0/tests/events/tests/events.ts#L61-L62
Maybe there are at least some utilities elsewhere for this purpose?
Subscribing to the CPI events is more complicated than the log based default events. It's possible, but not as efficient to do with the regular PRC methods.
We should definitely add parsing utilities for CPI events though. It's been on my todo list for a while but I couldn't get to it yet.