diff --git a/CHANGELOG.md b/CHANGELOG.md index e22b2dc27e..131e7201c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi ### Fixes +- ts: add optional `commitment` parameter to `Program.addEventListener` ([#3052](https://github.com/coral-xyz/anchor/pull/3052)) + ### Breaking ## [0.30.1] - 2024-06-20 diff --git a/ts/packages/anchor/src/program/event.ts b/ts/packages/anchor/src/program/event.ts index 42b41d5dbd..b10a2746d1 100644 --- a/ts/packages/anchor/src/program/event.ts +++ b/ts/packages/anchor/src/program/event.ts @@ -1,8 +1,8 @@ -import { PublicKey } from "@solana/web3.js"; -import { IdlEvent, IdlField } from "../idl.js"; +import { Commitment, PublicKey } from "@solana/web3.js"; import { Coder } from "../coder/index.js"; -import { DecodeType } from "./namespace/types.js"; +import { IdlEvent, IdlField } from "../idl.js"; import Provider from "../provider.js"; +import { DecodeType } from "./namespace/types.js"; const PROGRAM_LOG = "Program log: "; const PROGRAM_DATA = "Program data: "; @@ -73,7 +73,8 @@ export class EventManager { public addEventListener( eventName: string, - callback: (event: any, slot: number, signature: string) => void + callback: (event: any, slot: number, signature: string) => void, + commitment?: Commitment ): number { let listener = this._listenerIdCount; this._listenerIdCount += 1; @@ -116,7 +117,8 @@ export class EventManager { }); } } - } + }, + commitment ); return listener; diff --git a/ts/packages/anchor/src/program/index.ts b/ts/packages/anchor/src/program/index.ts index 3baa1ff73f..f073de9c2f 100644 --- a/ts/packages/anchor/src/program/index.ts +++ b/ts/packages/anchor/src/program/index.ts @@ -1,28 +1,28 @@ +import { Commitment, PublicKey } from "@solana/web3.js"; import { inflate } from "pako"; -import { PublicKey } from "@solana/web3.js"; -import Provider, { getProvider } from "../provider.js"; +import { BorshCoder, Coder } from "../coder/index.js"; import { Idl, - idlAddress, - decodeIdlAccount, IdlInstruction, convertIdlToCamelCase, + decodeIdlAccount, + idlAddress, } from "../idl.js"; -import { Coder, BorshCoder } from "../coder/index.js"; +import Provider, { getProvider } from "../provider.js"; +import { utf8 } from "../utils/bytes/index.js"; +import { CustomAccountResolver } from "./accounts-resolver.js"; +import { Address, translateAddress } from "./common.js"; +import { EventManager } from "./event.js"; import NamespaceFactory, { - RpcNamespace, - InstructionNamespace, - TransactionNamespace, AccountNamespace, - SimulateNamespace, + IdlEvents, + InstructionNamespace, MethodsNamespace, + RpcNamespace, + SimulateNamespace, + TransactionNamespace, ViewNamespace, - IdlEvents, } from "./namespace/index.js"; -import { utf8 } from "../utils/bytes/index.js"; -import { EventManager } from "./event.js"; -import { Address, translateAddress } from "./common.js"; -import { CustomAccountResolver } from "./accounts-resolver.js"; export * from "./common.js"; export * from "./context.js"; @@ -377,9 +377,10 @@ export class Program { event: IdlEvents[E], slot: number, signature: string - ) => void + ) => void, + commitment?: Commitment ): number { - return this._events.addEventListener(eventName, callback); + return this._events.addEventListener(eventName, callback, commitment); } /**