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

Add get program accounts RPC method #1522

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

mcintyre94
Copy link
Contributor

@mcintyre94 mcintyre94 commented Aug 10, 2023

This PR adds the getProgramAccounts RPC method for experimental web3js

This is very similar to getMultipleAccounts, with the fun extra quirk that it can return either an RPC response or not, depending on the value of withContext. Annoyingly my attempts to use a conditional type (Typescript playground) didn't work, it just always returned T | RpcResponse<T>. I suspect this is the same underlying issue as #1280

So instead this method has 10 overloads, (4 encodings + no encoding) * 2 options for withContext. The previous limit was 5, so that's why there's a change to json-rpc-types.ts

I also decided against refactoring to try to share data structures between getAccountInfo, getMultipleAccounts and getProgramAccounts. They have subtly different behaviours/structures and I think it's just clearer to keep them as-is for now.

Ref #1449

@mcintyre94 mcintyre94 requested a review from buffalojoec August 10, 2023 14:15
Copy link
Contributor

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!! What a beast

@mcintyre94 mcintyre94 force-pushed the get-program-accounts branch from d3d77bd to 2f844e8 Compare August 10, 2023 15:49
@mcintyre94 mcintyre94 merged commit a22700c into solana-labs:master Aug 11, 2023
@mcintyre94 mcintyre94 deleted the get-program-accounts branch August 11, 2023 09:49
@@ -127,6 +127,142 @@ export const ALLOWED_NUMERIC_KEYPATHS: Partial<
['value', KEYPATH_WILDCARD, 'data', 'parsed', 'info', 'commission'],
['value', KEYPATH_WILDCARD, 'data', 'parsed', 'info', 'votes', KEYPATH_WILDCARD, 'confirmationCount'],
],
getProgramAccounts: [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. Related comment: #1492 (comment)

Comment on lines +90 to +109
expect(accountInfo[0]).toMatchObject({
account: expect.objectContaining({
data: expect.any(String),
executable: expect.any(Boolean),
lamports: expect.any(BigInt),
owner: expect.any(String),
rentEpoch: expect.any(BigInt),
space: expect.any(BigInt),
}),
pubkey: expect.any(String),
});
expect(accountInfo[1]).toMatchObject({
account: expect.objectContaining({
data: expect.any(String),
executable: expect.any(Boolean),
lamports: expect.any(BigInt),
owner: expect.any(String),
rentEpoch: expect.any(BigInt),
space: expect.any(BigInt),
}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually assert on the values of the accounts, since they come from fixtures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely could, we just have a lot of tests already that don't

Copy link
Contributor

@buffalojoec buffalojoec Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of think we should. It's an easy lay-up for completing some of these tests and asserting proper functionality. Happy to start this work

We just have to make sure we don't change fixtures! 😝

Comment on lines +90 to +98
getProgramAccounts(
program: Base58EncodedAddress,
config: GetProgramAccountsApiCommonConfig &
GetProgramAccountsApiSliceableCommonConfig &
Readonly<{
encoding: 'base64';
withContext: true;
}>
): RpcResponse<AccountWithPubkey<AccountInfoBase & AccountInfoWithBase64EncodedData>[]>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it won't - I did something similar here: https://solanalabs.slack.com/archives/C050QNCV6BU/p1691418848861819

This playground works correctly

But when I used the same pattern in this codebase it wouldn't work, and just treated the output as like number | RpcResponse<number> for any input

I think it might be the same underlying issue as #1280 but I'm not sure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fucked around and found out (that there's a TypeScript bug). #1531

@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.78.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants