@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/lib/index.browser.cjs.js +61 -6
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +60 -7
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +97 -22
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +96 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +2594 -2291
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +5 -5
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +61 -6
- package/lib/index.native.js.map +1 -1
- package/package.json +5 -5
- package/src/__forks__/browser/rpc-websocket-factory.ts +1 -0
- package/src/__forks__/react-native/rpc-websocket-factory.ts +1 -0
- package/src/connection.ts +7 -2
- package/src/rpc-websocket-factory.ts +4 -0
- package/src/rpc-websocket.ts +79 -0
package/lib/index.browser.esm.js
CHANGED
|
@@ -8,9 +8,10 @@ import { serialize, deserialize, deserializeUnchecked } from 'borsh';
|
|
|
8
8
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
9
9
|
import { blob } from '@solana/buffer-layout';
|
|
10
10
|
import { toBigIntLE, toBufferLE } from 'bigint-buffer';
|
|
11
|
-
import { coerce, instance, string, tuple, literal, unknown,
|
|
12
|
-
import { Client } from 'rpc-websockets';
|
|
11
|
+
import { coerce, instance, string, tuple, literal, unknown, type, number, array, nullable, optional, boolean, record, union, create, any, assert as assert$1 } from 'superstruct';
|
|
13
12
|
import RpcClient from 'jayson/lib/client/browser';
|
|
13
|
+
import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
|
|
14
|
+
import createRpc from 'rpc-websockets/dist/lib/client/websocket.browser';
|
|
14
15
|
import { keccak_256 } from '@noble/hashes/sha3';
|
|
15
16
|
import { hmac } from '@noble/hashes/hmac';
|
|
16
17
|
import * as secp256k1 from '@noble/secp256k1';
|
|
@@ -3517,6 +3518,56 @@ class SolanaJSONRPCError extends Error {
|
|
|
3517
3518
|
|
|
3518
3519
|
var fetchImpl = globalThis.fetch;
|
|
3519
3520
|
|
|
3521
|
+
class RpcWebSocketClient extends RpcWebSocketCommonClient {
|
|
3522
|
+
constructor(address, options, generate_request_id) {
|
|
3523
|
+
const webSocketFactory = url => {
|
|
3524
|
+
const rpc = createRpc(url, {
|
|
3525
|
+
autoconnect: true,
|
|
3526
|
+
max_reconnects: 5,
|
|
3527
|
+
reconnect: true,
|
|
3528
|
+
reconnect_interval: 1000,
|
|
3529
|
+
...options
|
|
3530
|
+
});
|
|
3531
|
+
|
|
3532
|
+
if ('socket' in rpc) {
|
|
3533
|
+
this.underlyingSocket = rpc.socket;
|
|
3534
|
+
} else {
|
|
3535
|
+
this.underlyingSocket = rpc;
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
return rpc;
|
|
3539
|
+
};
|
|
3540
|
+
|
|
3541
|
+
super(webSocketFactory, address, options, generate_request_id);
|
|
3542
|
+
this.underlyingSocket = void 0;
|
|
3543
|
+
}
|
|
3544
|
+
|
|
3545
|
+
call(...args) {
|
|
3546
|
+
const readyState = this.underlyingSocket?.readyState;
|
|
3547
|
+
|
|
3548
|
+
if (readyState === 1
|
|
3549
|
+
/* WebSocket.OPEN */
|
|
3550
|
+
) {
|
|
3551
|
+
return super.call(...args);
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
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 + ')'));
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
notify(...args) {
|
|
3558
|
+
const readyState = this.underlyingSocket?.readyState;
|
|
3559
|
+
|
|
3560
|
+
if (readyState === 1
|
|
3561
|
+
/* WebSocket.OPEN */
|
|
3562
|
+
) {
|
|
3563
|
+
return super.notify(...args);
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
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 + ')'));
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3520
3571
|
// TODO: These constants should be removed in favor of reading them out of a
|
|
3521
3572
|
// Syscall account
|
|
3522
3573
|
|
|
@@ -4820,7 +4871,7 @@ class Connection {
|
|
|
4820
4871
|
this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
|
|
4821
4872
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
4822
4873
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
4823
|
-
this._rpcWebSocket = new
|
|
4874
|
+
this._rpcWebSocket = new RpcWebSocketClient(this._rpcWsEndpoint, {
|
|
4824
4875
|
autoconnect: false,
|
|
4825
4876
|
max_reconnects: Infinity
|
|
4826
4877
|
});
|
|
@@ -7268,7 +7319,11 @@ class Connection {
|
|
|
7268
7319
|
this._rpcWebSocketConnected = true;
|
|
7269
7320
|
this._rpcWebSocketHeartbeat = setInterval(() => {
|
|
7270
7321
|
// Ping server every 5s to prevent idle timeouts
|
|
7271
|
-
|
|
7322
|
+
(async () => {
|
|
7323
|
+
try {
|
|
7324
|
+
await this._rpcWebSocket.notify('ping'); // eslint-disable-next-line no-empty
|
|
7325
|
+
} catch {}
|
|
7326
|
+
})();
|
|
7272
7327
|
}, 5000);
|
|
7273
7328
|
|
|
7274
7329
|
this._updateSubscriptions();
|
|
@@ -7616,9 +7671,7 @@ class Connection {
|
|
|
7616
7671
|
*/
|
|
7617
7672
|
args) {
|
|
7618
7673
|
const clientSubscriptionId = this._nextClientSubscriptionId++;
|
|
7619
|
-
const hash = fastStableStringify$1([subscriptionConfig.method, args]
|
|
7620
|
-
/* isArrayProp */
|
|
7621
|
-
);
|
|
7674
|
+
const hash = fastStableStringify$1([subscriptionConfig.method, args]);
|
|
7622
7675
|
const existingSubscription = this._subscriptionsByHash[hash];
|
|
7623
7676
|
|
|
7624
7677
|
if (existingSubscription === undefined) {
|