From d9f40bb8798384f732595508660a640623a02ce7 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 26 Jul 2019 14:54:51 -0700 Subject: [PATCH] fix: support http endpoints (#433) --- web3.js/examples/get-balance.js | 2 +- web3.js/src/util/testnet.js | 29 +++++++++++++++++++++-------- web3.js/test/testnet.test.js | 8 ++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/web3.js/examples/get-balance.js b/web3.js/examples/get-balance.js index 68c1075ee..d2358afe4 100644 --- a/web3.js/examples/get-balance.js +++ b/web3.js/examples/get-balance.js @@ -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); diff --git a/web3.js/src/util/testnet.js b/web3.js/src/util/testnet.js index ce1947e57..2d5c33b65 100644 --- a/web3.js/src/util/testnet.js +++ b/web3.js/src/util/testnet.js @@ -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; } diff --git a/web3.js/test/testnet.test.js b/web3.js/test/testnet.test.js index 4f590d960..ad943b58f 100644 --- a/web3.js/test/testnet.test.js +++ b/web3.js/test/testnet.test.js @@ -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', () => {