Skip to content

Commit

Permalink
ts: Add commitment param to addEventListener (#3052)
Browse files Browse the repository at this point in the history
  • Loading branch information
livthomas authored Jun 26, 2024
1 parent 70d4f48 commit 18cc94b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions ts/packages/anchor/src/program/event.ts
Original file line number Diff line number Diff line change
@@ -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: ";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -116,7 +117,8 @@ export class EventManager {
});
}
}
}
},
commitment
);

return listener;
Expand Down
33 changes: 17 additions & 16 deletions ts/packages/anchor/src/program/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 18cc94b

Please sign in to comment.