Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts: add commitment param to addEventListener #3052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading