fix: add testnetChannelEndpoint()
This commit is contained in:
@ -10,7 +10,7 @@ channel=$(
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
p = require("../package.json");
|
p = require("../package.json");
|
||||||
}
|
}
|
||||||
p["solana-channel"]
|
p["testnetDefaultChannel"]
|
||||||
'
|
'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -262,4 +262,7 @@ declare module '@solana/web3.js' {
|
|||||||
connection: Connection,
|
connection: Connection,
|
||||||
wireTransaction: Buffer,
|
wireTransaction: Buffer,
|
||||||
): Promise<TransactionSignature>;
|
): Promise<TransactionSignature>;
|
||||||
|
|
||||||
|
// === src/util/testnet.js ===
|
||||||
|
declare export function testnetChannelEndpoint(channel?: string): string;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"bin": {
|
"bin": {
|
||||||
"solana-localnet": "bin/localnet.sh"
|
"solana-localnet": "bin/localnet.sh"
|
||||||
},
|
},
|
||||||
"solana-channel": "beta",
|
"testnetDefaultChannel": "beta",
|
||||||
"files": [
|
"files": [
|
||||||
"/bin",
|
"/bin",
|
||||||
"/doc",
|
"/doc",
|
||||||
@ -37,7 +37,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"bpf-sdk:install": "set -ex; npm run bpf-sdk:fetch; npm run bpf-sdk:extract",
|
"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: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 {} \\;",
|
"bpf-sdk:remove-symlinks": "find bpf-sdk -type l -print -exec cp {} {}.tmp \\; -exec mv {}.tmp {} \\;",
|
||||||
"build": "cross-env NODE_ENV=production rollup -c",
|
"build": "cross-env NODE_ENV=production rollup -c",
|
||||||
"clean": "rimraf ./coverage ./lib",
|
"clean": "rimraf ./coverage ./lib",
|
||||||
@ -55,8 +55,8 @@
|
|||||||
"lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
|
"lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
|
||||||
"localnet:down": "bin/localnet.sh down",
|
"localnet:down": "bin/localnet.sh down",
|
||||||
"localnet:logs": "bin/localnet.sh logs -f",
|
"localnet:logs": "bin/localnet.sh logs -f",
|
||||||
"localnet:up": "bin/localnet.sh up $npm_package_solana_channel",
|
"localnet:up": "bin/localnet.sh up $npm_package_testnetDefaultChannel",
|
||||||
"localnet:update": "bin/localnet.sh update $npm_package_solana_channel",
|
"localnet:update": "bin/localnet.sh update $npm_package_testnetDefaultChannel",
|
||||||
"ok": "set -ex; npm run lint; npm run flow; npm run test; npm run doc",
|
"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",
|
"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'",
|
"pretty": "prettier --write '{,{examples,src,test}/**/}*.js'",
|
||||||
|
@ -13,3 +13,4 @@ export {sendAndConfirmTransaction} from './util/send-and-confirm-transaction';
|
|||||||
export {
|
export {
|
||||||
sendAndConfirmRawTransaction,
|
sendAndConfirmRawTransaction,
|
||||||
} from './util/send-and-confirm-raw-transaction';
|
} from './util/send-and-confirm-raw-transaction';
|
||||||
|
export {testnetChannelEndpoint} from './util/testnet';
|
||||||
|
@ -168,7 +168,9 @@ export class Transaction {
|
|||||||
programIds.push(programId);
|
programIds.push(programId);
|
||||||
}
|
}
|
||||||
|
|
||||||
instruction.keys.map(key => key.toString()).forEach(key => {
|
instruction.keys
|
||||||
|
.map(key => key.toString())
|
||||||
|
.forEach(key => {
|
||||||
if (!keys.includes(key)) {
|
if (!keys.includes(key)) {
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
}
|
}
|
||||||
|
27
web3.js/src/util/testnet.js
Normal file
27
web3.js/src/util/testnet.js
Normal 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}`);
|
||||||
|
}
|
18
web3.js/test/testnet.test.js
Normal file
18
web3.js/test/testnet.test.js
Normal 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
|
||||||
|
});
|
@ -6,8 +6,12 @@
|
|||||||
|
|
||||||
export const url = 'http://localhost:8899/';
|
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.edge.testnet.solana.com/';
|
||||||
//export const url = 'https://api.testnet.solana.com/';
|
export const url = 'https://api.beta.testnet.solana.com/';
|
||||||
|
export const url = 'https://api.testnet.solana.com/';
|
||||||
|
*/
|
||||||
|
Reference in New Issue
Block a user