@solana/web3.js 1.72.0 → 1.73.1-pr-29195.6

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,60 @@ 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
+ var _this$underlyingSocke;
3579
+
3580
+ const readyState = (_this$underlyingSocke = this.underlyingSocket) === null || _this$underlyingSocke === void 0 ? void 0 : _this$underlyingSocke.readyState;
3581
+
3582
+ if (readyState === 1
3583
+ /* WebSocket.OPEN */
3584
+ ) {
3585
+ return super.call(...args);
3586
+ }
3587
+
3588
+ 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 + ')'));
3589
+ }
3590
+
3591
+ notify(...args) {
3592
+ var _this$underlyingSocke2;
3593
+
3594
+ const readyState = (_this$underlyingSocke2 = this.underlyingSocket) === null || _this$underlyingSocke2 === void 0 ? void 0 : _this$underlyingSocke2.readyState;
3595
+
3596
+ if (readyState === 1
3597
+ /* WebSocket.OPEN */
3598
+ ) {
3599
+ return super.notify(...args);
3600
+ }
3601
+
3602
+ 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 + ')'));
3603
+ }
3604
+
3605
+ }
3606
+
3550
3607
  // TODO: These constants should be removed in favor of reading them out of a
3551
3608
  // Syscall account
3552
3609
 
@@ -3817,7 +3874,8 @@ const GetInflationRewardResult = jsonRpcResult(superstruct.array(superstruct.nul
3817
3874
  epoch: superstruct.number(),
3818
3875
  effectiveSlot: superstruct.number(),
3819
3876
  amount: superstruct.number(),
3820
- postBalance: superstruct.number()
3877
+ postBalance: superstruct.number(),
3878
+ commission: superstruct.optional(superstruct.nullable(superstruct.number()))
3821
3879
  }))));
3822
3880
 
3823
3881
  /**
@@ -4496,7 +4554,8 @@ const RewardsResult = superstruct.type({
4496
4554
  pubkey: superstruct.string(),
4497
4555
  lamports: superstruct.number(),
4498
4556
  postBalance: superstruct.nullable(superstruct.number()),
4499
- rewardType: superstruct.nullable(superstruct.string())
4557
+ rewardType: superstruct.nullable(superstruct.string()),
4558
+ commission: superstruct.optional(superstruct.nullable(superstruct.number()))
4500
4559
  });
4501
4560
  /**
4502
4561
  * Expected JSON RPC response for the "getBlock" message
@@ -4849,7 +4908,7 @@ class Connection {
4849
4908
  this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
4850
4909
  this._rpcRequest = createRpcRequest(this._rpcClient);
4851
4910
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
4852
- this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
4911
+ this._rpcWebSocket = new RpcWebSocketClient(this._rpcWsEndpoint, {
4853
4912
  autoconnect: false,
4854
4913
  max_reconnects: Infinity
4855
4914
  });
@@ -7303,7 +7362,11 @@ class Connection {
7303
7362
  this._rpcWebSocketConnected = true;
7304
7363
  this._rpcWebSocketHeartbeat = setInterval(() => {
7305
7364
  // Ping server every 5s to prevent idle timeouts
7306
- this._rpcWebSocket.notify('ping').catch(() => {});
7365
+ (async () => {
7366
+ try {
7367
+ await this._rpcWebSocket.notify('ping'); // eslint-disable-next-line no-empty
7368
+ } catch {}
7369
+ })();
7307
7370
  }, 5000);
7308
7371
 
7309
7372
  this._updateSubscriptions();