@solana/web3.js 1.36.0 → 1.37.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.
@@ -47,24 +47,28 @@ var inherits_browser = {exports: {}};
47
47
  if (typeof Object.create === 'function') {
48
48
  // implementation from standard node.js 'util' module
49
49
  inherits_browser.exports = function inherits(ctor, superCtor) {
50
- ctor.super_ = superCtor;
51
- ctor.prototype = Object.create(superCtor.prototype, {
52
- constructor: {
53
- value: ctor,
54
- enumerable: false,
55
- writable: true,
56
- configurable: true
57
- }
58
- });
50
+ if (superCtor) {
51
+ ctor.super_ = superCtor;
52
+ ctor.prototype = Object.create(superCtor.prototype, {
53
+ constructor: {
54
+ value: ctor,
55
+ enumerable: false,
56
+ writable: true,
57
+ configurable: true
58
+ }
59
+ });
60
+ }
59
61
  };
60
62
  } else {
61
63
  // old school shim for old browsers
62
64
  inherits_browser.exports = function inherits(ctor, superCtor) {
63
- ctor.super_ = superCtor;
64
- var TempCtor = function () {};
65
- TempCtor.prototype = superCtor.prototype;
66
- ctor.prototype = new TempCtor();
67
- ctor.prototype.constructor = ctor;
65
+ if (superCtor) {
66
+ ctor.super_ = superCtor;
67
+ var TempCtor = function () {};
68
+ TempCtor.prototype = superCtor.prototype;
69
+ ctor.prototype = new TempCtor();
70
+ ctor.prototype.constructor = ctor;
71
+ }
68
72
  };
69
73
  }
70
74
 
@@ -1277,7 +1281,7 @@ hash.ripemd160 = hash.ripemd.ripemd160;
1277
1281
 
1278
1282
  var hash = hash$1;
1279
1283
 
1280
- const version$2 = "logger/5.5.0";
1284
+ const version$2 = "logger/5.6.0";
1281
1285
 
1282
1286
  let _permanentCensorErrors = false;
1283
1287
  let _censorErrors = false;
