@solana/web3.js 1.27.0 → 1.28.0

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
@@ -498,16 +498,35 @@ class Message {
498
498
 
499
499
  _defineProperty__default['default'](this, "instructions", void 0);
500
500
 
501
+ _defineProperty__default['default'](this, "indexToProgramIds", new Map());
502
+
501
503
  this.header = args.header;
502
504
  this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
503
505
  this.recentBlockhash = args.recentBlockhash;
504
506
  this.instructions = args.instructions;
507
+ this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
508
+ }
509
+
510
+ isAccountSigner(index) {
511
+ return index < this.header.numRequiredSignatures;
505
512
  }
506
513
 
507
514
  isAccountWritable(index) {
508
515
  return index < this.header.numRequiredSignatures - this.header.numReadonlySignedAccounts || index >= this.header.numRequiredSignatures && index < this.accountKeys.length - this.header.numReadonlyUnsignedAccounts;
509
516
  }
510
517
 
518
+ isProgramId(index) {
519
+ return this.indexToProgramIds.has(index);
520
+ }
521
+
522
+ programIds() {
523
+ return [...this.indexToProgramIds.values()];
524
+ }
525
+
526
+ nonProgramIds() {
527
+ return this.accountKeys.filter((_, index) => !this.isProgramId(index));
528
+ }
529
+
511
530
  serialize() {
512
531
  const numKeys = this.accountKeys.length;
513
532
  let keyCount = [];
@@ -1222,7 +1241,7 @@ class Transaction {
1222
1241
  */
1223
1242
 
1224
1243
 
1225
- static populate(message, signatures) {
1244
+ static populate(message, signatures = []) {
1226
1245
  const transaction = new Transaction();
1227
1246
  transaction.recentBlockhash = message.recentBlockhash;
1228
1247
 
@@ -1242,7 +1261,7 @@ class Transaction {
1242
1261
  const pubkey = message.accountKeys[account];
1243
1262
  return {
1244
1263
  pubkey,
1245
- isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()),
1264
+ isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
1246
1265
  isWritable: message.isAccountWritable(account)
1247
1266
  };
1248
1267
  });
@@ -2674,7 +2693,15 @@ const VersionResult = superstruct.type({
2674
2693
  });
2675
2694
  const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.type({
2676
2695
  err: superstruct.nullable(superstruct.union([superstruct.type({}), superstruct.string()])),
2677
- logs: superstruct.nullable(superstruct.array(superstruct.string()))
2696
+ logs: superstruct.nullable(superstruct.array(superstruct.string())),
2697
+ accounts: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.type({
2698
+ executable: superstruct.boolean(),
2699
+ owner: superstruct.string(),
2700
+ lamports: superstruct.number(),
2701
+ data: superstruct.array(superstruct.string()),
2702
+ rentEpoch: superstruct.optional(superstruct.number())
2703
+ })))),
2704
+ unitsConsumed: superstruct.optional(superstruct.number())
2678
2705
  }));
2679
2706
 
2680
2707
  function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
@@ -3406,6 +3433,8 @@ class Connection {
3406
3433
 
3407
3434
  /** @internal */
3408
3435
 
3436
+ /** @internal */
3437
+
3409
3438
  /**
3410
3439
  * Establish a JSON RPC connection
3411
3440
  *
@@ -3415,6 +3444,8 @@ class Connection {
3415
3444
  constructor(endpoint, commitmentOrConfig) {
3416
3445
  _defineProperty__default['default'](this, "_commitment", void 0);
3417
3446
 
3447
+ _defineProperty__default['default'](this, "_confirmTransactionInitialTimeout", void 0);
3448
+
3418
3449
  _defineProperty__default['default'](this, "_rpcEndpoint", void 0);
3419
3450
 
3420
3451
  _defineProperty__default['default'](this, "_rpcWsEndpoint", void 0);
@@ -3483,6 +3514,7 @@ class Connection {
3483
3514
  this._commitment = commitmentOrConfig;
3484
3515
  } else if (commitmentOrConfig) {
3485
3516
  this._commitment = commitmentOrConfig.commitment;
3517
+ this._confirmTransactionInitialTimeout = commitmentOrConfig.confirmTransactionInitialTimeout;
3486
3518
  wsEndpoint = commitmentOrConfig.wsEndpoint;
3487
3519
  httpHeaders = commitmentOrConfig.httpHeaders;
3488
3520
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
@@ -3942,7 +3974,7 @@ class Connection {
3942
3974
  reject(err);
3943
3975
  }
3944
3976
  });
3945
- let timeoutMs = 60 * 1000;
3977
+ let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
3946
3978
 
3947
3979
  switch (subscriptionCommitment) {
3948
3980
  case 'processed':
@@ -3951,7 +3983,7 @@ class Connection {
3951
3983
  case 'confirmed':
3952
3984
  case 'singleGossip':
3953
3985
  {
3954
- timeoutMs = 30 * 1000;
3986
+ timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
3955
3987
  break;
3956
3988
  }
3957
3989
  }
@@ -4738,7 +4770,15 @@ class Connection {
4738
4770
  */
4739
4771
 
4740
4772
 
4741
- async simulateTransaction(transaction, signers) {
4773
+ async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
4774
+ let transaction;
4775
+
4776
+ if (transactionOrMessage instanceof Transaction) {
4777
+ transaction = transactionOrMessage;
4778
+ } else {
4779
+ transaction = Transaction.populate(transactionOrMessage);
4780
+ }
4781
+
4742
4782
  if (transaction.nonceInfo && signers) {
4743
4783
  transaction.sign(...signers);
4744
4784
  } else {
@@ -4771,7 +4811,9 @@ class Connection {
4771
4811
  }
4772
4812
  }
4773
4813
 
4774
- const signData = transaction.serializeMessage();
4814
+ const message = transaction._compile();
4815
+
4816
+ const signData = message.serialize();
4775
4817
 
4776
4818
  const wireTransaction = transaction._serialize(signData);
4777
4819
 
@@ -4781,6 +4823,14 @@ class Connection {
4781
4823
  commitment: this.commitment
4782
4824
  };
4783
4825
 
4826
+ if (includeAccounts) {
4827
+ const addresses = (Array.isArray(includeAccounts) ? includeAccounts : message.nonProgramIds()).map(key => key.toBase58());
4828
+ config['accounts'] = {
4829
+ encoding: 'base64',
4830
+ addresses
4831
+ };
4832
+ }
4833
+
4784
4834
  if (signers) {
4785
4835
  config.sigVerify = true;
4786
4836
  }