fix: add testnetChannelEndpoint()

This commit is contained in:
Michael Vines
2018-12-19 19:28:28 -08:00
parent b5d058e88f
commit 62c1efc955
8 changed files with 69 additions and 14 deletions

View File

@ -10,7 +10,7 @@ channel=$(
} catch (err) {
p = require("../package.json");
}
p["solana-channel"]
p["testnetDefaultChannel"]
'
)

View File

@ -262,4 +262,7 @@ declare module '@solana/web3.js' {
connection: Connection,
wireTransaction: Buffer,
): Promise<TransactionSignature>;
// === src/util/testnet.js ===
declare export function testnetChannelEndpoint(channel?: string): string;
}

View File

@ -24,7 +24,7 @@
"bin": {
"solana-localnet": "bin/localnet.sh"
},
"solana-channel": "beta",
"testnetDefaultChannel": "beta",
"files": [
"/bin",
"/doc",
@ -37,7 +37,7 @@
"scripts": {
"bpf-sdk:install": "set -ex; npm run bpf-sdk:fetch; npm run bpf-sdk:extract",
"bpf-sdk:extract": "test -d bpf-sdk || tar jxvf bpf-sdk.tar.bz2",
"bpf-sdk:fetch": "test -f bpf-sdk.tar.bz2 || curl http://solana-sdk.s3.amazonaws.com/$npm_package_solana_channel/bpf-sdk.tar.bz2 -o bpf-sdk.tar.bz2",
"bpf-sdk:fetch": "test -f bpf-sdk.tar.bz2 || curl http://solana-sdk.s3.amazonaws.com/$npm_package_testnetDefaultChannel/bpf-sdk.tar.bz2 -o bpf-sdk.tar.bz2",
"bpf-sdk:remove-symlinks": "find bpf-sdk -type l -print -exec cp {} {}.tmp \\; -exec mv {}.tmp {} \\;",
"build": "cross-env NODE_ENV=production rollup -c",
"clean": "rimraf ./coverage ./lib",
@ -55,8 +55,8 @@
"lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
"localnet:down": "bin/localnet.sh down",
"localnet:logs": "bin/localnet.sh logs -f",
"localnet:up": "bin/localnet.sh up $npm_package_solana_channel",
"localnet:update": "bin/localnet.sh update $npm_package_solana_channel",
"localnet:up": "bin/localnet.sh up $npm_package_testnetDefaultChannel",
"localnet:update": "bin/localnet.sh update $npm_package_testnetDefaultChannel",
"ok": "set -ex; npm run lint; npm run flow; npm run test; npm run doc",
"prepare": "set -ex; npm run clean; npm run bpf-sdk:install; npm run build; rm -rf bpf-sdk; npm rum bpf-sdk:extract; npm run bpf-sdk:remove-symlinks",
"pretty": "prettier --write '{,{examples,src,test}/**/}*.js'",

View File

@ -13,3 +13,4 @@ export {sendAndConfirmTransaction} from './util/send-and-confirm-transaction';
export {
sendAndConfirmRawTransaction,
} from './util/send-and-confirm-raw-transaction';
export {testnetChannelEndpoint} from './util/testnet';

View File

@ -168,7 +168,9 @@ export class Transaction {
programIds.push(programId);
}
instruction.keys.map(key => key.toString()).forEach(key => {
instruction.keys
.map(key => key.toString())
.forEach(key => {
if (!keys.includes(key)) {
keys.push(key);
}

View File

@ -0,0 +1,27 @@
//@flow
import {testnetDefaultChannel} from '../../package.json';
/**
* @private
*/
const endpoint = {
edge: 'https://api.edge.testnet.solana.com',
beta: 'https://api.beta.testnet.solana.com',
stable: 'https://api.testnet.solana.com',
};
/**
* Retrieves the RPC endpoint URL for the specified testnet release
* channel
*/
export function testnetChannelEndpoint(channel?: string): string {
if (!channel) {
return endpoint[testnetDefaultChannel];
}
if (endpoint[channel]) {
return endpoint[channel];
}
throw new Error(`Unknown channel: ${channel}`);
}

View File

@ -0,0 +1,18 @@
// @flow
import {testnetChannelEndpoint} from '../src/util/testnet';
test('invalid', () => {
expect(() => {
testnetChannelEndpoint('abc123');
}).toThrow();
});
test('edge', () => {
expect(testnetChannelEndpoint('edge')).toEqual(
'https://api.edge.testnet.solana.com',
);
});
test('default', () => {
testnetChannelEndpoint(); // Should not throw
});

View File

@ -6,8 +6,12 @@
export const url = 'http://localhost:8899/';
//export const url = 'http://edge.testnet.solana.com:8899/';
//export const url = 'http://beta.edge.testnet.solana.com:8899/';
/*
export const url = 'http://edge.testnet.solana.com:8899/';
export const url = 'http://beta.testnet.solana.com:8899/';
export const url = 'http://testnet.solana.com:8899/';
//export const url = 'http://testnet.solana.com:8899/';
//export const url = 'https://api.testnet.solana.com/';
export const url = 'https://api.edge.testnet.solana.com/';
export const url = 'https://api.beta.testnet.solana.com/';
export const url = 'https://api.testnet.solana.com/';
*/