feat: rename testnet util methods
This commit is contained in:
parent
352f296c09
commit
aeedd3867f
|
@ -16,3 +16,4 @@ experimental.const_params=true
|
|||
include_warnings=true
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowIgnore
|
||||
|
|
|
@ -662,11 +662,11 @@ declare module '@solana/web3.js' {
|
|||
commitment?: Commitment,
|
||||
): Promise<TransactionSignature>;
|
||||
|
||||
// === src/util/testnet.js ===
|
||||
export function testnetChannelEndpoint(
|
||||
channel?: string,
|
||||
tls?: boolean,
|
||||
): string;
|
||||
// === src/util/cluster.js ===
|
||||
export type Cluster = 'devnet' | 'testnet' | 'mainnet-beta';
|
||||
|
||||
export function clusterApiUrl(cluster?: Cluster, tls?: boolean): string;
|
||||
|
||||
// === src/index.js ===
|
||||
export const LAMPORTS_PER_SOL: number;
|
||||
}
|
||||
|
|
|
@ -676,11 +676,14 @@ declare module '@solana/web3.js' {
|
|||
commitment: ?Commitment,
|
||||
): Promise<TransactionSignature>;
|
||||
|
||||
// === src/util/testnet.js ===
|
||||
declare export function testnetChannelEndpoint(
|
||||
channel?: string,
|
||||
// === src/util/cluster.js ===
|
||||
declare export type Cluster = 'devnet' | 'testnet' | 'mainnet-beta';
|
||||
|
||||
declare export function clusterApiUrl(
|
||||
cluster?: Cluster,
|
||||
tls?: boolean,
|
||||
): string;
|
||||
|
||||
// === src/index.js ===
|
||||
declare export var LAMPORTS_PER_SOL: number;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// @flow
|
||||
import {clusterApiUrl} from '../src/util/cluster';
|
||||
|
||||
test('invalid', () => {
|
||||
expect(() => {
|
||||
// $FlowIgnore
|
||||
clusterApiUrl('abc123');
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
test('devnet', () => {
|
||||
expect(clusterApiUrl()).toEqual('https://devnet.solana.com');
|
||||
expect(clusterApiUrl('devnet')).toEqual('https://devnet.solana.com');
|
||||
expect(clusterApiUrl('devnet', true)).toEqual('https://devnet.solana.com');
|
||||
expect(clusterApiUrl('devnet', false)).toEqual('http://devnet.solana.com');
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
// @flow
|
||||
import {testnetChannelEndpoint} from '../src/util/testnet';
|
||||
|
||||
test('invalid', () => {
|
||||
expect(() => {
|
||||
testnetChannelEndpoint('abc123');
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
test('stable', () => {
|
||||
expect(testnetChannelEndpoint('stable')).toEqual('https://devnet.solana.com');
|
||||
|
||||
expect(testnetChannelEndpoint('stable', true)).toEqual(
|
||||
'https://devnet.solana.com',
|
||||
);
|
||||
|
||||
expect(testnetChannelEndpoint('stable', false)).toEqual(
|
||||
'http://devnet.solana.com',
|
||||
);
|
||||
});
|
||||
|
||||
test('default', () => {
|
||||
testnetChannelEndpoint(); // Should not throw
|
||||
});
|
Loading…
Reference in New Issue