@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.d.ts CHANGED
@@ -302,8 +302,13 @@ declare module '@solana/web3.js' {
302
302
  accountKeys: PublicKey[];
303
303
  recentBlockhash: Blockhash;
304
304
  instructions: CompiledInstruction[];
305
+ private indexToProgramIds;
305
306
  constructor(args: MessageArgs);
307
+ isAccountSigner(index: number): boolean;
306
308
  isAccountWritable(index: number): boolean;
309
+ isProgramId(index: number): boolean;
310
+ programIds(): PublicKey[];
311
+ nonProgramIds(): PublicKey[];
307
312
  serialize(): Buffer;
308
313
  /**
309
314
  * Decode a compiled message into a Message object.
@@ -505,7 +510,7 @@ declare module '@solana/web3.js' {
505
510
  /**
506
511
  * Populate Transaction object from message and signatures
507
512
  */
508
- static populate(message: Message, signatures: Array<string>): Transaction;
513
+ static populate(message: Message, signatures?: Array<string>): Transaction;
509
514
  }
510
515
 
511
516
  export type TokenAccountsFilter =
@@ -720,9 +725,23 @@ declare module '@solana/web3.js' {
720
725
  'solana-core': string;
721
726
  'feature-set'?: number;
722
727
  };
728
+ export type SimulatedTransactionAccountInfo = {
729
+ /** `true` if this account's data contains a loaded program */
730
+ executable: boolean;
731
+ /** Identifier of the program that owns the account */
732
+ owner: string;
733
+ /** Number of lamports assigned to the account */
734
+ lamports: number;
735
+ /** Optional data assigned to the account */
736
+ data: string[];
737
+ /** Optional rent epoch info for account */
738
+ rentEpoch?: number;
739
+ };
723
740
  export type SimulatedTransactionResponse = {
724
741
  err: TransactionError | string | null;
725
742
  logs: Array<string> | null;
743
+ accounts?: SimulatedTransactionAccountInfo[] | null;
744
+ unitsConsumed?: number;
726
745
  };
727
746
  export type ParsedInnerInstruction = {
728
747
  index: number;
@@ -1172,6 +1191,8 @@ declare module '@solana/web3.js' {
1172
1191
  lamports: number;
1173
1192
  /** Optional data assigned to the account */
1174
1193
  data: T;
1194
+ /** Optional rent epoch infor for account */
1195
+ rentEpoch?: number;
1175
1196
  };
1176
1197
  /**
1177
1198
  * Account information identified by pubkey
@@ -1334,6 +1355,8 @@ declare module '@solana/web3.js' {
1334
1355
  fetchMiddleware?: FetchMiddleware;
1335
1356
  /** Optional Disable retring calls when server responds with HTTP 429 (Too Many Requests) */
1336
1357
  disableRetryOnRateLimit?: boolean;
1358
+ /** time to allow for the server to initially process a transaction (in milliseconds) */
1359
+ confirmTransactionInitialTimeout?: number;
1337
1360
  };
1338
1361
  /**
1339
1362
  * A connection to a fullnode JSON RPC endpoint
@@ -1767,8 +1790,9 @@ declare module '@solana/web3.js' {
1767
1790
  * Simulate a transaction
1768
1791
  */
1769
1792
  simulateTransaction(
1770
- transaction: Transaction,
1793
+ transactionOrMessage: Transaction | Message,
1771
1794
  signers?: Array<Signer>,
1795
+ includeAccounts?: boolean | Array<PublicKey>,
1772
1796
  ): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
1773
1797
  /**
1774
1798
  * Sign and send a transaction
package/lib/index.esm.js CHANGED
@@ -461,16 +461,35 @@ class Message {
461
461
 
462
462
  _defineProperty(this, "instructions", void 0);
463
463
 
464
+ _defineProperty(this, "indexToProgramIds", new Map());
465
+
464
466
  this.header = args.header;
465
467
  this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
466
468
  this.recentBlockhash = args.recentBlockhash;
467
469
  this.instructions = args.instructions;
470
+ this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
471
+ }
472
+
473
+ isAccountSigner(index) {
474
+ return index < this.header.numRequiredSignatures;
468
475
  }
469
476
 
470
477
  isAccountWritable(index) {
471
478
  return index < this.header.numRequiredSignatures - this.header.numReadonlySignedAccounts || index >= this.header.numRequiredSignatures && index < this.accountKeys.length - this.header.numReadonlyUnsignedAccounts;
472
479
  }
473
480
 
481
+ isProgramId(index) {
482
+ return this.indexToProgramIds.has(index);
483
+ }
484
+
485
+ programIds() {
486
+ return [...this.indexToProgramIds.values()];
487
+ }
488
+
489
+ nonProgramIds() {
490
+ return this.accountKeys.filter((_, index) => !this.isProgramId(index));
491
+ }
492
+
474
493
  serialize() {
475
494
  const numKeys = this.accountKeys.length;
476
495
  let keyCount = [];
@@ -1185,7 +1204,7 @@ class Transaction {
1185
1204
  */
