SHA256
Обновить настройки серверов и выбор Solana RPC
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { rpcEndpointFromShineHttp } from './solana-rpc-gateway.js';
|
||||
|
||||
// Старые настройки не содержали выбора RPC: всегда использовался шлюз.
|
||||
export function readSolanaEndpointSettings(settings, shineHttp) {
|
||||
const customSolanaServer = String(settings?.customSolanaServer || '').trim();
|
||||
const solanaRpcMode = settings?.solanaRpcMode === 'custom' && customSolanaServer ? 'custom' : 'gateway';
|
||||
return { solanaRpcMode, customSolanaServer,
|
||||
solanaServer: solanaRpcMode === 'custom' ? customSolanaServer : rpcEndpointFromShineHttp(shineHttp) };
|
||||
}
|
||||
|
||||
export function validateHttpEndpoint(value) {
|
||||
const raw = String(value || '').trim();
|
||||
const url = new URL(raw);
|
||||
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.hash) throw new Error('Invalid HTTP endpoint');
|
||||
return raw;
|
||||
}
|
||||
|
||||
const genesisPrefixes = {
|
||||
'mainnet-beta': '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
||||
devnet: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
|
||||
testnet: '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
|
||||
};
|
||||
|
||||
export async function verifyCustomSolanaCluster(endpoint, cluster, fetchRpc = fetch) {
|
||||
const expected = genesisPrefixes[cluster];
|
||||
if (!expected) return false;
|
||||
try {
|
||||
const response = await fetchRpc(endpoint, {
|
||||
method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getGenesisHash', params: [] }),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
});
|
||||
if (!response.ok) return false;
|
||||
const json = await response.json();
|
||||
return typeof json.result === 'string' && json.result.startsWith(expected);
|
||||
} catch { return false; }
|
||||
}
|
||||
Reference in New Issue
Block a user