@solana/web3.js 1.27.1 → 1.28.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/module.flow.js CHANGED
@@ -362,7 +362,11 @@ declare module "@solana/web3.js" {
362
362
  recentBlockhash: Blockhash;
363
363
  instructions: CompiledInstruction[];
364
364
  constructor(args: MessageArgs): this;
365
+ isAccountSigner(index: number): boolean;
365
366
  isAccountWritable(index: number): boolean;
367
+ isProgramId(index: number): boolean;
368
+ programIds(): PublicKey[];
369
+ nonProgramIds(): PublicKey[];
366
370
  serialize(): Buffer;
367
371
 
368
372
  /**
@@ -626,7 +630,7 @@ declare module "@solana/web3.js" {
626
630
  /**
627
631
  * Populate Transaction object from message and signatures
628
632
  */
629
- static populate(message: Message, signatures: Array<string>): Transaction;
633
+ static populate(message: Message, signatures?: Array<string>): Transaction;
630
634
  }
631
635
  declare export type TokenAccountsFilter =
632
636
  | {
@@ -966,9 +970,38 @@ declare module "@solana/web3.js" {
966
970
  "feature-set"?: number,
967
971
  ...
968
972
  };
973
+ declare export type SimulatedTransactionAccountInfo = {
974
+ /**
975
+ * `true` if this account's data contains a loaded program
976
+ */
977
+ executable: boolean,
978
+
979
+ /**
980
+ * Identifier of the program that owns the account
981
+ */
982
+ owner: string,
983
+
984
+ /**
985
+ * Number of lamports assigned to the account
986
+ */
987
+ lamports: number,
988
+
989
+ /**
990
+ * Optional data assigned to the account
991
+ */
992
+ data: string[],
993
+
994
+ /**
995
+ * Optional rent epoch info for account
996
+ */
997
+ rentEpoch?: number,
998
+ ...
999
+ };
969
1000
  declare export type SimulatedTransactionResponse = {
970
1001
  err: TransactionError | string | null,
971
1002
  logs: Array<string> | null,
1003
+ accounts?: SimulatedTransactionAccountInfo[] | null,
1004
+ unitsConsumed?: number,
972
1005
  ...
973
1006
  };
974
1007
  declare export type ParsedInnerInstruction = {
@@ -1791,6 +1824,11 @@ declare module "@solana/web3.js" {
1791
1824
  * Optional data assigned to the account
1792
1825
  */
1793
1826
  data: T,
1827
+
1828
+ /**
1829
+ * Optional rent epoch infor for account
1830
+ */
1831
+ rentEpoch?: number,
1794
1832
  ...
1795
1833
  };
1796
1834
 
@@ -2024,6 +2062,11 @@ declare module "@solana/web3.js" {
2024
2062
  * Optional Disable retring calls when server responds with HTTP 429 (Too Many Requests)
2025
2063
  */
2026
2064
  disableRetryOnRateLimit?: boolean,
2065
+
2066
+ /**
2067
+ * time to allow for the server to initially process a transaction (in milliseconds)
2068
+ */
2069
+ confirmTransactionInitialTimeout?: number,
2027
2070
  ...
2028
2071
  };
2029
2072
 
@@ -2527,8 +2570,9 @@ feeCalculator: FeeCalculator,...
2527
2570
  * Simulate a transaction
2528
2571
  */
2529
2572
  simulateTransaction(
2530
- transaction: Transaction,
2531
- signers?: Array<Signer>
2573
+ transactionOrMessage: Transaction | Message,
2574
+ signers?: Array<Signer>,
2575
+ includeAccounts?: boolean | Array<PublicKey>
2532
2576
  ): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
2533
2577
 
2534
2578
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.27.1",
3
+ "version": "1.28.1",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
package/src/connection.ts CHANGED
@@ -439,15 +439,44 @@ const VersionResult = pick({
439
439
  'feature-set': optional(number()),
440
440
  });
441
441
 
442
+ export type SimulatedTransactionAccountInfo = {
443
+ /** `true` if this account's data contains a loaded program */
444
+ executable: boolean;
445
+ /** Identifier of the program that owns the account */
446
+ owner: string;
447
+ /** Number of lamports assigned to the account */
448
+ lamports: number;
449
+ /** Optional data assigned to the account */
450
+ data: string[];
451
+ /** Optional rent epoch info for account */
452
+ rentEpoch?: number;
453
+ };
454
+
442
455
  export type SimulatedTransactionResponse = {
443
456
  err: TransactionError | string | null;
444
457
  logs: Array<string> | null;
458
+ accounts?: SimulatedTransactionAccountInfo[] | null;
459
+ unitsConsumed?: number;
445
460
  };
446
461
 
447
462
  const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
448
463
  pick({
449
464
  err: nullable(union([pick({}), string()])),
450
465
  logs: nullable(array(string())),
466
+ accounts: optional(
467
+ nullable(
468
+ array(
469
+ pick({
470
+ executable: boolean(),
471
+ owner: string(),
472
+ lamports: number(),
473
+ data: array(string()),
474
+ rentEpoch: optional(number()),
475
+ }),
476
+ ),
477
+ ),
478
+ ),
479
+ unitsConsumed: optional(number()),
451
480
  }),
452
481
  );
453
482
 
@@ -1679,6 +1708,8 @@ export type AccountInfo<T> = {
1679
1708
  lamports: number;
1680
1709
  /** Optional data assigned to the account */
1681
1710
  data: T;
1711
+ /** Optional rent epoch infor for account */
1712
+ rentEpoch?: number;
1682
1713
  };
1683
1714
 
1684
1715
  /**
@@ -1948,6 +1979,8 @@ export type ConnectionConfig = {
1948
1979
  fetchMiddleware?: FetchMiddleware;
1949
1980
  /** Optional Disable retring calls when server responds with HTTP 429 (Too Many Requests) */
1950
1981
  disableRetryOnRateLimit?: boolean;
1982
+ /** time to allow for the server to initially process a transaction (in milliseconds) */
1983
+ confirmTransactionInitialTimeout?: number;
1951
1984
  };
