@solana/web3.js 1.73.1 → 1.73.2

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.73.1",
3
+ "version": "1.73.2",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
7
7
  "blockchain"
8
8
  ],
9
9
  "license": "MIT",
10
- "author": "Solana Maintainers <maintainers@solana.com>",
10
+ "author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
11
11
  "homepage": "https://solana.com/",
12
12
  "repository": {
13
13
  "type": "git",
@@ -81,9 +81,9 @@
81
81
  "@babel/preset-env": "^7.12.11",
82
82
  "@babel/preset-typescript": "^7.12.16",
83
83
  "@commitlint/config-conventional": "^17.0.2",
84
- "@rollup/plugin-alias": "^3.1.9",
84
+ "@rollup/plugin-alias": "^4.0.3",
85
85
  "@rollup/plugin-babel": "^5.2.3",
86
- "@rollup/plugin-commonjs": "^22.0.0",
86
+ "@rollup/plugin-commonjs": "^24.0.1",
87
87
  "@rollup/plugin-json": "^6.0.0",
88
88
  "@rollup/plugin-multi-entry": "^4.0.0",
89
89
  "@rollup/plugin-node-resolve": "^13.0.0",
@@ -120,7 +120,7 @@
120
120
  "nyc": "^15.1.0",
121
121
  "prettier": "^2.3.0",
122
122
  "rimraf": "3.0.2",
123
- "rollup": "2.70.2",
123
+ "rollup": "2.79.1",
124
124
  "rollup-plugin-dts": "^4.0.0",
125
125
  "rollup-plugin-node-polyfills": "^0.2.1",
126
126
  "rollup-plugin-terser": "^7.0.2",
@@ -0,0 +1 @@
1
+ export {default} from 'rpc-websockets/dist/lib/client/websocket.browser';
@@ -0,0 +1 @@
1
+ export {default} from 'rpc-websockets/dist/lib/client/websocket.browser';
package/src/connection.ts CHANGED
@@ -26,7 +26,6 @@ import {
26
26
  any,
27
27
  } from 'superstruct';
28
28
  import type {Struct} from 'superstruct';
29
- import {Client as RpcWebSocketClient} from 'rpc-websockets';
30
29
  import RpcClient from 'jayson/lib/client/browser';
31
30
  import {JSONRPCError} from 'jayson';
32
31
 
@@ -36,6 +35,7 @@ import fetchImpl, {Response} from './fetch-impl';
36
35
  import {DurableNonce, NonceAccount} from './nonce-account';
37
36
  import {PublicKey} from './publickey';
38
37
  import {Signer} from './keypair';
38
+ import RpcWebSocketClient from './rpc-websocket';
39
39
  import {MS_PER_SLOT} from './timing';
40
40
  import {
41
41
  Transaction,
@@ -5803,7 +5803,12 @@ export class Connection {
5803
5803
  this._rpcWebSocketConnected = true;
5804
5804
  this._rpcWebSocketHeartbeat = setInterval(() => {
5805
5805
  // Ping server every 5s to prevent idle timeouts
5806
- this._rpcWebSocket.notify('ping').catch(() => {});
5806
+ (async () => {
5807
+ try {
5808
+ await this._rpcWebSocket.notify('ping');
5809
+ // eslint-disable-next-line no-empty
5810
+ } catch {}
5811
+ })();
5807
5812
  }, 5000);
5808
5813
  this._updateSubscriptions();
5809
5814
  }
@@ -0,0 +1,4 @@
1
+ import {ICommonWebSocketFactory} from 'rpc-websockets/dist/lib/client/client.types';
2
+ import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket';
3
+
4
+ export default WebsocketFactory as ICommonWebSocketFactory;
@@ -0,0 +1,79 @@
1
+ import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
2
+ import RpcWebSocketBrowserFactory from 'rpc-websockets/dist/lib/client/websocket.browser';
3
+ import {
4
+ ICommonWebSocket,
5
+ IWSClientAdditionalOptions,
6
+ NodeWebSocketType,
7
+ NodeWebSocketTypeOptions,
8
+ } from 'rpc-websockets/dist/lib/client/client.types';
9
+
10
+ import createRpc from './rpc-websocket-factory';
11
+
12
+ interface IHasReadyState {
13
+ readyState: WebSocket['readyState'];
14
+ }
15
+
16
+ export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
17
+ private underlyingSocket: IHasReadyState | undefined;
18
+ constructor(
19
+ address?: string,
20
+ options?: IWSClientAdditionalOptions & NodeWebSocketTypeOptions,
21
+ generate_request_id?: (
22
+ method: string,
23
+ params: object | Array<any>,
24
+ ) => number,
25
+ ) {
26
+ const webSocketFactory = (url: string) => {
27
+ const rpc = createRpc(url, {
28
+ autoconnect: true,
29
+ max_reconnects: 5,
30
+ reconnect: true,
31
+ reconnect_interval: 1000,
32
+ ...options,
33
+ });
34
+ if ('socket' in rpc) {
35
+ this.underlyingSocket = (
36
+ rpc as ReturnType<typeof RpcWebSocketBrowserFactory>
37
+ ).socket;
38
+ } else {
39
+ this.underlyingSocket = rpc as NodeWebSocketType;
40
+ }
41
+ return rpc as ICommonWebSocket;
42
+ };
43
+ super(webSocketFactory, address, options, generate_request_id);
44
+ }
45
+ call(
46
+ ...args: Parameters<RpcWebSocketCommonClient['call']>
47
+ ): ReturnType<RpcWebSocketCommonClient['call']> {
48
+ const readyState = this.underlyingSocket?.readyState;
49
+ if (readyState === 1 /* WebSocket.OPEN */) {
50
+ return super.call(...args);
51
+ }
52
+ return Promise.reject(
53
+ new Error(
54
+ 'Tried to call a JSON-RPC method `' +
55
+ args[0] +
56
+ '` but the socket was not `CONNECTING` or `OPEN` (`readyState` was ' +
57
+ readyState +
58
+ ')',
59
+ ),
60
+ );
61
+ }
62
+ notify(
63
+ ...args: Parameters<RpcWebSocketCommonClient['notify']>
64
+ ): ReturnType<RpcWebSocketCommonClient['notify']> {
65
+ const readyState = this.underlyingSocket?.readyState;
66
+ if (readyState === 1 /* WebSocket.OPEN */) {
67
+ return super.notify(...args);
68
+ }
69
+ return Promise.reject(
70
+ new Error(
71
+ 'Tried to send a JSON-RPC notification `' +
72
+ args[0] +
73
+ '` but the socket was not `CONNECTING` or `OPEN` (`readyState` was ' +
74
+ readyState +
75
+ ')',
76
+ ),
77
+ );
78
+ }
79
+ }