@solana/web3.js 1.37.2 → 1.39.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.cjs.js CHANGED
@@ -8,7 +8,7 @@ var BN = require('bn.js');
8
8
  var bs58 = require('bs58');
9
9
  var borsh = require('borsh');
10
10
  var BufferLayout = require('@solana/buffer-layout');
11
- var fetch = require('cross-fetch');
11
+ var crossFetch = require('cross-fetch');
12
12
  var superstruct = require('superstruct');
13
13
  var rpcWebsockets = require('rpc-websockets');
14
14
  var RpcClient = require('jayson/lib/client/browser');
@@ -41,7 +41,7 @@ var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
41
41
  var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
42
42
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
43
43
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
44
- var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
44
+ var crossFetch__default = /*#__PURE__*/_interopDefaultLegacy(crossFetch);
45
45
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
46
46
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
47
47
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
@@ -2403,6 +2403,26 @@ class TransactionInstruction {
2403
2403
  this.data = opts.data;
2404
2404
  }
2405
2405
  }
2406
+ /**
2407
+ * @internal
2408
+ */
2409
+
2410
+
2411
+ toJSON() {
2412
+ return {
2413
+ keys: this.keys.map(({
2414
+ pubkey,
2415
+ isSigner,
2416
+ isWritable
2417
+ }) => ({
2418
+ pubkey: pubkey.toJSON(),
2419
+ isSigner,
2420
+ isWritable
2421
+ })),
2422
+ programId: this.programId.toJSON(),
2423
+ data: [...this.data]
2424
+ };
2425
+ }
2406
2426
 
2407
2427
  }
2408
2428
  /**
@@ -2442,8 +2462,33 @@ class Transaction {
2442
2462
  this.instructions = [];
2443
2463
  this.recentBlockhash = void 0;
2444
2464
  this.nonceInfo = void 0;
2465
+ this._message = void 0;
2466
+ this._json = void 0;
2445
2467
  opts && Object.assign(this, opts);
2446
2468
  }
2469
+ /**
2470
+ * @internal
2471
+ */
2472
+
2473
+
2474
+ toJSON() {
2475
+ return {
2476
+ recentBlockhash: this.recentBlockhash || null,
2477
+ feePayer: this.feePayer ? this.feePayer.toJSON() : null,
2478
+ nonceInfo: this.nonceInfo ? {
2479
+ nonce: this.nonceInfo.nonce,
2480
+ nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2481
+ } : null,
2482
+ instructions: this.instructions.map(instruction => instruction.toJSON()),
2483
+ signatures: this.signatures.map(({
2484
+ publicKey,
2485
+ signature
2486
+ }) => ({
2487
+ publicKey: publicKey.toJSON(),
2488
+ signature: signature ? [...signature] : null
2489
+ }))
2490
+ };
2491
+ }
2447
2492
  /**
2448
2493
  * Add one or more instructions to this Transaction
2449
2494
  */
@@ -2471,6 +2516,14 @@ class Transaction {
2471
2516
 
2472
2517
 
2473
2518
  compileMessage() {
2519
+ if (this._message) {
2520
+ if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2521
+ throw new Error('Transaction mutated after being populated from Message');
2522
+ }
2523
+
2524
+ return this._message;
2525
+ }
2526
+
2474
2527
  const {
2475
2528
  nonceInfo
2476
2529
  } = this;
@@ -2992,6 +3045,8 @@ class Transaction {
2992
3045
  data: bs58__default["default"].decode(instruction.data)
2993
3046
  }));
2994
3047
  });
3048
+ transaction._message = message;
3049
+ transaction._json = transaction.toJSON();
2995
3050
  return transaction;
2996
3051
  }
2997
3052
 
@@ -4426,7 +4481,8 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4426
4481
  * A performance sample
4427
4482
  */
4428
4483
 
4429
- function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
4484
+ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4485
+ const fetch = customFetch ? customFetch : crossFetch__default["default"];
4430
4486
  let agentManager;
4431
4487
 
4432
4488
  {
@@ -4444,7 +4500,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4444
4500
  reject(error);
4445
4501
  }
4446
4502
  });
4447
- return await fetch__default["default"](...modifiedFetchArgs);
4503
+ return await fetch(...modifiedFetchArgs);
4448
4504
  };
4449
4505
  }
4450
4506
 
@@ -4468,7 +4524,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4468
4524
  if (fetchWithMiddleware) {
4469
4525
  res = await fetchWithMiddleware(url, options);
4470
4526
  } else {
4471
- res = await fetch__default["default"](url, options);
4527
+ res = await fetch(url, options);
4472
4528
  }
4473
4529
 
4474
4530
  if (res.status !== 429
@@ -5234,6 +5290,7 @@ class Connection {
5234
5290
  const useHttps = url.protocol === 'https:';
5235
5291
  let wsEndpoint;
5236
5292
  let httpHeaders;
5293
+ let fetch;
5237
5294
  let fetchMiddleware;
5238
5295
  let disableRetryOnRateLimit;
5239
5296
 
@@ -5244,13 +5301,14 @@ class Connection {
5244
5301
  this._confirmTransactionInitialTimeout = commitmentOrConfig.confirmTransactionInitialTimeout;
5245
5302
  wsEndpoint = commitmentOrConfig.wsEndpoint;
5246
5303
  httpHeaders = commitmentOrConfig.httpHeaders;
5304
+ fetch = commitmentOrConfig.fetch;
5247
5305
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
5248
5306
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
5249
5307
  }
5250
5308
 
5251
5309
  this._rpcEndpoint = endpoint;
5252
5310
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5253
- this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit);
5311
+ this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5254
5312
  this._rpcRequest = createRpcRequest(this._rpcClient);
5255
5313
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5256
5314
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -6765,7 +6823,9 @@ class Connection {
6765
6823
  });
6766
6824
  transaction.instructions = transactionOrMessage.instructions;
6767
6825
  } else {
6768
- transaction = Transaction.populate(transactionOrMessage);
6826
+ transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
6827
+
6828
+ transaction._message = transaction._json = undefined;
6769
6829
  }
6770
6830
 
6771
6831
  if (transaction.nonceInfo && signers) {