Skip to content

Commit

Permalink
refactor(experimental): add cluster level API for rpc-core
Browse files Browse the repository at this point in the history
Continuing the work from the cluster-level transports. Here I'm establishing the different cluster-specific
Solana APIs (no airdrop on mainnet, that's it). This sets up `createSolanaRpcApi()` to return pass-through
API type definitions, like `createJsonRpcApi()`.
  • Loading branch information
buffalojoec authored Feb 2, 2024
1 parent e58bb22 commit 5175d8a
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/rpc-core/src/rpc-methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { createJsonRpcApi } from '@solana/rpc-transport';
import {
createJsonRpcApi,
IRpcTransport,
IRpcTransportDevnet,
IRpcTransportMainnet,
IRpcTransportTestnet,
IRpcTransportWithCluster,
} from '@solana/rpc-transport';
import { IRpcApi } from '@solana/rpc-types';

import { getParamsPatcherForSolanaLabsRpc, ParamsPatcherConfig } from '../params-patcher';
Expand Down Expand Up @@ -112,9 +119,26 @@ export type SolanaRpcMethods = GetAccountInfoApi &
RequestAirdropApi &
SendTransactionApi &
SimulateTransactionApi;
export type SolanaRpcMethodsDevnet = SolanaRpcMethods;
export type SolanaRpcMethodsTestnet = SolanaRpcMethods;
export type SolanaRpcMethodsMainnet = Omit<SolanaRpcMethods, 'requestAirdrop'>;
export type SolanaRpcMethodsFromTransport<TTransport extends IRpcTransport | IRpcTransportWithCluster> =
TTransport extends IRpcTransportDevnet
? SolanaRpcMethodsDevnet
: TTransport extends IRpcTransportTestnet
? SolanaRpcMethodsTestnet
: TTransport extends IRpcTransportMainnet
? SolanaRpcMethodsMainnet
: SolanaRpcMethods;

export function createSolanaRpcApi(config?: Config): IRpcApi<SolanaRpcMethods> {
return createJsonRpcApi<SolanaRpcMethods>({
export function createSolanaRpcApi<
TRpcMethods extends
| SolanaRpcMethods
| SolanaRpcMethodsDevnet
| SolanaRpcMethodsTestnet
| SolanaRpcMethodsMainnet = SolanaRpcMethods,
>(config?: Config): IRpcApi<TRpcMethods> {
return createJsonRpcApi<TRpcMethods>({
parametersTransformer: getParamsPatcherForSolanaLabsRpc(config) as (params: unknown[]) => unknown[],
responseTransformer: patchResponseForSolanaLabsRpc,
});
Expand Down

0 comments on commit 5175d8a

Please sign in to comment.