@solana/web3.js 1.5.1 → 1.6.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 +38 -8
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +38 -8
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +30 -2
- package/lib/index.esm.js +38 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +38 -8
- 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 +46 -5
- package/package.json +1 -1
- package/src/connection.ts +83 -9
package/lib/index.browser.esm.js
CHANGED
|
@@ -4392,7 +4392,23 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
|
|
|
4392
4392
|
logs: nullable(array(string()))
|
|
4393
4393
|
}));
|
|
4394
4394
|
|
|
4395
|
-
function createRpcClient(url, useHttps) {
|
|
4395
|
+
function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware) {
|
|
4396
|
+
|
|
4397
|
+
let fetchWithMiddleware;
|
|
4398
|
+
|
|
4399
|
+
if (fetchMiddleware) {
|
|
4400
|
+
fetchWithMiddleware = (url, options) => {
|
|
4401
|
+
return new Promise((resolve, reject) => {
|
|
4402
|
+
fetchMiddleware(url, options, async (url, options) => {
|
|
4403
|
+
try {
|
|
4404
|
+
resolve(await fetch(url, options));
|
|
4405
|
+
} catch (error) {
|
|
4406
|
+
reject(error);
|
|
4407
|
+
}
|
|
4408
|
+
});
|
|
4409
|
+
});
|
|
4410
|
+
};
|
|
4411
|
+
}
|
|
4396
4412
|
|
|
4397
4413
|
const clientBrowser = new RpcClient(async (request, callback) => {
|
|
4398
4414
|
const agent = undefined;
|
|
@@ -4400,9 +4416,9 @@ function createRpcClient(url, useHttps) {
|
|
|
4400
4416
|
method: 'POST',
|
|
4401
4417
|
body: request,
|
|
4402
4418
|
agent,
|
|
4403
|
-
headers: {
|
|
4419
|
+
headers: Object.assign({
|
|
4404
4420
|
'Content-Type': 'application/json'
|
|
4405
|
-
}
|
|
4421
|
+
}, httpHeaders || {})
|
|
4406
4422
|
};
|
|
4407
4423
|
|
|
4408
4424
|
try {
|
|
@@ -4411,7 +4427,11 @@ function createRpcClient(url, useHttps) {
|
|
|
4411
4427
|
let waitTime = 500;
|
|
4412
4428
|
|
|
4413
4429
|
for (;;) {
|
|
4414
|
-
|
|
4430
|
+
if (fetchWithMiddleware) {
|
|
4431
|
+
res = await fetchWithMiddleware(url, options);
|
|
4432
|
+
} else {
|
|
4433
|
+
res = await fetch(url, options);
|
|
4434
|
+
}
|
|
4415
4435
|
|
|
4416
4436
|
if (res.status !== 429
|
|
4417
4437
|
/* Too many requests */
|
|
@@ -5038,9 +5058,9 @@ class Connection {
|
|
|
5038
5058
|
* Establish a JSON RPC connection
|
|
5039
5059
|
*
|
|
5040
5060
|
* @param endpoint URL to the fullnode JSON RPC endpoint
|
|
5041
|
-
* @param
|
|
5061
|
+
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
5042
5062
|
*/
|
|
5043
|
-
constructor(endpoint,
|
|
5063
|
+
constructor(endpoint, commitmentOrConfig) {
|
|
5044
5064
|
_defineProperty(this, "_commitment", void 0);
|
|
5045
5065
|
|
|
5046
5066
|
_defineProperty(this, "_rpcEndpoint", void 0);
|
|
@@ -5092,10 +5112,20 @@ class Connection {
|
|
|
5092
5112
|
this._rpcEndpoint = endpoint;
|
|
5093
5113
|
let url = urlParse(endpoint);
|
|
5094
5114
|
const useHttps = url.protocol === 'https:';
|
|
5095
|
-
|
|
5115
|
+
let httpHeaders;
|
|
5116
|
+
let fetchMiddleware;
|
|
5117
|
+
|
|
5118
|
+
if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
|
|
5119
|
+
this._commitment = commitmentOrConfig;
|
|
5120
|
+
} else if (commitmentOrConfig) {
|
|
5121
|
+
this._commitment = commitmentOrConfig.commitment;
|
|
5122
|
+
httpHeaders = commitmentOrConfig.httpHeaders;
|
|
5123
|
+
fetchMiddleware = commitmentOrConfig.fetchMiddleware;
|
|
5124
|
+
}
|
|
5125
|
+
|
|
5126
|
+
this._rpcClient = createRpcClient(url.href, useHttps, httpHeaders, fetchMiddleware);
|
|
5096
5127
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
5097
5128
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
5098
|
-
this._commitment = commitment;
|
|
5099
5129
|
this._blockhashInfo = {
|
|
5100
5130
|
recentBlockhash: null,
|
|
5101
5131
|
lastFetch: 0,
|