1952
1985
 
1953
1986
  /**
@@ -1955,6 +1988,7 @@ export type ConnectionConfig = {
1955
1988
  */
1956
1989
  export class Connection {
1957
1990
  /** @internal */ _commitment?: Commitment;
1991
+ /** @internal */ _confirmTransactionInitialTimeout?: number;
1958
1992
  /** @internal */ _rpcEndpoint: string;
1959
1993
  /** @internal */ _rpcWsEndpoint: string;
1960
1994
  /** @internal */ _rpcClient: RpcClient;
@@ -2039,6 +2073,8 @@ export class Connection {
2039
2073
  this._commitment = commitmentOrConfig;
2040
2074
  } else if (commitmentOrConfig) {
2041
2075
  this._commitment = commitmentOrConfig.commitment;
2076
+ this._confirmTransactionInitialTimeout =
2077
+ commitmentOrConfig.confirmTransactionInitialTimeout;
2042
2078
  wsEndpoint = commitmentOrConfig.wsEndpoint;
2043
2079
  httpHeaders = commitmentOrConfig.httpHeaders;
2044
2080
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
@@ -2598,14 +2634,14 @@ export class Connection {
2598
2634
  }
2599
2635
  });
2600
2636
 
2601
- let timeoutMs = 60 * 1000;
2637
+ let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
2602
2638
  switch (subscriptionCommitment) {
2603
2639
  case 'processed':
2604
2640
  case 'recent':
2605
2641
  case 'single':
2606
2642
  case 'confirmed':
2607
2643
  case 'singleGossip': {
2608
- timeoutMs = 30 * 1000;
2644
+ timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
2609
2645
  break;
2610
2646
  }
2611
2647
  // exhaust enums to ensure full coverage
@@ -3430,9 +3466,17 @@ export class Connection {
3430
3466
  * Simulate a transaction
3431
3467
  */
3432
3468
  async simulateTransaction(
3433
- transaction: Transaction,
3469
+ transactionOrMessage: Transaction | Message,
3434
3470
  signers?: Array<Signer>,
3471
+ includeAccounts?: boolean | Array<PublicKey>,
3435
3472
  ): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
3473
+ let transaction;
3474
+ if (transactionOrMessage instanceof Transaction) {
3475
+ transaction = transactionOrMessage;
3476
+ } else {
3477
+ transaction = Transaction.populate(transactionOrMessage);
3478
+ }
3479
+
3436
3480
  if (transaction.nonceInfo && signers) {
3437
3481
  transaction.sign(...signers);
3438
3482
  } else {
@@ -3466,7 +3510,8 @@ export class Connection {
3466
3510
  }
3467
3511
  }
3468
3512
 
3469
- const signData = transaction.serializeMessage();
3513
+ const message = transaction._compile();
3514
+ const signData = message.serialize();
3470
3515
  const wireTransaction = transaction._serialize(signData);
3471
3516
  const encodedTransaction = wireTransaction.toString('base64');
3472
3517
  const config: any = {
@@ -3474,6 +3519,19 @@ export class Connection {
3474
3519
  commitment: this.commitment,
3475
3520
  };
3476
3521
 
3522
+ if (includeAccounts) {
3523
+ const addresses = (
3524
+ Array.isArray(includeAccounts)
3525
+ ? includeAccounts
3526
+ : message.nonProgramIds()
3527
+ ).map(key => key.toBase58());
3528
+
3529
+ config['accounts'] = {
3530
+ encoding: 'base64',
3531
+ addresses,
3532
+ };
3533
+ }
3534
+
3477
3535
  if (signers) {
3478
3536
  config.sigVerify = true;
3479
3537
  }
package/src/message.ts CHANGED
@@ -66,11 +66,26 @@ export class Message {
66
66
  recentBlockhash: Blockhash;
67
67
  instructions: CompiledInstruction[];
68
68
 
69
+ private indexToProgramIds: Map<number, PublicKey> = new Map<
70
+ number,
71
+ PublicKey
72
+ >();
73
+
69
74
  constructor(args: MessageArgs) {
70
75
  this.header = args.header;
71
76
  this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
72
77
  this.recentBlockhash = args.recentBlockhash;
73
78
  this.instructions = args.instructions;
79
+ this.instructions.forEach(ix =>
80
+ this.indexToProgramIds.set(
81
+ ix.programIdIndex,
82
+ this.accountKeys[ix.programIdIndex],
83
+ ),
84
+ );
85
+ }
86
+
87
+ isAccountSigner(index: number): boolean {
88
+ return index < this.header.numRequiredSignatures;
74
89
  }
75
90
 
76
91
  isAccountWritable(index: number): boolean {
@@ -84,6 +99,18 @@ export class Message {
84
99
  );
85
100
  }
86
101
 
102
+ isProgramId(index: number): boolean {
103
+ return this.indexToProgramIds.has(index);
104
+ }
105
+
106
+ programIds(): PublicKey[] {
107
+ return [...this.indexToProgramIds.values()];
108
+ }
109
+
110
+ nonProgramIds(): PublicKey[] {
111
+ return this.accountKeys.filter((_, index) => !this.isProgramId(index));
112
+ }
113
+
87
114
  serialize(): Buffer {
88
115
  const numKeys = this.accountKeys.length;
89
116
 
@@ -666,7 +666,10 @@ export class Transaction {
666
666
  /**
667
667
  * Populate Transaction object from message and signatures
668
668
  */
669
- static populate(message: Message, signatures: Array<string>): Transaction {
669
+ static populate(
670
+ message: Message,
671
+ signatures: Array<string> = [],
672
+ ): Transaction {
670
673
  const transaction = new Transaction();
671
674
  transaction.recentBlockhash = message.recentBlockhash;
672
675
  if (message.header.numRequiredSignatures > 0) {
@@ -688,9 +691,10 @@ export class Transaction {
688
691
  const pubkey = message.accountKeys[account];
689
692
  return {
690
693
  pubkey,
691
- isSigner: transaction.signatures.some(
692
- keyObj => keyObj.publicKey.toString() === pubkey.toString(),
693
- ),
694
+ isSigner:
695
+ transaction.signatures.some(
696
+ keyObj => keyObj.publicKey.toString() === pubkey.toString(),
697
+ ) || message.isAccountSigner(account),
694
698
  isWritable: message.isAccountWritable(account),
695
699
  };
696
700
  });