@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.
@@ -12,8 +12,9 @@ var borsh = require('borsh');
12
12
  var BufferLayout = require('@solana/buffer-layout');
13
13
  var bigintBuffer = require('bigint-buffer');
14
14
  var superstruct = require('superstruct');
15
- var rpcWebsockets = require('rpc-websockets');
16
15
  var RpcClient = require('jayson/lib/client/browser');
16
+ var RpcWebSocketCommonClient = require('rpc-websockets/dist/lib/client');
17
+ var createRpc = require('rpc-websockets/dist/lib/client/websocket.browser');
17
18
  var sha3 = require('@noble/hashes/sha3');
18
19
  var hmac = require('@noble/hashes/hmac');
19
20
  var secp256k1 = require('@noble/secp256k1');
@@ -43,6 +44,8 @@ var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
43
44
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
44
45
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
45
46
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
47
+ var RpcWebSocketCommonClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcWebSocketCommonClient);
48
+ var createRpc__default = /*#__PURE__*/_interopDefaultLegacy(createRpc);
46
49
  var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
47
50
 
48
51
  /**
@@ -3547,6 +3550,56 @@ class SolanaJSONRPCError extends Error {
3547
3550
 
3548
3551
  var fetchImpl = globalThis.fetch;
3549
3552
 
3553
+ class RpcWebSocketClient extends RpcWebSocketCommonClient__default["default"] {
3554
+ constructor(address, options, generate_request_id) {
3555
+ const webSocketFactory = url => {
3556
+ const rpc = createRpc__default["default"](url, {
3557
+ autoconnect: true,
3558
+ max_reconnects: 5,
3559
+ reconnect: true,
3560
+ reconnect_interval: 1000,
3561
+ ...options
3562
+ });
3563
+
3564
+ if ('socket' in rpc) {
3565
+ this.underlyingSocket = rpc.socket;
3566
+ } else {
3567
+ this.underlyingSocket = rpc;
3568
+ }
3569
+
3570
+ return rpc;
3571
+ };
3572
+
3573
+ super(webSocketFactory, address, options, generate_request_id);
3574
+ this.underlyingSocket = void 0;
3575
+ }
3576
+
3577
+ call(...args) {
3578
+ const readyState = this.underlyingSocket?.readyState;
3579
+
3580
+ if (readyState === 1
3581
+ /* WebSocket.OPEN */
3582
+ ) {
3583
+ return super.call(...args);
3584
+ }
3585
+
3586
+ return Promise.reject(new Error('Tried to call a JSON-RPC method `' + args[0] + '` but the socket was not `CONNECTING` or `OPEN` (`readyState` was ' + readyState + ')'));
3587
+ }
3588
+
3589
+ notify(...args) {
3590
+ const readyState = this.underlyingSocket?.readyState;
3591
+
3592
+ if (readyState === 1
3593
+ /* WebSocket.OPEN */
3594
+ ) {
3595
+ return super.notify(...args);
3596
+ }
3597
+
3598
+ return Promise.reject(new Error('Tried to send a JSON-RPC notification `' + args[0] + '` but the socket was not `CONNECTING` or `OPEN` (`readyState` was ' + readyState + ')'));
3599
+ }
3600
+
3601
+ }
3602
+
3550
3603
  // TODO: These constants should be removed in favor of reading them out of a
3551
3604
  // Syscall account
3552
3605
 
@@ -4850,7 +4903,7 @@ class Connection {
4850
4903
  this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
4851
4904
  this._rpcRequest = createRpcRequest(this._rpcClient);
4852
4905
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
4853
- this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
4906
+ this._rpcWebSocket = new RpcWebSocketClient(this._rpcWsEndpoint, {
4854
4907
  autoconnect: false,
4855
4908
  max_reconnects: Infinity
4856
4909
  });
@@ -7298,7 +7351,11 @@ class Connection {
7298
7351
  this._rpcWebSocketConnected = true;
7299
7352
  this._rpcWebSocketHeartbeat = setInterval(() => {
7300
7353
  // Ping server every 5s to prevent idle timeouts
7301
- this._rpcWebSocket.notify('ping').catch(() => {});
7354
+ (async () => {
7355
+ try {
7356
+ await this._rpcWebSocket.notify('ping'); // eslint-disable-next-line no-empty
7357
+ } catch {}
7358
+ })();
7302
7359
  }, 5000);
7303
7360
 
7304
7361
  this._updateSubscriptions();
@@ -7646,9 +7703,7 @@ class Connection {
7646
7703
  */
7647
7704
  args) {
7648
7705
  const clientSubscriptionId = this._nextClientSubscriptionId++;
7649
- const hash = fastStableStringify$1([subscriptionConfig.method, args], true
7650
- /* isArrayProp */
7651
- );
7706
+ const hash = fastStableStringify$1([subscriptionConfig.method, args]);
7652
7707
  const existingSubscription = this._subscriptionsByHash[hash];
7653
7708
 
7654
7709
  if (existingSubscription === undefined) {