@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/lib/index.d.ts
CHANGED
|
@@ -1285,6 +1285,8 @@ declare module '@solana/web3.js' {
|
|
|
1285
1285
|
export type ConnectionConfig = {
|
|
1286
1286
|
/** Optional commitment level */
|
|
1287
1287
|
commitment?: Commitment;
|
|
1288
|
+
/** Optional endpoint URL to the fullnode JSON RPC PubSub WebSocket Endpoint */
|
|
1289
|
+
wsEndpoint?: string;
|
|
1288
1290
|
/** Optional HTTP headers object */
|
|
1289
1291
|
httpHeaders?: HttpHeaders;
|
|
1290
1292
|
/** Optional fetch middleware callback */
|
package/lib/index.esm.js
CHANGED
|
@@ -8,7 +8,7 @@ import { sha256 } from 'crypto-hash';
|
|
|
8
8
|
import { serialize, deserialize } from 'borsh';
|
|
9
9
|
import * as BufferLayout from 'buffer-layout';
|
|
10
10
|
import invariant from 'assert';
|
|
11
|
-
import {
|
|
11
|
+
import { format, parse } from 'url';
|
|
12
12
|
import fetch from 'node-fetch';
|
|
13
13
|
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert } from 'superstruct';
|
|
14
14
|
import { Client } from 'rpc-websockets';
|
|
@@ -2340,6 +2340,24 @@ function promiseTimeout(promise, timeoutMs) {
|
|
|
2340
2340
|
});
|
|
2341
2341
|
}
|
|
2342
2342
|
|
|
2343
|
+
function makeWebsocketUrl(endpoint) {
|
|
2344
|
+
let url = parse(endpoint);
|
|
2345
|
+
const useHttps = url.protocol === 'https:';
|
|
2346
|
+
url.protocol = useHttps ? 'wss:' : 'ws:';
|
|
2347
|
+
url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
2348
|
+
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
|
|
2349
|
+
// we're directly trying to connect to solana-validator's ws listening port.
|
|
2350
|
+
// When the endpoint omits the port, we're connecting to the protocol
|
|
2351
|
+
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
2352
|
+
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
2353
|
+
|
|
2354
|
+
if (url.port !== null) {
|
|
2355
|
+
url.port = String(Number(url.port) + 1);
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
return format(url);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2343
2361
|
const PublicKeyFromString = coerce(instance(PublicKey), string(), value => new PublicKey(value));
|
|
2344
2362
|
const RawAccountDataResult = tuple([string(), literal('base64')]);
|
|
2345
2363
|
const BufferFromRawAccountData = coerce(instance(Buffer), RawAccountDataResult, value => Buffer.from(value[0], 'base64'));
|
|
@@ -3211,6 +3229,10 @@ class Connection {
|
|
|
3211
3229
|
|
|
3212
3230
|
/** @internal */
|
|
3213
3231
|
|
|
3232
|
+
/** @internal */
|
|
3233
|
+
|
|
3234
|
+
/** @internal */
|
|
3235
|
+
|
|
3214
3236
|
/**
|
|
3215
3237
|
* Establish a JSON RPC connection
|
|
3216
3238
|
*
|
|
@@ -3228,6 +3250,13 @@ class Connection {
|
|
|
3228
3250
|
|
|
3229
3251
|
_defineProperty(this, "_pollingBlockhash", false);
|
|
3230
3252
|
|
|
3253
|
+
_defineProperty(this, "_blockhashInfo", {
|
|
3254
|
+
recentBlockhash: null,
|
|
3255
|
+
lastFetch: 0,
|
|
3256
|
+
transactionSignatures: [],
|
|
3257
|
+
simulatedSignatures: []
|
|
3258
|
+
});
|
|
3259
|
+
|
|
3231
3260
|
_defineProperty(this, "_accountChangeSubscriptionCounter", 0);
|
|
3232
3261
|
|
|
3233
3262
|
_defineProperty(this, "_accountChangeSubscriptions", {});
|
|
@@ -3256,9 +3285,9 @@ class Connection {
|
|
|
3256
3285
|
|
|
3257
3286
|
_defineProperty(this, "_slotUpdateSubscriptions", {});
|
|
3258
3287
|
|
|
3259
|
-
this._rpcEndpoint = endpoint;
|
|
3260
3288
|
let url = parse(endpoint);
|
|
3261
3289
|
const useHttps = url.protocol === 'https:';
|
|
3290
|
+
let wsEndpoint;
|
|
3262
3291
|
let httpHeaders;
|
|
3263
3292
|
let fetchMiddleware;
|
|
3264
3293
|
|
|
@@ -3266,32 +3295,17 @@ class Connection {
|
|
|
3266
3295
|
this._commitment = commitmentOrConfig;
|
|
3267
3296
|
} else if (commitmentOrConfig) {
|
|
3268
3297
|
this._commitment = commitmentOrConfig.commitment;
|
|
3298
|
+
wsEndpoint = commitmentOrConfig.wsEndpoint;
|
|
3269
3299
|
httpHeaders = commitmentOrConfig.httpHeaders;
|
|
3270
3300
|
fetchMiddleware = commitmentOrConfig.fetchMiddleware;
|
|
3271
3301
|
}
|
|
3272
3302
|
|
|
3303
|
+
this._rpcEndpoint = endpoint;
|
|
3304
|
+
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
|
3273
3305
|
this._rpcClient = createRpcClient(url.href, useHttps, httpHeaders, fetchMiddleware);
|
|
3274
3306
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
3275
3307
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
3276
|
-
this.
|
|
3277
|
-
recentBlockhash: null,
|
|
3278
|
-
lastFetch: 0,
|
|
3279
|
-
transactionSignatures: [],
|
|
3280
|
-
simulatedSignatures: []
|
|
3281
|
-
};
|
|
3282
|
-
url.protocol = useHttps ? 'wss:' : 'ws:';
|
|
3283
|
-
url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
3284
|
-
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
|
|
3285
|
-
// we're directly trying to connect to solana-validator's ws listening port.
|
|
3286
|
-
// When the endpoint omits the port, we're connecting to the protocol
|
|
3287
|
-
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
3288
|
-
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
3289
|
-
|
|
3290
|
-
if (url.port !== null) {
|
|
3291
|
-
url.port = String(Number(url.port) + 1);
|
|
3292
|
-
}
|
|
3293
|
-
|
|
3294
|
-
this._rpcWebSocket = new Client(format(url), {
|
|
3308
|
+
this._rpcWebSocket = new Client(this._rpcWsEndpoint, {
|
|
3295
3309
|
autoconnect: false,
|
|
3296
3310
|
max_reconnects: Infinity
|
|
3297
3311
|
});
|