diff --git a/packages/rpc-transport-http/src/__tests__/is-solana-request-test.ts b/packages/rpc-transport-http/src/__tests__/is-solana-request-test.ts new file mode 100644 index 000000000000..a0fa85c32a86 --- /dev/null +++ b/packages/rpc-transport-http/src/__tests__/is-solana-request-test.ts @@ -0,0 +1,12 @@ +import { isSolanaRequest } from '../is-solana-request'; + +describe('isSolanaRequest', () => { + it('returns true if the method name is from the Solana RPC API', () => { + const request = { methodName: 'getBalance', params: ['1234..5678'] }; + expect(isSolanaRequest(request)).toBe(true); + }); + it('returns false if the method name is not from the Solana RPC API', () => { + const request = { methodName: 'getAssetsByAuthority', params: ['1234..5678'] }; + expect(isSolanaRequest(request)).toBe(false); + }); +}); diff --git a/packages/rpc-transport-http/src/is-solana-request.ts b/packages/rpc-transport-http/src/is-solana-request.ts new file mode 100644 index 000000000000..47bb0fbb3c65 --- /dev/null +++ b/packages/rpc-transport-http/src/is-solana-request.ts @@ -0,0 +1,65 @@ +import type { RpcRequest } from '@solana/rpc-spec'; + +const SOLANA_RPC_METHODS: string[] = [ + 'getAccountInfo', + 'getBalance', + 'getBlock', + 'getBlockCommitment', + 'getBlockHeight', + 'getBlockProduction', + 'getBlocks', + 'getBlocksWithLimit', + 'getBlockTime', + 'getClusterNodes', + 'getEpochInfo', + 'getEpochSchedule', + 'getFeeForMessage', + 'getFirstAvailableBlock', + 'getGenesisHash', + 'getHealth', + 'getHighestSnapshotSlot', + 'getIdentity', + 'getInflationGovernor', + 'getInflationRate', + 'getInflationReward', + 'getLargestAccounts', + 'getLatestBlockhash', + 'getLeaderSchedule', + 'getMaxRetransmitSlot', + 'getMaxShredInsertSlot', + 'getMinimumBalanceForRentExemption', + 'getMultipleAccounts', + 'getProgramAccounts', + 'getRecentPerformanceSamples', + 'getRecentPrioritizationFees', + 'getSignaturesForAddress', + 'getSignatureStatuses', + 'getSlot', + 'getSlotLeader', + 'getSlotLeaders', + 'getStakeActivation', + 'getStakeMinimumDelegation', + 'getSupply', + 'getTokenAccountBalance', + 'getTokenAccountsByDelegate', + 'getTokenAccountsByOwner', + 'getTokenLargestAccounts', + 'getTokenSupply', + 'getTransaction', + 'getTransactionCount', + 'getVersion', + 'getVoteAccounts', + 'index', + 'isBlockhashValid', + 'minimumLedgerSlot', + 'requestAirdrop', + 'sendTransaction', + 'simulateTransaction', +]; + +/** + * Helper function that checks if a given `RpcRequest` comes from the Solana RPC API. + */ +export function isSolanaRequest(request: RpcRequest): boolean { + return SOLANA_RPC_METHODS.includes(request.methodName); +}