This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b4def2
commit f2d3b70
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/rpc-transport-http/src/__tests__/is-solana-request-test.ts
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,12 @@ | ||
import { isSolanaRequest } from '../is-solana-request'; | ||
|
||
describe('isSolanaRequest', () => { | ||
it('returns true if the method name is from the Solana RPC API', () => { | ||
const payload = { jsonrpc: '2.0', method: 'getBalance', params: ['1234..5678'] }; | ||
expect(isSolanaRequest(payload)).toBe(true); | ||
}); | ||
it('returns false if the method name is not from the Solana RPC API', () => { | ||
const payload = { jsonrpc: '2.0', method: 'getAssetsByAuthority', params: ['1234..5678'] }; | ||
expect(isSolanaRequest(payload)).toBe(false); | ||
}); | ||
}); |
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,69 @@ | ||
import { isJsonRpcPayload } from '@solana/rpc-spec'; | ||
|
||
const SOLANA_RPC_METHODS = [ | ||
'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', | ||
] as const; | ||
|
||
/** | ||
* Helper function that checks if a given `RpcRequest` comes from the Solana RPC API. | ||
*/ | ||
export function isSolanaRequest(payload: unknown): payload is Readonly<{ | ||
jsonrpc: '2.0'; | ||
method: (typeof SOLANA_RPC_METHODS)[number]; | ||
params: unknown; | ||
}> { | ||
return isJsonRpcPayload(payload) && (SOLANA_RPC_METHODS as readonly string[]).includes(payload.method); | ||
} |