From 6d6c2fa6bfbfdeafc16eb0ad55683a11a70920b3 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 21 Jan 2024 12:47:16 -0600 Subject: [PATCH] refactor(experimental): add cluster level API for rpc-core --- packages/rpc-core/src/rpc-methods/index.ts | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/rpc-core/src/rpc-methods/index.ts b/packages/rpc-core/src/rpc-methods/index.ts index 9a262fbd18e1..3db555c76389 100644 --- a/packages/rpc-core/src/rpc-methods/index.ts +++ b/packages/rpc-core/src/rpc-methods/index.ts @@ -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'; @@ -112,9 +118,25 @@ export type SolanaRpcMethods = GetAccountInfoApi & RequestAirdropApi & SendTransactionApi & SimulateTransactionApi; +export type SolanaRpcMethodsDevnet = SolanaRpcMethods; +export type SolanaRpcMethodsTestnet = SolanaRpcMethods; +export type SolanaRpcMethodsMainnet = Omit; +export type SolanaRpcMethodsFromTransport = TTransport extends IRpcTransportDevnet + ? SolanaRpcMethodsDevnet + : TTransport extends IRpcTransportTestnet + ? SolanaRpcMethodsTestnet + : TTransport extends IRpcTransportMainnet + ? SolanaRpcMethodsMainnet + : SolanaRpcMethods; -export function createSolanaRpcApi(config?: Config): IRpcApi { - return createJsonRpcApi({ +export function createSolanaRpcApi< + TRpcMethods extends + | SolanaRpcMethods + | SolanaRpcMethodsDevnet + | SolanaRpcMethodsTestnet + | SolanaRpcMethodsMainnet = SolanaRpcMethods, +>(config?: Config): IRpcApi { + return createJsonRpcApi({ parametersTransformer: getParamsPatcherForSolanaLabsRpc(config) as (params: unknown[]) => unknown[], responseTransformer: patchResponseForSolanaLabsRpc, });