fix: support http endpoints (#433)

This commit is contained in:
Michael Vines 2019-07-26 14:54:51 -07:00
parent 677c075ade
commit d9f40bb879
3 changed files with 30 additions and 9 deletions

View File

@ -9,7 +9,7 @@ const solanaWeb3 = require('..');
const account = new solanaWeb3.Account(); const account = new solanaWeb3.Account();
let url; let url;
url = 'https://testnet.solana.com:8443'; url = 'http://testnet.solana.com:8899';
//url = 'http://localhost:8899'; //url = 'http://localhost:8899';
const connection = new solanaWeb3.Connection(url); const connection = new solanaWeb3.Connection(url);

View File

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

View File

@ -11,6 +11,14 @@ test('edge', () => {
expect(testnetChannelEndpoint('edge')).toEqual( expect(testnetChannelEndpoint('edge')).toEqual(
'https://edge.testnet.solana.com:8443', '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', () => { test('default', () => {