@solana/web3.js 1.35.1 → 1.37.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
@@ -81,32 +81,38 @@ var inherits_browser = {exports: {}};
81
81
  if (typeof Object.create === 'function') {
82
82
  // implementation from standard node.js 'util' module
83
83
  inherits_browser.exports = function inherits(ctor, superCtor) {
84
- ctor.super_ = superCtor;
85
- ctor.prototype = Object.create(superCtor.prototype, {
86
- constructor: {
87
- value: ctor,
88
- enumerable: false,
89
- writable: true,
90
- configurable: true
91
- }
92
- });
84
+ if (superCtor) {
85
+ ctor.super_ = superCtor;
86
+ ctor.prototype = Object.create(superCtor.prototype, {
87
+ constructor: {
88
+ value: ctor,
89
+ enumerable: false,
90
+ writable: true,
91
+ configurable: true
92
+ }
93
+ });
94
+ }
93
95
  };
94
96
  } else {
95
97
  // old school shim for old browsers
96
98
  inherits_browser.exports = function inherits(ctor, superCtor) {
97
- ctor.super_ = superCtor;
98
- var TempCtor = function () {};
99
- TempCtor.prototype = superCtor.prototype;
100
- ctor.prototype = new TempCtor();
101
- ctor.prototype.constructor = ctor;
99
+ if (superCtor) {
100
+ ctor.super_ = superCtor;
101
+ var TempCtor = function () {};
102
+ TempCtor.prototype = superCtor.prototype;
103
+ ctor.prototype = new TempCtor();
104
+ ctor.prototype.constructor = ctor;
105
+ }
102
106
  };
103
107
  }
104
108
 
105
109
  try {
106
110
  var util = require('util');
111
+ /* istanbul ignore next */
107
112
  if (typeof util.inherits !== 'function') throw '';
108
113
  inherits$1.exports = util.inherits;
109
114
  } catch (e) {
115
+ /* istanbul ignore next */
110
116
  inherits$1.exports = inherits_browser.exports;
111
117
  }
112
118
 
@@ -1319,7 +1325,7 @@ hash.ripemd160 = hash.ripemd.ripemd160;
1319
1325
 
1320
1326
  var hash = hash$1;
1321
1327
 
1322
- const version$2 = "logger/5.5.0";
1328
+ const version$2 = "logger/5.6.0";
1323
1329
 
1324
1330
  let _permanentCensorErrors = false;
1325
1331
  let _censorErrors = false;
