feat: add filters support to the connection.onProgramAccountChange method (#18257)

* add filters support to the connection.onProgramAccountChange method

* add jsdoc comment

* chore: lint

Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
Tommy Johnson 2021-06-28 10:21:47 -04:00 committed by GitHub
parent 1793a6eb5d
commit c2124154a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -1725,6 +1725,7 @@ type ProgramAccountSubscriptionInfo = {
callback: ProgramAccountChangeCallback;
commitment?: Commitment;
subscriptionId: SubscriptionId | null; // null when there's no current server subscription id
filters?: GetProgramAccountsFilter[];
};
/**
@ -3708,7 +3709,9 @@ export class Connection {
this._subscribe(
sub,
'programSubscribe',
this._buildArgs([sub.programId], sub.commitment, 'base64'),
this._buildArgs([sub.programId], sub.commitment, 'base64', {
filters: sub.filters,
}),
);
}
@ -3830,12 +3833,14 @@ export class Connection {
* @param programId Public key of the program to monitor
* @param callback Function to invoke whenever the account is changed
* @param commitment Specify the commitment level account changes must reach before notification
* @param filters The program account filters to pass into the RPC method
* @return subscription id
*/
onProgramAccountChange(
programId: PublicKey,
callback: ProgramAccountChangeCallback,
commitment?: Commitment,
filters?: GetProgramAccountsFilter[],
): number {
const id = ++this._programAccountChangeSubscriptionCounter;
this._programAccountChangeSubscriptions[id] = {
@ -3843,6 +3848,7 @@ export class Connection {
callback,
commitment,
subscriptionId: null,
filters,
};
this._updateSubscriptions();
return id;