Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
refactor(experimental): add cluster level API for rpc-core
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Feb 1, 2024
1 parent 0f48e23 commit 6d6c2fa
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions packages/rpc-core/src/rpc-methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { createJsonRpcApi } from '@solana/rpc-transport';
import { IRpcApi } from '@solana/rpc-types';
import {
IIRpcTransport,
IRpcApi,
IRpcTransportDevnet,
IRpcTransportMainnet,
IRpcTransportTestnet,
} from '@solana/rpc-types';

import { getParamsPatcherForSolanaLabsRpc, ParamsPatcherConfig } from '../params-patcher';
import { patchResponseForSolanaLabsRpc } from '../response-patcher';
Expand Down Expand Up @@ -112,9 +118,25 @@ 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 IIRpcTransport> = 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 6d6c2fa

Please sign in to comment.