@@ -1498,6 +1504,40 @@ class Logger {
1498
1504
  messageDetails.push(`code=${code}`);
1499
1505
  messageDetails.push(`version=${this.version}`);
1500
1506
  const reason = message;
1507
+ let url = "";
1508
+ switch (code) {
1509
+ case ErrorCode.NUMERIC_FAULT: {
1510
+ url = "NUMERIC_FAULT";
1511
+ const fault = message;
1512
+ switch (fault) {
1513
+ case "overflow":
1514
+ case "underflow":
1515
+ case "division-by-zero":
1516
+ url += "-" + fault;
1517
+ break;
1518
+ case "negative-power":
1519
+ case "negative-width":
1520
+ url += "-unsupported";
1521
+ break;
1522
+ case "unbound-bitwise-result":
1523
+ url += "-unbound-result";
1524
+ break;
1525
+ }
1526
+ break;
1527
+ }
1528
+ case ErrorCode.CALL_EXCEPTION:
1529
+ case ErrorCode.INSUFFICIENT_FUNDS:
1530
+ case ErrorCode.MISSING_NEW:
1531
+ case ErrorCode.NONCE_EXPIRED:
1532
+ case ErrorCode.REPLACEMENT_UNDERPRICED:
1533
+ case ErrorCode.TRANSACTION_REPLACED:
1534
+ case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
1535
+ url = code;
1536
+ break;
1537
+ }
1538
+ if (url) {
1539
+ message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
1540
+ }
1501
1541
  if (messageDetails.length) {
1502
1542
  message += " (" + messageDetails.join(", ") + ")";
1503
1543
  }
@@ -1631,7 +1671,7 @@ class Logger {
1631
1671
  Logger.errors = ErrorCode;
1632
1672
  Logger.levels = LogLevel;
1633
1673
 
1634
- const version$1 = "bytes/5.5.0";
1674
+ const version$1 = "bytes/5.6.0";
1635
1675
 
1636
1676
  const logger = new Logger(version$1);
1637
1677
  ///////////////////////////////
@@ -1728,7 +1768,7 @@ function isHexString(value, length) {
1728
1768
  return true;
1729
1769
  }
1730
1770
 
1731
- const version = "sha2/5.5.0";
1771
+ const version = "sha2/5.6.0";
1732
1772
 
1733
1773
  new Logger(version);
1734
1774
  function sha256(data) {
@@ -2066,10 +2106,10 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2066
2106
  const publicKey = (property = 'publicKey') => {
2067
2107
  return BufferLayout__namespace.blob(32, property);
2068
2108
  };
2109
+
2069
2110
  /**
2070
2111
  * Layout for a Rust String type
2071
2112
  */
2072
-
2073
2113
  const rustString = (property = 'string') => {
2074
2114
  const rsl = BufferLayout__namespace.struct([BufferLayout__namespace.u32('length'), BufferLayout__namespace.u32('lengthPadding'), BufferLayout__namespace.blob(BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'chars')], property);
2075
2115
 
@@ -2077,24 +2117,26 @@ const rustString = (property = 'string') => {
2077
2117
 
2078
2118
  const _encode = rsl.encode.bind(rsl);
2079
2119
 
2080
- rsl.decode = (buffer, offset) => {
2081
- const data = _decode(buffer, offset);
2120
+ const rslShim = rsl;
2082
2121
 
2083
- return data['chars'].toString('utf8');
2122
+ rslShim.decode = (b, offset) => {
2123
+ const data = _decode(b, offset);
2124
+
2125
+ return data['chars'].toString();
2084
2126
  };
2085
2127
 
2086
- rsl.encode = (str, buffer$1, offset) => {
2128
+ rslShim.encode = (str, b, offset) => {
2087
2129
  const data = {
2088
2130
  chars: buffer.Buffer.from(str, 'utf8')
2089
2131
  };
2090
- return _encode(data, buffer$1, offset);
2132
+ return _encode(data, b, offset);
2091
2133
  };
2092
2134
 
2093
- rsl.alloc = str => {
2135
+ rslShim.alloc = str => {
2094
2136
  return BufferLayout__namespace.u32().span + BufferLayout__namespace.u32().span + buffer.Buffer.from(str, 'utf8').length;
2095
2137
  };
2096
2138
 
2097
- return rsl;
2139
+ return rslShim;
2098
2140
  };
2099
2141
  /**
2100
2142
  * Layout for an Authorized object
@@ -2214,7 +2256,7 @@ class Message {
2214
2256
  accounts,
2215
2257
  programIdIndex
2216
2258
  } = instruction;
2217
- const data = bs58__default["default"].decode(instruction.data);
2259
+ const data = Array.from(bs58__default["default"].decode(instruction.data));
2218
2260
  let keyIndicesCount = [];
2219
2261
  encodeLength(keyIndicesCount, accounts.length);
2220
2262
  let dataCount = [];
@@ -2222,7 +2264,7 @@ class Message {
2222
2264
  return {
2223
2265
  programIdIndex,
2224
2266
  keyIndicesCount: buffer.Buffer.from(keyIndicesCount),
2225
- keyIndices: buffer.Buffer.from(accounts),
2267
+ keyIndices: accounts,
2226
2268
  dataLength: buffer.Buffer.from(dataCount),
2227
2269
  data
2228
2270
  };
@@ -2626,6 +2668,14 @@ class Transaction {
2626
2668
  serializeMessage() {
2627
2669
  return this._compile().serialize();
2628
2670
  }
2671
+ /**
2672
+ * Get the estimated fee associated with a transaction
2673
+ */
2674
+
2675
+
2676
+ async getEstimatedFee(connection) {
2677
+ return (await connection.getFeeForMessage(this.compileMessage())).value;
2678
+ }
2629
2679
  /**
2630
2680
  * Specify the public keys which will be used to sign the Transaction.
2631
2681
  * The first signer will be used as the transaction fee payer account.
@@ -2989,10 +3039,6 @@ function sleep(ms) {
2989
3039
  return new Promise(resolve => setTimeout(resolve, ms));
2990
3040
  }
2991
3041
 
2992
- /**
2993
- * @internal
2994
- */
2995
-
2996
3042
  /**
2997
3043
  * Populate a buffer of instruction data using an InstructionType
2998
3044
  * @internal
@@ -3792,11 +3838,11 @@ class SystemProgram {
3792
3838
  }
3793
3839
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3794
3840
 
3841
+ // Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
3795
3842
  // rest of the Transaction fields
3796
3843
  //
3797
3844
  // TODO: replace 300 with a proper constant for the size of the other
3798
3845
  // Transaction fields
3799
-
3800
3846
  const CHUNK_SIZE = PACKET_DATA_SIZE - 300;
3801
3847
  /**
3802
3848
  * Program loader interface
@@ -3904,7 +3950,9 @@ class Loader {
3904
3950
  instruction: 0,
3905
3951
  // Load instruction
3906
3952
  offset,
3907
- bytes
3953
+ bytes: bytes,
3954
+ bytesLength: 0,
3955
+ bytesLengthPadding: 0
3908
3956
  }, data);
3909
3957
  const transaction = new Transaction().add({
3910
3958
  keys: [{
@@ -4364,6 +4412,20 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.t
4364
4412
  unitsConsumed: superstruct.optional(superstruct.number())
4365
4413
  }));
4366
4414
 
4415
+ /**
4416
+ * Expected JSON RPC response for the "getBlockProduction" message
4417
+ */
4418
+ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4419
+ byIdentity: superstruct.record(superstruct.string(), superstruct.array(superstruct.number())),
4420
+ range: superstruct.type({
4421
+ firstSlot: superstruct.number(),
4422
+ lastSlot: superstruct.number()
4423
+ })
4424
+ }));
4425
+ /**
4426
+ * A performance sample
4427
+ */
4428
+
4367
4429
  function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
4368
4430
  let agentManager;
4369
4431
 
@@ -5224,6 +5286,14 @@ class Connection {
5224
5286
  get commitment() {
5225
5287
  return this._commitment;
5226
5288
  }
5289
+ /**
5290
+ * The RPC endpoint
5291
+ */
5292
+
5293
+
5294
+ get rpcEndpoint() {
5295
+ return this._rpcEndpoint;
5296
+ }
5227
5297
  /**
5228
5298
  * Fetch the balance for the specified public key, return with context
5229
5299
  */
@@ -5509,35 +5579,32 @@ class Connection {
5509
5579
  }
5510
5580
  }
5511
5581
  /**
5512
- * Fetch all the account info for multiple accounts specified by an array of public keys
5582
+ * Fetch all the account info for multiple accounts specified by an array of public keys, return with context
5513
5583
  */
5514
5584
 
5515
5585
 
5516
- async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5586
+ async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
5517
5587
  const keys = publicKeys.map(key => key.toBase58());
5518
- let commitment;
5519
- let encoding = 'base64';
5520
5588
 
5521
- if (configOrCommitment) {
5522
- if (typeof configOrCommitment === 'string') {
5523
- commitment = configOrCommitment;
5524
- encoding = 'base64';
5525
- } else {
5526
- commitment = configOrCommitment.commitment;
5527
- encoding = configOrCommitment.encoding || 'base64';
5528
- }
5529
- }
5530
-
5531
- const args = this._buildArgs([keys], commitment, encoding);
5589
+ const args = this._buildArgs([keys], commitment, 'base64');
5532
5590
 
5533
5591
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5534
- const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(ParsedAccountInfoResult))));
5592
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
5535
5593
 
5536
5594
  if ('error' in res) {
5537
5595
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
5538
5596
  }
5539
5597
 
5540
- return res.result.value;
5598
+ return res.result;
5599
+ }
5600
+ /**
5601
+ * Fetch all the account info for multiple accounts specified by an array of public keys
5602
+ */
5603
+
5604
+
5605
+ async getMultipleAccountsInfo(publicKeys, commitment) {
5606
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
5607
+ return res.value;
5541
5608
  }
