Skip to content

Commit

Permalink
fix: support http endpoints (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jun 15, 2020
1 parent 677c075 commit d9f40bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion web3.js/examples/get-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
29 changes: 21 additions & 8 deletions web3.js/src/util/testnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions web3.js/test/testnet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit d9f40bb

Please sign in to comment.