-
Notifications
You must be signed in to change notification settings - Fork 907
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
fix: onProgramAccountChange()
and onAccountChange()
now accept an encoding
#2861
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2787,6 +2787,39 @@ export type GetNonceAndContextConfig = { | |
minContextSlot?: number; | ||
}; | ||
|
||
export type AccountSubscriptionConfig = Readonly<{ | ||
/** Optional commitment level */ | ||
commitment?: Commitment; | ||
/** | ||
* Encoding format for Account data | ||
* - `base58` is slow. | ||
* - `jsonParsed` encoding attempts to use program-specific state parsers to return more | ||
* human-readable and explicit account state data | ||
* - If `jsonParsed` is requested but a parser cannot be found, the field falls back to `base64` | ||
* encoding, detectable when the `data` field is type `string`. | ||
*/ | ||
encoding?: 'base58' | 'base64' | 'base64+zstd' | 'jsonParsed'; | ||
}>; | ||
|
||
export type ProgramAccountSubscriptionConfig = Readonly<{ | ||
/** Optional commitment level */ | ||
commitment?: Commitment; | ||
/** | ||
* Encoding format for Account data | ||
* - `base58` is slow. | ||
* - `jsonParsed` encoding attempts to use program-specific state parsers to return more | ||
* human-readable and explicit account state data | ||
* - If `jsonParsed` is requested but a parser cannot be found, the field falls back to `base64` | ||
* encoding, detectable when the `data` field is type `string`. | ||
*/ | ||
encoding?: 'base58' | 'base64' | 'base64+zstd' | 'jsonParsed'; | ||
/** | ||
* Filter results using various filter objects | ||
* The resultant account must meet ALL filter criteria to be included in the returned results | ||
*/ | ||
filters?: GetProgramAccountsFilter[]; | ||
}>; | ||
|
||
/** | ||
* Information describing an account | ||
*/ | ||
|
@@ -6334,18 +6367,34 @@ export class Connection { | |
* | ||
* @param publicKey Public key of the account 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 config | ||
* @return subscription id | ||
*/ | ||
onAccountChange( | ||
publicKey: PublicKey, | ||
callback: AccountChangeCallback, | ||
config?: AccountSubscriptionConfig, | ||
): ClientSubscriptionId; | ||
/** @deprecated Instead, pass in an {@link AccountSubscriptionConfig} */ | ||
// eslint-disable-next-line no-dupe-class-members | ||
onAccountChange( | ||
publicKey: PublicKey, | ||
callback: AccountChangeCallback, | ||
commitment?: Commitment, | ||
): ClientSubscriptionId; | ||
Comment on lines
6380
to
+6384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing method signature for backward compatibility. |
||
// eslint-disable-next-line no-dupe-class-members | ||
onAccountChange( | ||
publicKey: PublicKey, | ||
callback: AccountChangeCallback, | ||
commitmentOrConfig?: Commitment | AccountSubscriptionConfig, | ||
): ClientSubscriptionId { | ||
const {commitment, config} = | ||
extractCommitmentFromConfig(commitmentOrConfig); | ||
const args = this._buildArgs( | ||
[publicKey.toBase58()], | ||
commitment || this._commitment || 'finalized', // Apply connection/server default. | ||
'base64', | ||
config, | ||
); | ||
return this._makeSubscription( | ||
{ | ||
|
@@ -6394,21 +6443,40 @@ 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 | ||
* @param config | ||
* @return subscription id | ||
*/ | ||
onProgramAccountChange( | ||
programId: PublicKey, | ||
callback: ProgramAccountChangeCallback, | ||
config?: ProgramAccountSubscriptionConfig, | ||
): ClientSubscriptionId; | ||
/** @deprecated Instead, pass in a {@link ProgramAccountSubscriptionConfig} */ | ||
// eslint-disable-next-line no-dupe-class-members | ||
onProgramAccountChange( | ||
programId: PublicKey, | ||
callback: ProgramAccountChangeCallback, | ||
commitment?: Commitment, | ||
filters?: GetProgramAccountsFilter[], | ||
): ClientSubscriptionId; | ||
Comment on lines
6456
to
+6461
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing method signature for backward compatibility. |
||
// eslint-disable-next-line no-dupe-class-members | ||
onProgramAccountChange( | ||
programId: PublicKey, | ||
callback: ProgramAccountChangeCallback, | ||
commitmentOrConfig?: Commitment | ProgramAccountSubscriptionConfig, | ||
maybeFilters?: GetProgramAccountsFilter[], | ||
): ClientSubscriptionId { | ||
const {commitment, config} = | ||
extractCommitmentFromConfig(commitmentOrConfig); | ||
const args = this._buildArgs( | ||
[programId.toBase58()], | ||
commitment || this._commitment || 'finalized', // Apply connection/server default. | ||
'base64' /* encoding */, | ||
filters ? {filters: filters} : undefined /* extra */, | ||
config | ||
? config | ||
: maybeFilters | ||
? {filters: maybeFilters} | ||
: undefined /* extra */, | ||
Comment on lines
+6475
to
+6479
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to TypeScript, you either have a config, or you have commitment/filters, but never both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little gross, but wfm. |
||
); | ||
return this._makeSubscription( | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I laughed at this, until I realized it's actually what's in the docs. 😅