1186
1205
 
1187
1206
 
1188
- static populate(message, signatures) {
1207
+ static populate(message, signatures = []) {
1189
1208
  const transaction = new Transaction();
1190
1209
  transaction.recentBlockhash = message.recentBlockhash;
1191
1210
 
@@ -1205,7 +1224,7 @@ class Transaction {
1205
1224
  const pubkey = message.accountKeys[account];
1206
1225
  return {
1207
1226
  pubkey,
1208
- isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()),
1227
+ isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
1209
1228
  isWritable: message.isAccountWritable(account)
1210
1229
  };
1211
1230
  });
@@ -2637,7 +2656,15 @@ const VersionResult = type({
2637
2656
  });
2638
2657
  const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
2639
2658
  err: nullable(union([type({}), string()])),
2640
- logs: nullable(array(string()))
2659
+ logs: nullable(array(string())),
2660
+ accounts: optional(nullable(array(type({
2661
+ executable: boolean(),
2662
+ owner: string(),
2663
+ lamports: number(),
2664
+ data: array(string()),
2665
+ rentEpoch: optional(number())
2666
+ })))),
2667
+ unitsConsumed: optional(number())
2641
2668
  }));
2642
2669
 
2643
2670
  function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
@@ -3369,6 +3396,8 @@ class Connection {
3369
3396
 
3370
3397
  /** @internal */
3371
3398
 
3399
+ /** @internal */
3400
+
3372
3401
  /**
3373
3402
  * Establish a JSON RPC connection
3374
3403
  *
@@ -3378,6 +3407,8 @@ class Connection {
3378
3407
  constructor(endpoint, commitmentOrConfig) {
3379
3408
  _defineProperty(this, "_commitment", void 0);
3380
3409
 
3410
+ _defineProperty(this, "_confirmTransactionInitialTimeout", void 0);
3411
+
3381
3412
  _defineProperty(this, "_rpcEndpoint", void 0);
3382
3413
 
3383
3414
  _defineProperty(this, "_rpcWsEndpoint", void 0);
@@ -3446,6 +3477,7 @@ class Connection {
3446
3477
  this._commitment = commitmentOrConfig;
3447
3478
  } else if (commitmentOrConfig) {
3448
3479
  this._commitment = commitmentOrConfig.commitment;
3480
+ this._confirmTransactionInitialTimeout = commitmentOrConfig.confirmTransactionInitialTimeout;
3449
3481
  wsEndpoint = commitmentOrConfig.wsEndpoint;
3450
3482
  httpHeaders = commitmentOrConfig.httpHeaders;
3451
3483
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
@@ -3905,7 +3937,7 @@ class Connection {
3905
3937
  reject(err);
3906
3938
  }
3907
3939
  });
3908
- let timeoutMs = 60 * 1000;
3940
+ let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
3909
3941
 
3910
3942
  switch (subscriptionCommitment) {
3911
3943
  case 'processed':
@@ -3914,7 +3946,7 @@ class Connection {
3914
3946
  case 'confirmed':
3915
3947
  case 'singleGossip':
3916
3948
  {
3917
- timeoutMs = 30 * 1000;
3949
+ timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
3918
3950
  break;
3919
3951
  }
3920
3952
  }
@@ -4701,7 +4733,15 @@ class Connection {
4701
4733
  */
4702
4734
 
4703
4735
 
4704
- async simulateTransaction(transaction, signers) {
4736
+ async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
4737
+ let transaction;
4738
+
4739
+ if (transactionOrMessage instanceof Transaction) {
4740
+ transaction = transactionOrMessage;
4741
+ } else {
4742
+ transaction = Transaction.populate(transactionOrMessage);
4743
+ }
4744
+
4705
4745
  if (transaction.nonceInfo && signers) {
4706
4746
  transaction.sign(...signers);
4707
4747
  } else {
@@ -4734,7 +4774,9 @@ class Connection {
4734
4774
  }
4735
4775
  }
4736
4776
 
4737
- const signData = transaction.serializeMessage();
4777
+ const message = transaction._compile();
4778
+
4779
+ const signData = message.serialize();
4738
4780
 
4739
4781
  const wireTransaction = transaction._serialize(signData);
4740
4782
 
@@ -4744,6 +4786,14 @@ class Connection {
4744
4786
  commitment: this.commitment
4745
4787
  };
4746
4788
 
4789
+ if (includeAccounts) {
4790
+ const addresses = (Array.isArray(includeAccounts) ? includeAccounts : message.nonProgramIds()).map(key => key.toBase58());
4791
+ config['accounts'] = {
4792
+ encoding: 'base64',
4793
+ addresses
4794
+ };
4795
+ }
4796
+
4747
4797
  if (signers) {
4748
4798
  config.sigVerify = true;
4749
4799
  }