fix: support http endpoints (#433)
This commit is contained in:
parent
677c075ade
commit
d9f40bb879
|
@ -9,7 +9,7 @@ const solanaWeb3 = require('..');
|
|||
const account = new solanaWeb3.Account();
|
||||
|
||||
let url;
|
||||
url = 'https://testnet.solana.com:8443';
|
||||
url = 'http://testnet.solana.com:8899';
|
||||
//url = 'http://localhost:8899';
|
||||
const connection = new solanaWeb3.Connection(url);
|
||||
|
||||
|
|
|
@ -6,22 +6,35 @@ import {testnetDefaultChannel} from '../../package.json';
|
|||
* @private
|
||||
*/
|
||||
const endpoint = {
|
||||
edge: 'https://edge.testnet.solana.com:8443',
|
||||
beta: 'https://beta.testnet.solana.com:8443',
|
||||
stable: 'https://testnet.solana.com:8443',
|
||||
http: {
|
||||
edge: 'http://edge.testnet.solana.com:8899',
|
||||
beta: 'http://beta.testnet.solana.com:8899',
|
||||
stable: 'http://testnet.solana.com:8899',
|
||||
},
|
||||
https: {
|
||||
edge: 'https://edge.testnet.solana.com:8443',
|
||||
beta: 'https://beta.testnet.solana.com:8443',
|
||||
stable: 'https://testnet.solana.com:8443',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the RPC endpoint URL for the specified testnet release
|
||||
* channel
|
||||
*/
|
||||
export function testnetChannelEndpoint(channel?: string): string {
|
||||
export function testnetChannelEndpoint(
|
||||
channel?: string,
|
||||
tls?: boolean,
|
||||
): string {
|
||||
const key = tls === false ? 'http' : 'https';
|
||||
|
||||
if (!channel) {
|
||||
return endpoint[testnetDefaultChannel];
|
||||
return endpoint[key][testnetDefaultChannel];
|
||||
}
|
||||
|
||||
if (endpoint[channel]) {
|
||||
return endpoint[channel];
|
||||
const url = endpoint[key][channel];
|
||||
if (!url) {
|
||||
throw new Error(`Unknown ${key} channel: ${channel}`);
|
||||
}
|
||||
throw new Error(`Unknown channel: ${channel}`);
|
||||
return url;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,14 @@ test('edge', () => {
|
|||
expect(testnetChannelEndpoint('edge')).toEqual(
|
||||
'https://edge.testnet.solana.com:8443',
|
||||
);
|
||||
|
||||
expect(testnetChannelEndpoint('edge', true)).toEqual(
|
||||
'https://edge.testnet.solana.com:8443',
|
||||
);
|
||||
|
||||
expect(testnetChannelEndpoint('edge', false)).toEqual(
|
||||
'http://edge.testnet.solana.com:8899',
|
||||
);
|
||||
});
|
||||
|
||||
test('default', () => {
|
||||
|
|
Loading…
Reference in New Issue