瀏覽代碼

ts: Add `commitment` param to `addEventListener` (#3052)

Tomáš Livora 1 年之前
父節點
當前提交
18cc94be94
共有 3 個文件被更改,包括 26 次插入21 次删除
  1. 2 0
      CHANGELOG.md
  2. 7 5
      ts/packages/anchor/src/program/event.ts
  3. 17 16
      ts/packages/anchor/src/program/index.ts

+ 2 - 0
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

+ 7 - 5
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;

+ 17 - 16
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<IDL extends Idl = Idl> {
       event: IdlEvents<IDL>[E],
       slot: number,
       signature: string
-    ) => void
+    ) => void,
+    commitment?: Commitment
   ): number {
-    return this._events.addEventListener(eventName, callback);
+    return this._events.addEventListener(eventName, callback, commitment);
   }
 
   /**