5542
5609
  /**
5543
5610
  * Returns epoch activation information for a stake account that has been delegated
@@ -6149,6 +6216,54 @@ class Connection {
6149
6216
  })
6150
6217
  };
6151
6218
  }
6219
+ /*
6220
+ * Returns the current block height of the node
6221
+ */
6222
+
6223
+
6224
+ async getBlockHeight(commitment) {
6225
+ const args = this._buildArgs([], commitment);
6226
+
6227
+ const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6228
+ const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6229
+
6230
+ if ('error' in res) {
6231
+ throw new Error('failed to get block height information: ' + res.error.message);
6232
+ }
6233
+
6234
+ return res.result;
6235
+ }
6236
+ /*
6237
+ * Returns recent block production information from the current or previous epoch
6238
+ */
6239
+
6240
+
6241
+ async getBlockProduction(configOrCommitment) {
6242
+ let extra;
6243
+ let commitment;
6244
+
6245
+ if (typeof configOrCommitment === 'string') {
6246
+ commitment = configOrCommitment;
6247
+ } else if (configOrCommitment) {
6248
+ const {
6249
+ commitment: c,
6250
+ ...rest
6251
+ } = configOrCommitment;
6252
+ commitment = c;
6253
+ extra = rest;
6254
+ }
6255
+
6256
+ const args = this._buildArgs([], commitment, 'base64', extra);
6257
+
6258
+ const unsafeRes = await this._rpcRequest('getBlockProduction', args);
6259
+ const res = superstruct.create(unsafeRes, BlockProductionResponseStruct);
6260
+
6261
+ if ('error' in res) {
6262
+ throw new Error('failed to get block production information: ' + res.error.message);
6263
+ }
6264
+
6265
+ return res.result;
6266
+ }
6152
6267
  /**
6153
6268
  * Fetch a confirmed or finalized transaction from the cluster.
6154
6269
  */
