import { SuiChainId } from '@sentio/chain';
import { Endpoints } from '@sentio/runtime';
// import { ServerError, Status } from 'nice-grpc'
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
export const SuiNetwork = {
    MAIN_NET: SuiChainId.SUI_MAINNET,
    TEST_NET: SuiChainId.SUI_TESTNET
};
function inferNetworkFromUrl(url) {
    if (url.includes('mainnet'))
        return 'mainnet';
    if (url.includes('testnet'))
        return 'testnet';
    if (url.includes('devnet'))
        return 'devnet';
    if (url.includes('localnet') || url.includes('127.0.0.1') || url.includes('localhost'))
        return 'localnet';
    return 'custom';
}
export function getClient(network) {
    let chainServer = Endpoints.INSTANCE.chainServer.get(network);
    if (!chainServer) {
        chainServer = getRpcEndpoint(network);
        // throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')
    }
    return new SuiJsonRpcClient({ url: chainServer, network: inferNetworkFromUrl(chainServer) });
}
export function getRpcEndpoint(network) {
    switch (network) {
        case SuiNetwork.TEST_NET:
            return 'https://fullnode.testnet.sui.io/';
    }
    return 'https://fullnode.mainnet.sui.io/';
}
//# sourceMappingURL=network.js.map