@solana/web3.js 1.4.1 → 1.5.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/lib/index.d.ts CHANGED
@@ -447,6 +447,14 @@ declare module '@solana/web3.js' {
447
447
  | 'singleGossip'
448
448
  | 'root'
449
449
  | 'max';
450
+ /**
451
+ * A subset of Commitment levels, which are at least optimistically confirmed
452
+ * <pre>
453
+ * 'confirmed': Query the most recent block which has reached 1 confirmation by the cluster
454
+ * 'finalized': Query the most recent block which has been finalized by the cluster
455
+ * </pre>
456
+ */
457
+ export type Finality = 'confirmed' | 'finalized';
450
458
  /**
451
459
  * Filter for largest accounts query
452
460
  * <pre>
@@ -1310,30 +1318,37 @@ declare module '@solana/web3.js' {
1310
1318
  * Fetch a list of Transactions and transaction statuses from the cluster
1311
1319
  * for a confirmed block
1312
1320
  */
1313
- getConfirmedBlock(slot: number): Promise<ConfirmedBlock>;
1321
+ getConfirmedBlock(
1322
+ slot: number,
1323
+ commitment?: Finality,
1324
+ ): Promise<ConfirmedBlock>;
1314
1325
  /**
1315
1326
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
1316
1327
  */
1317
1328
  getConfirmedBlockSignatures(
1318
1329
  slot: number,
1330
+ commitment?: Finality,
1319
1331
  ): Promise<ConfirmedBlockSignatures>;
1320
1332
  /**
1321
1333
  * Fetch a transaction details for a confirmed transaction
1322
1334
  */
1323
1335
  getConfirmedTransaction(
1324
1336
  signature: TransactionSignature,
1337
+ commitment?: Finality,
1325
1338
  ): Promise<ConfirmedTransaction | null>;
1326
1339
  /**
1327
1340
  * Fetch parsed transaction details for a confirmed transaction
1328
1341
  */
1329
1342
  getParsedConfirmedTransaction(
1330
1343
  signature: TransactionSignature,
1344
+ commitment?: Finality,
1331
1345
  ): Promise<ParsedConfirmedTransaction | null>;
1332
1346
  /**
1333
1347
  * Fetch parsed transaction details for a batch of confirmed transactions
1334
1348
  */
1335
1349
  getParsedConfirmedTransactions(
1336
1350
  signatures: TransactionSignature[],
1351
+ commitment?: Finality,
1337
1352
  ): Promise<(ParsedConfirmedTransaction | null)[]>;
1338
1353
  /**
1339
1354
  * Fetch a list of all the confirmed signatures for transactions involving an address
@@ -1360,6 +1375,7 @@ declare module '@solana/web3.js' {
1360
1375
  getConfirmedSignaturesForAddress2(
1361
1376
  address: PublicKey,
1362
1377
  options?: ConfirmedSignaturesForAddress2Options,
1378
+ commitment?: Finality,
1363
1379
  ): Promise<Array<ConfirmedSignatureInfo>>;
1364
1380
  /**
1365
1381
  * Fetch the contents of a Nonce account from the cluster, return with context
package/lib/index.esm.js CHANGED
@@ -3952,8 +3952,10 @@ class Connection {
3952
3952
  */
3953
3953
 
3954
3954
 
3955
- async getConfirmedBlock(slot) {
3956
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', [slot]);
3955
+ async getConfirmedBlock(slot, commitment) {
3956
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
3957
+
3958
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
3957
3959
  const res = create(unsafeRes, GetConfirmedBlockRpcResult);
3958
3960
 
3959
3961
  if ('error' in res) {
@@ -3973,11 +3975,13 @@ class Connection {
3973
3975
  */
3974
3976
 
3975
3977
 
3976
- async getConfirmedBlockSignatures(slot) {
3977
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', [slot, {
3978
+ async getConfirmedBlockSignatures(slot, commitment) {
3979
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
3978
3980
  transactionDetails: 'signatures',
3979
3981
  rewards: false
3980
- }]);
3982
+ });
3983
+
3984
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
3981
3985
  const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
3982
3986
 
3983
3987
  if ('error' in res) {
@@ -3997,8 +4001,10 @@ class Connection {
3997
4001
  */
3998
4002
 
3999
4003
 
4000
- async getConfirmedTransaction(signature) {
4001
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', [signature]);
4004
+ async getConfirmedTransaction(signature, commitment) {
4005
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
4006
+
4007
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
4002
4008
  const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
4003
4009
 
4004
4010
  if ('error' in res) {
@@ -4012,8 +4018,10 @@ class Connection {
4012
4018
  */
4013
4019
 
4014
4020
 
4015
- async getParsedConfirmedTransaction(signature) {
4016
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', [signature, 'jsonParsed']);
4021
+ async getParsedConfirmedTransaction(signature, commitment) {
4022
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
4023
+
4024
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
4017
4025
  const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
4018
4026
 
4019
4027
  if ('error' in res) {
@@ -4027,11 +4035,13 @@ class Connection {
4027
4035
  */
4028
4036
 
4029
4037
 
4030
- async getParsedConfirmedTransactions(signatures) {
4038
+ async getParsedConfirmedTransactions(signatures, commitment) {
4031
4039
  const batch = signatures.map(signature => {
4040
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
4041
+
4032
4042
  return {
4033
4043
  methodName: 'getConfirmedTransaction',
4034
- args: [signature, 'jsonParsed']
4044
+ args
4035
4045
  };
4036
4046
  });
4037
4047
  const unsafeRes = await this._rpcBatchRequest(batch);
@@ -4069,7 +4079,7 @@ class Connection {
4069
4079
  }
4070
4080
 
4071
4081
  try {
4072
- const block = await this.getConfirmedBlockSignatures(startSlot);
4082
+ const block = await this.getConfirmedBlockSignatures(startSlot, 'finalized');
4073
4083
 
4074
4084
  if (block.signatures.length > 0) {
4075
4085
  options.until = block.signatures[block.signatures.length - 1].toString();
@@ -4120,8 +4130,10 @@ class Connection {
4120
4130
  */
4121
4131
 
4122
4132
 
4123
- async getConfirmedSignaturesForAddress2(address, options) {
4124
- const unsafeRes = await this._rpcRequest('getConfirmedSignaturesForAddress2', [address.toBase58(), options]);
4133
+ async getConfirmedSignaturesForAddress2(address, options, commitment) {
4134
+ const args = this._buildArgsAtLeastConfirmed([address.toBase58()], commitment, undefined, options);
4135
+
4136
+ const unsafeRes = await this._rpcRequest('getConfirmedSignaturesForAddress2', args);
4125
4137
  const res = create(unsafeRes, GetConfirmedSignaturesForAddress2RpcResult);
4126
4138
 
4127
4139
  if ('error' in res) {
@@ -4831,6 +4843,20 @@ class Connection {
4831
4843
  */
4832
4844
 
4833
4845
 
4846
+ _buildArgsAtLeastConfirmed(args, override, encoding, extra) {
4847
+ const commitment = override || this._commitment;
4848
+
4849
+ if (commitment && !['confirmed', 'finalized'].includes(commitment)) {
4850
+ throw new Error('Using Connection with default commitment: `' + this._commitment + '`, but method requires at least `confirmed`');
4851
+ }
4852
+
4853
+ return this._buildArgs(args, override, encoding, extra);
4854
+ }
4855
+ /**
4856
+ * @internal
4857
+ */
4858
+
4859
+
4834
4860
  _wsOnSignatureNotification(notification) {
4835
4861
  const res = create(notification, SignatureNotificationResult);
4836
4862