@solana/web3.js 1.14.1 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.esm.js +34 -20
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +34 -20
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.esm.js +35 -21
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +34 -20
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +1 -1
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +5 -0
- package/package.json +3 -3
- package/src/connection.ts +16 -23
- package/src/util/url.ts +20 -0
package/module.flow.js
CHANGED
|
@@ -1964,6 +1964,11 @@ declare module "@solana/web3.js" {
|
|
|
1964
1964
|
*/
|
|
1965
1965
|
commitment?: Commitment,
|
|
1966
1966
|
|
|
1967
|
+
/**
|
|
1968
|
+
* Optional endpoint URL to the fullnode JSON RPC PubSub WebSocket Endpoint
|
|
1969
|
+
*/
|
|
1970
|
+
wsEndpoint?: string,
|
|
1971
|
+
|
|
1967
1972
|
/**
|
|
1968
1973
|
* Optional HTTP headers object
|
|
1969
1974
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"eslint": "^7.19.0",
|
|
89
89
|
"eslint-config-prettier": "^8.0.0",
|
|
90
90
|
"eslint-plugin-import": "2.23.3",
|
|
91
|
-
"eslint-plugin-mocha": "^
|
|
91
|
+
"eslint-plugin-mocha": "^9.0.0",
|
|
92
92
|
"eslint-plugin-prettier": "^3.0.0",
|
|
93
93
|
"esm": "^3.2.25",
|
|
94
94
|
"flow-bin": "^0.150.0",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"nyc": "^15.1.0",
|
|
103
103
|
"prettier": "^2.3.0",
|
|
104
104
|
"rimraf": "3.0.2",
|
|
105
|
-
"rollup": "2.
|
|
105
|
+
"rollup": "2.50.1",
|
|
106
106
|
"rollup-plugin-dts": "^3.0.1",
|
|
107
107
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
108
108
|
"rollup-plugin-terser": "^7.0.2",
|
package/src/connection.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import bs58 from 'bs58';
|
|
3
3
|
import {Buffer} from 'buffer';
|
|
4
|
-
import {parse as urlParse
|
|
4
|
+
import {parse as urlParse} from 'url';
|
|
5
5
|
import fetch, {Response} from 'node-fetch';
|
|
6
6
|
import {
|
|
7
7
|
type as pick,
|
|
@@ -36,6 +36,7 @@ import {Message} from './message';
|
|
|
36
36
|
import {sleep} from './util/sleep';
|
|
37
37
|
import {promiseTimeout} from './util/promise-timeout';
|
|
38
38
|
import {toBuffer} from './util/to-buffer';
|
|
39
|
+
import {makeWebsocketUrl} from './util/url';
|
|
39
40
|
import type {Blockhash} from './blockhash';
|
|
40
41
|
import type {FeeCalculator} from './fee-calculator';
|
|
41
42
|
import type {TransactionSignature} from './transaction';
|
|
@@ -1917,6 +1918,8 @@ export type FetchMiddleware = (
|
|
|
1917
1918
|
export type ConnectionConfig = {
|
|
1918
1919
|
/** Optional commitment level */
|
|
1919
1920
|
commitment?: Commitment;
|
|
1921
|
+
/** Optional endpoint URL to the fullnode JSON RPC PubSub WebSocket Endpoint */
|
|
1922
|
+
wsEndpoint?: string;
|
|
1920
1923
|
/** Optional HTTP headers object */
|
|
1921
1924
|
httpHeaders?: HttpHeaders;
|
|
1922
1925
|
/** Optional fetch middleware callback */
|
|
@@ -1929,6 +1932,7 @@ export type ConnectionConfig = {
|
|
|
1929
1932
|
export class Connection {
|
|
1930
1933
|
/** @internal */ _commitment?: Commitment;
|
|
1931
1934
|
/** @internal */ _rpcEndpoint: string;
|
|
1935
|
+
/** @internal */ _rpcWsEndpoint: string;
|
|
1932
1936
|
/** @internal */ _rpcClient: RpcClient;
|
|
1933
1937
|
/** @internal */ _rpcRequest: RpcRequest;
|
|
1934
1938
|
/** @internal */ _rpcBatchRequest: RpcBatchRequest;
|
|
@@ -1948,6 +1952,11 @@ export class Connection {
|
|
|
1948
1952
|
lastFetch: number;
|
|
1949
1953
|
simulatedSignatures: Array<string>;
|
|
1950
1954
|
transactionSignatures: Array<string>;
|
|
1955
|
+
} = {
|
|
1956
|
+
recentBlockhash: null,
|
|
1957
|
+
lastFetch: 0,
|
|
1958
|
+
transactionSignatures: [],
|
|
1959
|
+
simulatedSignatures: [],
|
|
1951
1960
|
};
|
|
1952
1961
|
|
|
1953
1962
|
/** @internal */ _accountChangeSubscriptionCounter: number = 0;
|
|
@@ -1995,21 +2004,24 @@ export class Connection {
|
|
|
1995
2004
|
endpoint: string,
|
|
1996
2005
|
commitmentOrConfig?: Commitment | ConnectionConfig,
|
|
1997
2006
|
) {
|
|
1998
|
-
this._rpcEndpoint = endpoint;
|
|
1999
|
-
|
|
2000
2007
|
let url = urlParse(endpoint);
|
|
2001
2008
|
const useHttps = url.protocol === 'https:';
|
|
2002
2009
|
|
|
2010
|
+
let wsEndpoint;
|
|
2003
2011
|
let httpHeaders;
|
|
2004
2012
|
let fetchMiddleware;
|
|
2005
2013
|
if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
|
|
2006
2014
|
this._commitment = commitmentOrConfig;
|
|
2007
2015
|
} else if (commitmentOrConfig) {
|
|
2008
2016
|
this._commitment = commitmentOrConfig.commitment;
|
|
2017
|
+
wsEndpoint = commitmentOrConfig.wsEndpoint;
|
|
2009
2018
|
httpHeaders = commitmentOrConfig.httpHeaders;
|
|
2010
2019
|
fetchMiddleware = commitmentOrConfig.fetchMiddleware;
|
|
2011
2020
|
}
|
|
2012
2021
|
|
|
2022
|
+
this._rpcEndpoint = endpoint;
|
|
2023
|
+
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
|
2024
|
+
|
|
2013
2025
|
this._rpcClient = createRpcClient(
|
|
2014
2026
|
url.href,
|
|
2015
2027
|
useHttps,
|
|
@@ -2019,26 +2031,7 @@ export class Connection {
|
|
|
2019
2031
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
2020
2032
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
2021
2033
|
|
|
2022
|
-
this.
|
|
2023
|
-
recentBlockhash: null,
|
|
2024
|
-
lastFetch: 0,
|
|
2025
|
-
transactionSignatures: [],
|
|
2026
|
-
simulatedSignatures: [],
|
|
2027
|
-
};
|
|
2028
|
-
|
|
2029
|
-
url.protocol = useHttps ? 'wss:' : 'ws:';
|
|
2030
|
-
url.host = '';
|
|
2031
|
-
// Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
2032
|
-
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
|
|
2033
|
-
// we're directly trying to connect to solana-validator's ws listening port.
|
|
2034
|
-
// When the endpoint omits the port, we're connecting to the protocol
|
|
2035
|
-
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
2036
|
-
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
2037
|
-
if (url.port !== null) {
|
|
2038
|
-
url.port = String(Number(url.port) + 1);
|
|
2039
|
-
}
|
|
2040
|
-
|
|
2041
|
-
this._rpcWebSocket = new RpcWebSocketClient(urlFormat(url), {
|
|
2034
|
+
this._rpcWebSocket = new RpcWebSocketClient(this._rpcWsEndpoint, {
|
|
2042
2035
|
autoconnect: false,
|
|
2043
2036
|
max_reconnects: Infinity,
|
|
2044
2037
|
});
|
package/src/util/url.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {format as urlFormat, parse as urlParse} from 'url';
|
|
2
|
+
|
|
3
|
+
export function makeWebsocketUrl(endpoint: string) {
|
|
4
|
+
let url = urlParse(endpoint);
|
|
5
|
+
const useHttps = url.protocol === 'https:';
|
|
6
|
+
|
|
7
|
+
url.protocol = useHttps ? 'wss:' : 'ws:';
|
|
8
|
+
url.host = '';
|
|
9
|
+
|
|
10
|
+
// Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
11
|
+
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
|
|
12
|
+
// we're directly trying to connect to solana-validator's ws listening port.
|
|
13
|
+
// When the endpoint omits the port, we're connecting to the protocol
|
|
14
|
+
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
15
|
+
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
16
|
+
if (url.port !== null) {
|
|
17
|
+
url.port = String(Number(url.port) + 1);
|
|
18
|
+
}
|
|
19
|
+
return urlFormat(url);
|
|
20
|
+
}
|