feat: rename testnet util methods

This commit is contained in:
Justin Starry
2020-03-30 20:27:09 +08:00
committed by Michael Vines
parent 352f296c09
commit aeedd3867f
8 changed files with 65 additions and 73 deletions

View File

@@ -30,7 +30,7 @@ export {
sendAndConfirmRecentTransaction,
} from './util/send-and-confirm-transaction';
export {sendAndConfirmRawTransaction} from './util/send-and-confirm-raw-transaction';
export {testnetChannelEndpoint} from './util/testnet';
export {clusterApiUrl} from './util/cluster';
/**
* There are 1-billion lamports in one SOL

View File

@@ -0,0 +1,36 @@
//@flow
/**
* @private
*/
const endpoint = {
http: {
devnet: 'http://devnet.solana.com',
testnet: 'http://testnet.solana.com',
'mainnet-beta': 'http://api.mainnet-beta.solana.com',
},
https: {
devnet: 'https://devnet.solana.com',
testnet: 'https://testnet.solana.com',
'mainnet-beta': 'https://api.mainnet-beta.solana.com',
},
};
export type Cluster = 'devnet' | 'testnet' | 'mainnet-beta';
/**
* Retrieves the RPC API URL for the specified cluster
*/
export function clusterApiUrl(cluster?: Cluster, tls?: boolean): string {
const key = tls === false ? 'http' : 'https';
if (!cluster) {
return endpoint[key]['devnet'];
}
const url = endpoint[key][cluster];
if (!url) {
throw new Error(`Unknown ${key} cluster: ${cluster}`);
}
return url;
}

View File

@@ -1,40 +0,0 @@
//@flow
import {testnetDefaultChannel} from '../../package.json';
/**
* @private
*/
const endpoint = {
http: {
edge: 'http://edge.devnet.solana.com:8899',
beta: 'http://beta.devnet.solana.com:8899',
stable: 'http://devnet.solana.com',
},
https: {
edge: 'https://edge.devnet.solana.com:8443',
beta: 'https://beta.devnet.solana.com:8443',
stable: 'https://devnet.solana.com',
},
};
/**
* Retrieves the RPC endpoint URL for the specified testnet release
* channel
*/
export function testnetChannelEndpoint(
channel?: string,
tls?: boolean,
): string {
const key = tls === false ? 'http' : 'https';
if (!channel) {
return endpoint[key][testnetDefaultChannel];
}
const url = endpoint[key][channel];
if (!url) {
throw new Error(`Unknown ${key} channel: ${channel}`);
}
return url;
}