UNPKG

interchainjs

Version:

InterchainJS is a JavaScript library for interacting with Cosmos SDK based blockchains.

41 lines (40 loc) 1.32 kB
/** * This file and any referenced files were automatically generated by @hyperweb/telescope@1.17.4 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ import { createCosmosQueryClient } from "@interchainjs/cosmos"; const _rpcClients = {}; export const getRpcEndpointKey = (rpcEndpoint) => { if (typeof rpcEndpoint === 'string') { return rpcEndpoint; } else if (!!rpcEndpoint) { //@ts-ignore return rpcEndpoint.url; } }; export const getRpcClient = async (rpcEndpoint) => { const key = getRpcEndpointKey(rpcEndpoint); if (!key) return; if (_rpcClients.hasOwnProperty(key)) { return _rpcClients[key]; } const rpc = await createRpcClient(rpcEndpoint); _rpcClients[key] = rpc; return rpc; }; export const createRpcClient = async (rpcEndpoint, options) => { if (typeof rpcEndpoint === 'string') { return createCosmosQueryClient(rpcEndpoint, options); } else { const endpointStr = rpcEndpoint.url; const clientOptions = { ...options, headers: rpcEndpoint.headers }; return createCosmosQueryClient(endpointStr, clientOptions); } };