anchor icon indicating copy to clipboard operation
anchor copied to clipboard

No easy way to subscribe to self CPI logs

Open tanmaymunjal opened this issue 1 year ago • 3 comments

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.

tanmaymunjal avatar Aug 20 '23 17:08 tanmaymunjal

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.

acheroncrypto avatar Aug 21 '23 14:08 acheroncrypto

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?

ochaloup avatar Mar 28 '24 08:03 ochaloup

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.

acheroncrypto avatar Mar 28 '24 17:03 acheroncrypto