@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.
@@ -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;
2040
2077
 
2041
- return data['chars'].toString('utf8');
2078
+ rslShim.decode = (b, offset) => {
2079
+ const data = _decode(b, offset);
2080
+
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
  */
@@ -5973,35 +6041,32 @@ class Connection {
5973
6041
  }
5974
6042
  }
5975
6043
  /**
5976
- * Fetch all the account info for multiple accounts specified by an array of public keys
6044
+ * Fetch all the account info for multiple accounts specified by an array of public keys, return with context
5977
6045
  */
5978
6046
 
5979
6047
 
5980
- async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
6048
+ async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
5981
6049
  const keys = publicKeys.map(key => key.toBase58());
5982
- let commitment;
5983
- let encoding = 'base64';
5984
6050
 
5985
- if (configOrCommitment) {
5986
- if (typeof configOrCommitment === 'string') {
5987
- commitment = configOrCommitment;
5988
- encoding = 'base64';
5989
- } else {
5990
- commitment = configOrCommitment.commitment;
5991
- encoding = configOrCommitment.encoding || 'base64';
5992
- }
5993
- }
5994
-
5995
- const args = this._buildArgs([keys], commitment, encoding);
6051
+ const args = this._buildArgs([keys], commitment, 'base64');
5996
6052
 
5997
6053
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5998
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
6054
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
5999
6055
 
6000
6056
  if ('error' in res) {
6001
6057
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
6002
6058
  }
6003
6059
 
6004
- return res.result.value;
6060
+ return res.result;
6061
+ }
6062
+ /**
6063
+ * Fetch all the account info for multiple accounts specified by an array of public keys
6064
+ */
6065
+
6066
+
6067
+ async getMultipleAccountsInfo(publicKeys, commitment) {
6068
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
6069
+ return res.value;
6005
6070
  }
6006
6071
  /**
6007
6072
  * Returns epoch activation information for a stake account that has been delegated
@@ -6613,6 +6678,54 @@ class Connection {
6613
6678
  })
6614
6679
  };
6615
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
+ }
6616
6729
  /**
6617
6730
  * Fetch a confirmed or finalized transaction from the cluster.
6618
6731
  */
@@ -7273,12 +7386,6 @@ class Connection {
7273
7386
 
7274
7387
  if ('data' in res.error) {
7275
7388
  logs = res.error.data.logs;
7276
-
7277
- if (logs && Array.isArray(logs)) {
7278
- const traceIndent = '\n ';
7279
- const logTrace = traceIndent + logs.join(traceIndent);
7280
- console.error(res.error.message, logTrace);
7281
- }
7282
7389
  }
7283
7390
 
7284
7391
  throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
@@ -8094,16 +8201,18 @@ class Ed25519Program {
8094
8201
  const messageDataOffset = signatureOffset + signature.length;
8095
8202
  const numSignatures = 1;
8096
8203
  const instructionData = Buffer.alloc(messageDataOffset + message.length);
8204
+ const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
8205
+ : instructionIndex;
8097
8206
  ED25519_INSTRUCTION_LAYOUT.encode({
8098
8207
  numSignatures,
8099
8208
  padding: 0,
8100
8209
  signatureOffset,
8101
- signatureInstructionIndex: instructionIndex,
8210
+ signatureInstructionIndex: index,
8102
8211
  publicKeyOffset,
8103
- publicKeyInstructionIndex: instructionIndex,
8212
+ publicKeyInstructionIndex: index,
8104
8213
  messageDataOffset,
8105
8214
  messageDataSize: message.length,
8106
- messageInstructionIndex: instructionIndex
8215
+ messageInstructionIndex: index
8107
8216
  }, instructionData);
8108
8217
  instructionData.fill(publicKey, publicKeyOffset);
8109
8218
  instructionData.fill(signature, signatureOffset);
@@ -8174,10 +8283,10 @@ class Authorized {
8174
8283
  }
8175
8284
 
8176
8285
  }
8286
+
8177
8287
  /**
8178
8288
  * Stake account lockup info
8179
8289
  */
8180
-
8181
8290
  class Lockup {
8182
8291
  /** Unix timestamp of lockup expiration */
8183
8292
 
@@ -8202,10 +8311,6 @@ class Lockup {
8202
8311
 
8203
8312
 
8204
8313
  }
8205
- /**
8206
- * Create stake account transaction params
8207
- */
8208
-
8209
8314
  Lockup.default = new Lockup(0, 0, PublicKey.default);
8210
8315
 
8211
8316
  /**
@@ -9233,8 +9338,8 @@ class VoteAccount {
9233
9338
  }
9234
9339
 
9235
9340
  function parseAuthorizedVoter({
9236
- epoch,
9237
- authorizedVoter
9341
+ authorizedVoter,
9342
+ epoch
9238
9343
  }) {
9239
9344
  return {
9240
9345
  epoch,
@@ -9263,7 +9368,7 @@ function getPriorVoters({
9263
9368
  return [];
9264
9369
  }
9265
9370
 
9266
- return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
9371
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx).map(parsePriorVoters)];
9267
9372
  }
9268
9373
 
9269
9374
  /**