@@ -1456,6 +1460,40 @@ class Logger {
1456
1460
  messageDetails.push(`code=${code}`);
1457
1461
  messageDetails.push(`version=${this.version}`);
1458
1462
  const reason = message;
1463
+ let url = "";
1464
+ switch (code) {
1465
+ case ErrorCode.NUMERIC_FAULT: {
1466
+ url = "NUMERIC_FAULT";
1467
+ const fault = message;
1468
+ switch (fault) {
1469
+ case "overflow":
1470
+ case "underflow":
1471
+ case "division-by-zero":
1472
+ url += "-" + fault;
1473
+ break;
1474
+ case "negative-power":
1475
+ case "negative-width":
1476
+ url += "-unsupported";
1477
+ break;
1478
+ case "unbound-bitwise-result":
1479
+ url += "-unbound-result";
1480
+ break;
1481
+ }
1482
+ break;
1483
+ }
1484
+ case ErrorCode.CALL_EXCEPTION:
1485
+ case ErrorCode.INSUFFICIENT_FUNDS:
1486
+ case ErrorCode.MISSING_NEW:
1487
+ case ErrorCode.NONCE_EXPIRED:
1488
+ case ErrorCode.REPLACEMENT_UNDERPRICED:
1489
+ case ErrorCode.TRANSACTION_REPLACED:
1490
+ case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
1491
+ url = code;
1492
+ break;
1493
+ }
1494
+ if (url) {
1495
+ message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
1496
+ }
1459
1497
  if (messageDetails.length) {
1460
1498
  message += " (" + messageDetails.join(", ") + ")";
1461
1499
  }
@@ -1589,7 +1627,7 @@ class Logger {
1589
1627
  Logger.errors = ErrorCode;
1590
1628
  Logger.levels = LogLevel;
1591
1629
 
1592
- const version$1 = "bytes/5.5.0";
1630
+ const version$1 = "bytes/5.6.0";
1593
1631
 
1594
1632
  const logger = new Logger(version$1);
1595
1633
  ///////////////////////////////
@@ -1686,7 +1724,7 @@ function isHexString(value, length) {
1686
1724
  return true;
1687
1725
  }
1688
1726
 
1689
- const version = "sha2/5.5.0";
1727
+ const version = "sha2/5.6.0";
1690
1728
 
1691
1729
  new Logger(version);
1692
1730
  function sha256(data) {
@@ -2024,10 +2062,10 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2024
2062
  const publicKey = (property = 'publicKey') => {
2025
2063
  return BufferLayout.blob(32, property);
2026
2064
  };
2065
+
2027
2066
  /**
2028
2067
  * Layout for a Rust String type
2029
2068
  */
2030
-
2031
2069
  const rustString = (property = 'string') => {
2032
2070
  const rsl = BufferLayout.struct([BufferLayout.u32('length'), BufferLayout.u32('lengthPadding'), BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars')], property);
2033
2071
 
@@ -2035,24 +2073,26 @@ const rustString = (property = 'string') => {
2035
2073
 
2036
2074
  const _encode = rsl.encode.bind(rsl);
2037
2075
 
2038
- rsl.decode = (buffer, offset) => {
2039
- const data = _decode(buffer, offset);
2076
+ const rslShim = rsl;
2077
+
2078
+ rslShim.decode = (b, offset) => {
2079
+ const data = _decode(b, offset);
2040
2080
 
2041
- return data['chars'].toString('utf8');
2081
+ return data['chars'].toString();
2042
2082
  };
2043
2083
 
2044
- rsl.encode = (str, buffer, offset) => {
2084
+ rslShim.encode = (str, b, offset) => {
2045
2085
  const data = {
2046
2086
  chars: Buffer.from(str, 'utf8')
2047
2087
  };
2048
- return _encode(data, buffer, offset);
2088
+ return _encode(data, b, offset);
2049
2089
  };
2050
2090
 
2051
- rsl.alloc = str => {
2091
+ rslShim.alloc = str => {
2052
2092
  return BufferLayout.u32().span + BufferLayout.u32().span + Buffer.from(str, 'utf8').length;
2053
2093
  };
2054
2094
 
2055
- return rsl;
2095
+ return rslShim;
2056
2096
  };
2057
2097
  /**
2058
2098
  * Layout for an Authorized object
@@ -2172,7 +2212,7 @@ class Message {
2172
2212
  accounts,
2173
2213
  programIdIndex
2174
2214
  } = instruction;
2175
- const data = bs58.decode(instruction.data);
2215
+ const data = Array.from(bs58.decode(instruction.data));
2176
2216
  let keyIndicesCount = [];
2177
2217
  encodeLength(keyIndicesCount, accounts.length);
2178
2218
  let dataCount = [];
@@ -2180,7 +2220,7 @@ class Message {
2180
2220
  return {
2181
2221
  programIdIndex,
2182
2222
  keyIndicesCount: Buffer.from(keyIndicesCount),
2183
- keyIndices: Buffer.from(accounts),
2223
+ keyIndices: accounts,
2184
2224
  dataLength: Buffer.from(dataCount),
2185
2225
  data
2186
2226
  };
@@ -2584,6 +2624,14 @@ class Transaction {
2584
2624
  serializeMessage() {
2585
2625
  return this._compile().serialize();
2586
2626
  }
2627
+ /**
2628
+ * Get the estimated fee associated with a transaction
2629
+ */
2630
+
2631
+
2632
+ async getEstimatedFee(connection) {
2633
+ return (await connection.getFeeForMessage(this.compileMessage())).value;
2634
+ }
2587
2635
  /**
2588
2636
  * Specify the public keys which will be used to sign the Transaction.
2589
2637
  * The first signer will be used as the transaction fee payer account.
@@ -2947,10 +2995,6 @@ function sleep(ms) {
2947
2995
  return new Promise(resolve => setTimeout(resolve, ms));
2948
2996
  }
2949
2997
 
2950
- /**
2951
- * @internal
2952
- */
2953
-
2954
2998
  /**
2955
2999
  * Populate a buffer of instruction data using an InstructionType
2956
3000
  * @internal
@@ -3750,11 +3794,11 @@ class SystemProgram {
3750
3794
  }
3751
3795
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3752
3796
 
3797
+ // Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
3753
3798
  // rest of the Transaction fields
3754
3799
  //
3755
3800
  // TODO: replace 300 with a proper constant for the size of the other
3756
3801
  // Transaction fields
3757
-
3758
3802
  const CHUNK_SIZE = PACKET_DATA_SIZE - 300;
3759
3803
  /**
3760
3804
  * Program loader interface
@@ -3862,7 +3906,9 @@ class Loader {
3862
3906
  instruction: 0,
3863
3907
  // Load instruction
3864
3908
  offset,
3865
- bytes
3909
+ bytes: bytes,
3910
+ bytesLength: 0,
3911
+ bytesLengthPadding: 0
3866
3912
  }, data);
3867
3913
  const transaction = new Transaction().add({
3868
3914
  keys: [{
@@ -4494,7 +4540,7 @@ return new F();
4494
4540
 
4495
4541
  return exports;
4496
4542
 
4497
- })({}));
4543
+ }))({});
4498
4544
  })(__self__);
4499
4545
  __self__.fetch.ponyfill = true;
4500
4546
  // Remove "polyfill" property added by whatwg-fetch
@@ -4834,6 +4880,20 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
4834
4880
  unitsConsumed: optional(number())
4835
4881
  }));
4836
4882
 
4883
+ /**
4884
+ * Expected JSON RPC response for the "getBlockProduction" message
4885
+ */
4886
+ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
4887
+ byIdentity: record(string(), array(number())),
4888
+ range: type({
4889
+ firstSlot: number(),
4890
+ lastSlot: number()
4891
+ })
4892
+ }));
4893
+ /**
4894
+ * A performance sample
4895
+ */
4896
+
4837
4897
  function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
4838
4898
 
4839
4899
  let fetchWithMiddleware;
@@ -5688,6 +5748,14 @@ class Connection {
5688
5748
  get commitment() {
5689
5749
  return this._commitment;
5690
5750
  }
5751
+ /**
5752
+ * The RPC endpoint
5753
+ */
5754
+
5755
+
5756
+ get rpcEndpoint() {
5757
+ return this._rpcEndpoint;
5758
+ }
5691
5759
  /**
5692
5760
  * Fetch the balance for the specified public key, return with context
5693
5761
  */
@@ -6610,6 +6678,54 @@ class Connection {
6610
6678
  })
6611
6679
  };
6612
6680
  }
6681
+ /*
6682
+ * Returns the current block height of the node
6683
+ */
6684
+
6685
+
6686
+ async getBlockHeight(commitment) {
6687
+ const args = this._buildArgs([], commitment);
6688
+
6689
+ const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6690
+ const res = create(unsafeRes, jsonRpcResult(number()));
6691
+
6692
+ if ('error' in res) {
6693
+ throw new Error('failed to get block height information: ' + res.error.message);
6694
+ }
6695
+
6696
+ return res.result;
6697
+ }
6698
+ /*
6699
+ * Returns recent block production information from the current or previous epoch
6700
+ */
6701
+
6702
+
6703
+ async getBlockProduction(configOrCommitment) {
6704
+ let extra;
6705
+ let commitment;
6706
+
6707
+ if (typeof configOrCommitment === 'string') {
6708
+ commitment = configOrCommitment;
6709
+ } else if (configOrCommitment) {
6710
+ const {
6711
+ commitment: c,
6712
+ ...rest
6713
+ } = configOrCommitment;
6714
+ commitment = c;
6715
+ extra = rest;
6716
+ }
6717
+
6718
+ const args = this._buildArgs([], commitment, 'base64', extra);
6719
+
6720
+ const unsafeRes = await this._rpcRequest('getBlockProduction', args);
6721
+ const res = create(unsafeRes, BlockProductionResponseStruct);
6722
+
6723
+ if ('error' in res) {
6724
+ throw new Error('failed to get block production information: ' + res.error.message);
6725
+ }
6726
+
6727
+ return res.result;
6728
+ }
6613
6729
  /**
6614
6730
  * Fetch a confirmed or finalized transaction from the cluster.
6615
6731
  */
@@ -7102,7 +7218,14 @@ class Connection {
7102
7218
  let transaction;
7103
7219
 
7104
7220
  if (transactionOrMessage instanceof Transaction) {
7105
- transaction = transactionOrMessage;
7221
+ let originalTx = transactionOrMessage;
7222
+ transaction = new Transaction({
7223
+ recentBlockhash: originalTx.recentBlockhash,
7224
+ nonceInfo: originalTx.nonceInfo,
7225
+ feePayer: originalTx.feePayer,
7226
+ signatures: [...originalTx.signatures]
7227
+ });
7228
+ transaction.instructions = transactionOrMessage.instructions;
7106
7229
  } else {
7107
7230
  transaction = Transaction.populate(transactionOrMessage);
7108
7231
  }
@@ -7270,12 +7393,6 @@ class Connection {
7270
7393
 
7271
7394
  if ('data' in res.error) {
7272
7395
  logs = res.error.data.logs;
7273
-
7274
- if (logs && Array.isArray(logs)) {
7275
- const traceIndent = '\n ';
7276
- const logTrace = traceIndent + logs.join(traceIndent);
7277
- console.error(res.error.message, logTrace);
7278
- }
7279
7396
  }
7280
7397
 
7281
7398
  throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
@@ -7381,6 +7498,7 @@ class Connection {
7381
7498
 
7382
7499
  _resetSubscriptions() {
7383
7500
  Object.values(this._accountChangeSubscriptions).forEach(s => s.subscriptionId = null);
7501
+ Object.values(this._logsSubscriptions).forEach(s => s.subscriptionId = null);
7384
7502
  Object.values(this._programAccountChangeSubscriptions).forEach(s => s.subscriptionId = null);
7385
7503
  Object.values(this._rootSubscriptions).forEach(s => s.subscriptionId = null);
7386
7504
  Object.values(this._signatureSubscriptions).forEach(s => s.subscriptionId = null);
@@ -8091,16 +8209,18 @@ class Ed25519Program {
8091
8209
  const messageDataOffset = signatureOffset + signature.length;
8092
8210
  const numSignatures = 1;
8093
8211
  const instructionData = Buffer.alloc(messageDataOffset + message.length);
8212
+ const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
8213
+ : instructionIndex;
8094
8214
  ED25519_INSTRUCTION_LAYOUT.encode({
8095
8215
  numSignatures,
8096
8216
  padding: 0,
8097
8217
  signatureOffset,
8098
- signatureInstructionIndex: instructionIndex,
8218
+ signatureInstructionIndex: index,
8099
8219
  publicKeyOffset,
8100
- publicKeyInstructionIndex: instructionIndex,
8220
+ publicKeyInstructionIndex: index,
8101
8221
  messageDataOffset,
8102
8222
  messageDataSize: message.length,
8103
- messageInstructionIndex: instructionIndex
8223
+ messageInstructionIndex: index
8104
8224
  }, instructionData);
8105
8225
  instructionData.fill(publicKey, publicKeyOffset);
8106
8226
  instructionData.fill(signature, signatureOffset);
@@ -8171,10 +8291,10 @@ class Authorized {
8171
8291
  }
8172
8292
 
8173
8293
  }
8294
+
8174
8295
  /**
8175
8296
  * Stake account lockup info
8176
8297
  */
8177
-
8178
8298
  class Lockup {
8179
8299
  /** Unix timestamp of lockup expiration */
8180
8300
 
@@ -8199,10 +8319,6 @@ class Lockup {
8199
8319
 
8200
8320
 
8201
8321
  }
8202
- /**
8203
- * Create stake account transaction params
8204
- */
8205
-
8206
8322
  Lockup.default = new Lockup(0, 0, PublicKey.default);
8207
8323
 
8208
8324
  /**
@@ -9230,8 +9346,8 @@ class VoteAccount {
9230
9346
  }
9231
9347
 
9232
9348
  function parseAuthorizedVoter({
9233
- epoch,
9234
- authorizedVoter
9349
+ authorizedVoter,
9350
+ epoch
9235
9351
  }) {
9236
9352
  return {
9237
9353
  epoch,
@@ -9260,7 +9376,7 @@ function getPriorVoters({
9260
9376
  return [];
9261
9377
  }
9262
9378
 
9263
- return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
9379
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx).map(parsePriorVoters)];
9264
9380
  }
9265
9381
 
9266
9382
  /**