@@ -6809,12 +6924,6 @@ class Connection {
6809
6924
 
6810
6925
  if ('data' in res.error) {
6811
6926
  logs = res.error.data.logs;
6812
-
6813
- if (logs && Array.isArray(logs)) {
6814
- const traceIndent = '\n ';
6815
- const logTrace = traceIndent + logs.join(traceIndent);
6816
- console.error(res.error.message, logTrace);
6817
- }
6818
6927
  }
6819
6928
 
6820
6929
  throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
@@ -7630,16 +7739,18 @@ class Ed25519Program {
7630
7739
  const messageDataOffset = signatureOffset + signature.length;
7631
7740
  const numSignatures = 1;
7632
7741
  const instructionData = buffer.Buffer.alloc(messageDataOffset + message.length);
7742
+ const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
7743
+ : instructionIndex;
7633
7744
  ED25519_INSTRUCTION_LAYOUT.encode({
7634
7745
  numSignatures,
7635
7746
  padding: 0,
7636
7747
  signatureOffset,
7637
- signatureInstructionIndex: instructionIndex,
7748
+ signatureInstructionIndex: index,
7638
7749
  publicKeyOffset,
7639
- publicKeyInstructionIndex: instructionIndex,
7750
+ publicKeyInstructionIndex: index,
7640
7751
  messageDataOffset,
7641
7752
  messageDataSize: message.length,
7642
- messageInstructionIndex: instructionIndex
7753
+ messageInstructionIndex: index
7643
7754
  }, instructionData);
7644
7755
  instructionData.fill(publicKey, publicKeyOffset);
7645
7756
  instructionData.fill(signature, signatureOffset);
@@ -7710,10 +7821,10 @@ class Authorized {
7710
7821
  }
7711
7822
 
7712
7823
  }
7824
+
7713
7825
  /**
7714
7826
  * Stake account lockup info
7715
7827
  */
7716
-
7717
7828
  class Lockup {
7718
7829
  /** Unix timestamp of lockup expiration */
7719
7830
 
@@ -7738,10 +7849,6 @@ class Lockup {
7738
7849
 
7739
7850
 
7740
7851
  }
7741
- /**
7742
- * Create stake account transaction params
7743
- */
7744
-
7745
7852
  Lockup.default = new Lockup(0, 0, PublicKey.default);
7746
7853
 
7747
7854
  /**
@@ -8769,8 +8876,8 @@ class VoteAccount {
8769
8876
  }
8770
8877
 
8771
8878
  function parseAuthorizedVoter({
8772
- epoch,
8773
- authorizedVoter
8879
+ authorizedVoter,
8880
+ epoch
8774
8881
  }) {
8775
8882
  return {
8776
8883
  epoch,
@@ -8799,7 +8906,7 @@ function getPriorVoters({
8799
8906
  return [];
8800
8907
  }
8801
8908
 
8802
- return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8909
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx).map(parsePriorVoters)];
8803
8910
  }
8804
8911
 
8805
8912
  /**