coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

ts: add commitment param to `Program.addEventListener` #3051

Closed livthomas closed 5 days ago

livthomas commented 6 days ago

Right now, if you call Program.addEventListener, you only get subscribed to Anchor events at the default commitment level set in the Connection instance. And if you want to receive events at multiple commitment levels, you need to create a separate connection for each.

It looks like Connection.onLogs method provides a third optional commitment parameter so it is actually possible to subscribe to the same event at multiple commitment levels using a single connection.

It would be nice if Program.addEventListener method also took an optional commitment parameter so we could use a single Solana connection across the whole app. Right now, we are basically forced to create multiple connection instances just because Anchor doesn't support this.

acheroncrypto commented 6 days ago

It would be nice if Program.addEventListener method also took an optional commitment parameter so we could use a single Solana connection across the whole app.

Sounds great! Feel free to create a PR for this, or let me know if you'd like me to add it.

livthomas commented 6 days ago

I have implemented it in https://github.com/coral-xyz/anchor/pull/3052

acheroncrypto commented 5 days ago

Added in https://github.com/coral-xyz/anchor/pull/3052