-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up SolanaRpcApi: no longer extend RpcApiMethods (#3213)
Extending `RpcApiMethods` removes the ability to access typed keys on `SolanaRpcApi` etc, because it's typed as `[method: string]: RpcApiMethod`. In this PR we change from: ```ts interface GetAssetApi extends RpcApiMethods { ``` To: ```ts type GetAssetApi = { ``` (Thanks @lorisleiva!) This allows `createRpcApi` to maintain its typing, meaning that it still constrains any API methods we attempt to build an RPC for. But we now have typesafe `keyof SolanaRpcApi` etc. I've also removed the export of `RpcApiMethods`, since this should now be used only as a constraint internally and not a type externally. I've added a typetest with a bit more detail, but this basically makes this work: ```ts 'getAccountInfo' satisfies keyof SolanaRpcApi; // @ts-expect-error RPC API does not have this method 'someMadeUpMethod' satisfies keyof SolanaRpcApi; ``` Previously `someMadeUpMethod` would satisfy it, because `keyof SolanaRpcApi` was just string.
- Loading branch information
1 parent
3df153c
commit 3fc388f
Showing
68 changed files
with
157 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@solana/rpc-graphql': patch | ||
'@solana/accounts': patch | ||
'@solana/rpc-spec': patch | ||
'@solana/rpc-api': patch | ||
--- | ||
|
||
Clean up SolanaRpcApi: no longer extend RpcApiMethods + remove export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { SolanaRpcApi, SolanaRpcApiDevnet, SolanaRpcApiMainnet, SolanaRpcApiTestnet } from '..'; | ||
|
||
'getAccountInfo' satisfies keyof SolanaRpcApi; | ||
// @ts-expect-error RPC API does not have this method | ||
'someMadeUpMethod' satisfies keyof SolanaRpcApi; | ||
|
||
// if we extend the RPC API with additional methods, we can access them on keyof | ||
type TestRpcApi = SolanaRpcApi & { | ||
someMadeUpMethod: () => void; | ||
}; | ||
'someMadeUpMethod' satisfies keyof TestRpcApi; | ||
|
||
// request airdrop is available on test networks, but not mainnet | ||
'requestAirdrop' satisfies keyof SolanaRpcApiDevnet; | ||
'requestAirdrop' satisfies keyof SolanaRpcApiTestnet; | ||
'requestAirdrop' satisfies keyof SolanaRpcApi; | ||
// @ts-expect-error requestAirdrop is not available on mainnet | ||
'requestAirdrop' satisfies keyof SolanaRpcApiMainnet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import type { RpcApiMethods } from '@solana/rpc-spec'; | ||
import type { LamportsUnsafeBeyond2Pow53Minus1, Slot } from '@solana/rpc-types'; | ||
|
||
type GetBlockCommitmentApiResponse = Readonly<{ | ||
commitment: LamportsUnsafeBeyond2Pow53Minus1[] | null; | ||
totalStake: LamportsUnsafeBeyond2Pow53Minus1; | ||
}>; | ||
|
||
export interface GetBlockCommitmentApi extends RpcApiMethods { | ||
export type GetBlockCommitmentApi = { | ||
/** | ||
* Returns the amount of cluster stake in lamports that has voted on | ||
* a particular block, as well as the stake attributed to each vote account | ||
*/ | ||
getBlockCommitment(slot: Slot): GetBlockCommitmentApiResponse; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import type { RpcApiMethods } from '@solana/rpc-spec'; | ||
import type { Slot, UnixTimestampUnsafeBeyond2Pow53Minus1 } from '@solana/rpc-types'; | ||
|
||
/** Estimated production time, as Unix timestamp (seconds since the Unix epoch) */ | ||
type GetBlockTimeApiResponse = UnixTimestampUnsafeBeyond2Pow53Minus1; | ||
|
||
export interface GetBlockTimeApi extends RpcApiMethods { | ||
export type GetBlockTimeApi = { | ||
/** | ||
* Returns the estimated production time of a block. | ||
*/ | ||
getBlockTime( | ||
/** block number, identified by Slot */ | ||
blockNumber: Slot, | ||
): GetBlockTimeApiResponse; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.