-
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { GetBlockHeightApi } from './rpc-methods/getBlockHeight'; | ||
| import { GetBlocksApi } from './rpc-methods/getBlocks'; | ||
|
|
||
| declare interface JsonRpcApi extends GetBlockHeightApi, GetBlocksApi {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // TODO: Eventually move this into whatever package implements transactions | ||
| declare type Finality = 'confirmed' | 'finalized' | 'processed'; | ||
|
|
||
| declare type Slot = | ||
| // TODO(solana-labs/solana/issues/30341) Represent as bigint | ||
| number; | ||
|
Comment on lines
+9
to
+11
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. I know we've talked about this before, so pardon asking it again here... with the BYO-Transport model, is it possible to require that transports properly handle u64s and make this a
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. So, fast forward to when everything is We can't do this today, because the Solana RPC doesn't accept them. # params is normally [5, 10] but here I'm representing them as ["5", "10"]
curl https://api.mainnet-beta.solana.com -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0", "id": 1,
"method": "getBlocks",
"params": ["5", "10"]
}
'
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params: invalid type: string \"5\", expected u64."},"id":1}We need to change the server to parse strings as
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. But I see what you're saying. You're saying: make it a
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. I love this!
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. I was wondering it if it would be possible at the transport level to use |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { IJsonRpcTransport } from '@solana/rpc-transport'; | ||
|
|
||
| type GetBlockHeightApiResponse = | ||
| // TODO(solana-labs/solana/issues/30341) Represent as bigint | ||
| number; | ||
|
|
||
| declare interface GetBlockHeightApi { | ||
| /** | ||
| * Returns the current block height of the node | ||
| */ | ||
| getBlockHeight( | ||
| transport: IJsonRpcTransport, | ||
| config?: readonly { | ||
| // Defaults to `finalized` | ||
| commitment?: Finality; | ||
| // The minimum slot that the request can be evaluated at | ||
| minContextSlot?: Slot; | ||
| } | ||
|
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. All these levels of optionals... I can swee why graphql would make this so much neater |
||
| ): Promise<GetBlockHeightApiResponse>; | ||
|
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. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { IJsonRpcTransport } from '@solana/rpc-transport'; | ||
|
|
||
| type GetBlocksApiResponse = Slot[]; | ||
|
|
||
| declare interface GetBlocksApi { | ||
| /** | ||
| * Returns a list of confirmed blocks between two slots | ||
| */ | ||
| getBlocks( | ||
| transport: IJsonRpcTransport, | ||
| startSlot: Slot, | ||
| endSlotInclusive?: Slot, | ||
| config?: readonly { | ||
| // Defaults to `finalized` | ||
| commitment?: Exclude<Finality, 'processed'>; | ||
| } | ||
| ): Promise<GetBlocksApiResponse>; | ||
|
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
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 the docs are wrong on this one :-\
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. I fixed them! I don't know why the change hasn't deployed yet. https://github.com/solana-labs/solana/pull/30351/files
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
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 yes. Anyway, thanks for fixing! |
||
| } | ||
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.