"use strict";
/**
* This file and any referenced files were automatically generated by @hyperweb/telescope@1.17.0
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRpcClient = exports.getRpcClient = exports.getRpcEndpointKey = void 0;
const cosmos_1 = require("@interchainjs/cosmos");
const _rpcClients = {};
const getRpcEndpointKey = (rpcEndpoint) => {
    if (typeof rpcEndpoint === 'string') {
        return rpcEndpoint;
    }
    else if (!!rpcEndpoint) {
        //@ts-ignore
        return rpcEndpoint.url;
    }
};
exports.getRpcEndpointKey = getRpcEndpointKey;
const getRpcClient = async (rpcEndpoint) => {
    const key = (0, exports.getRpcEndpointKey)(rpcEndpoint);
    if (!key)
        return;
    if (_rpcClients.hasOwnProperty(key)) {
        return _rpcClients[key];
    }
    const rpc = await (0, exports.createRpcClient)(rpcEndpoint);
    _rpcClients[key] = rpc;
    return rpc;
};
exports.getRpcClient = getRpcClient;
const createRpcClient = async (rpcEndpoint, options) => {
    if (typeof rpcEndpoint === 'string') {
        return (0, cosmos_1.createCosmosQueryClient)(rpcEndpoint, options);
    }
    else {
        const endpointStr = rpcEndpoint.url;
        const clientOptions = {
            ...options,
            headers: rpcEndpoint.headers
        };
        return (0, cosmos_1.createCosmosQueryClient)(endpointStr, clientOptions);
    }
};
exports.createRpcClient = createRpcClient;
