-
Notifications
You must be signed in to change notification settings - Fork 1k
[experimental] A types-only RPC implementation using JavaScript proxies #1190
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
Changes from 1 commit
0bc8528
e3f892d
b2a8a82
b87de1a
1cd7604
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { GetAccountInfoApi } from './rpc-methods/getAccountInfo'; | ||
| import { GetBlockHeightApi } from './rpc-methods/getBlockHeight'; | ||
| import { GetBlocksApi } from './rpc-methods/getBlocks'; | ||
|
|
||
| declare interface JsonRpcApi extends GetBlockHeightApi, GetBlocksApi {} | ||
| declare interface JsonRpcApi extends GetAccountInfoApi, GetBlockHeightApi, GetBlocksApi {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { Base58EncodedAddress } from '@solana/keys'; | ||
| import { IJsonRPCTransport } from '../../rpc'; | ||
|
|
||
| type Base64EncodedBytes = string & { readonly __base64EncodedBytes: unique symbol }; | ||
| type Base64EncodedZStdCompressedBytes = string & { readonly __base64EncodedZStdCompressedBytes: unique symbol }; | ||
|
|
||
| type Base64EncodedDataResponse = [Base64EncodedBytes, 'base64']; | ||
| type Base64EncodedZStdCompressedDataResponse = [Base64EncodedZStdCompressedBytes, 'base64+zstd']; | ||
|
|
||
| type GetAccountInfoApiResponseBase = Readonly<{ | ||
| context: Readonly<{ | ||
| slot: Slot; | ||
| }>; | ||
| value: Readonly<{ | ||
| executable: boolean; | ||
| lamports: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint | ||
| owner: Base64EncodedAddress; | ||
| rentEpoch: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint | ||
| space: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint | ||
|
Contributor
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. Maybe I'm missing something, but in testing I didn't see
Contributor
Author
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. Haha. In the docs, this is called
Contributor
Author
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.
Contributor
Author
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. Looks like this is only in v1.15.
Contributor
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. Ah gotcha |
||
| }> | null; | ||
| }>; | ||
|
|
||
| type GetAccountInfoApiResponseWithEncodedData = Readonly<{ | ||
| value: Readonly<{ | ||
| data: Base64EncodedDataResponse; | ||
| }> | null; | ||
| }>; | ||
|
|
||
| type GetAccountInfoApiResponseWithEncodedZStdCompressedData = Readonly<{ | ||
| value: Readonly<{ | ||
| data: Base64EncodedZStdCompressedDataResponse; | ||
| }> | null; | ||
| }>; | ||
|
|
||
| type GetAccountInfoApiResponseWithJsonData = Readonly<{ | ||
| value: Readonly<{ | ||
| data: | ||
| | Readonly<{ | ||
| // Name of the program that owns this account. | ||
| program: string; | ||
| parsed: unknown; | ||
| space: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint | ||
| }> | ||
| // If `jsonParsed` encoding is requested but a parser cannot be found for the given | ||
| // account the `data` field falls back to `base64`. | ||
| | Base64EncodedDataResponse; | ||
| }> | null; | ||
| }>; | ||
|
|
||
| type GetAccountInfoApiCommonConfig = readonly { | ||
| // Defaults to `finalized` | ||
| commitment?: Finality; | ||
| // The minimum slot that the request can be evaluated at | ||
| minContextSlot?: Slot; | ||
| }; | ||
|
|
||
| type GetAccountInfoApiBase64EncodingCommonConfig = readonly { | ||
| // Limit the returned account data using the provided "offset: <usize>" and "length: <usize>" fields. | ||
| dataSlice?: DataSlice; | ||
| }; | ||
|
|
||
| declare interface GetAccountInfoApi { | ||
| /** | ||
| * Returns all information associated with the account of provided public key | ||
| */ | ||
| getAccountInfo( | ||
| transport: IJsonRPCTransport, | ||
| address: Base58EncodedAddress, | ||
| config?: readonly { | ||
| encoding: 'base64'; | ||
| } & | ||
| GetAccountInfoApiCommonConfig & | ||
| GetAccountInfoApiBase64EncodingCommonConfig | ||
| ): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithEncodedData>; | ||
| getAccountInfo( | ||
| transport: IJsonRPCTransport, | ||
| address: Base58EncodedAddress, | ||
| config?: readonly { | ||
| encoding: 'base64+zstd'; | ||
| } & | ||
| GetAccountInfoApiCommonConfig & | ||
| GetAccountInfoApiBase64EncodingCommonConfig | ||
| ): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithEncodedZStdCompressedData>; | ||
| getAccountInfo( | ||
| transport: IJsonRPCTransport, | ||
| address: Base58EncodedAddress, | ||
| config?: readonly { | ||
| encoding: 'jsonParsed'; | ||
| } & | ||
| GetAccountInfoApiCommonConfig | ||
| ): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithJsonData>; | ||
|
Comment on lines
+66
to
+91
Contributor
Author
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. This is a much more complicated example, where you can see how modulating the inputs changes the output type (eg. specifying different Things to pay attention to:
Contributor
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. This is extremely cool, and not nearly as complicated to read as I feared when I first opened the file 😅 |
||
| } | ||
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.
nit: Is
Finalitythe new term? If so, we should probably update the docs and all that. I'd prefer to keep thisCommitmentto make mental mapping easier, but I won't put up a big fight about it.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.
Ooh. I thought these three were what we're calling finality, as opposed to the olde deprecated suite of commitments.
From web3.js today:
https://github.com/solana-labs/solana-web3.js/blob/ad23683e8a42c726995cf0c1f0f903b20152854f/packages/library-legacy/src/connection.ts#L476-L501
So yeah, I have this wrong, somehow. I'll rename it.