@solana/web3.js 1.2.8 → 1.3.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
@@ -730,6 +730,21 @@ declare module '@solana/web3.js' {
730
730
  /** The unix timestamp of when the block was processed */
731
731
  blockTime: number | null;
732
732
  };
733
+ /**
734
+ * A ConfirmedBlock on the ledger with signatures only
735
+ */
736
+ export type ConfirmedBlockSignatures = {
737
+ /** Blockhash of this block */
738
+ blockhash: Blockhash;
739
+ /** Blockhash of this block's parent */
740
+ previousBlockhash: Blockhash;
741
+ /** Slot index of this block's parent */
742
+ parentSlot: number;
743
+ /** Vector of signatures */
744
+ signatures: Array<string>;
745
+ /** The unix timestamp of when the block was processed */
746
+ blockTime: number | null;
747
+ };
733
748
  /**
734
749
  * A performance sample
735
750
  */
@@ -1174,6 +1189,7 @@ declare module '@solana/web3.js' {
1174
1189
  getTransactionCount(commitment?: Commitment): Promise<number>;
1175
1190
  /**
1176
1191
  * Fetch the current total currency supply of the cluster in lamports
1192
+ * @deprecated Deprecated since v1.2.8. Use `Connection.getSupply()` instead.
1177
1193
  */
1178
1194
  getTotalSupply(commitment?: Commitment): Promise<number>;
1179
1195
  /**
@@ -1244,6 +1260,12 @@ declare module '@solana/web3.js' {
1244
1260
  * for a confirmed block
1245
1261
  */
1246
1262
  getConfirmedBlock(slot: number): Promise<ConfirmedBlock>;
1263
+ /**
1264
+ * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
1265
+ */
1266
+ getConfirmedBlockSignatures(
1267
+ slot: number,
1268
+ ): Promise<ConfirmedBlockSignatures>;
1247
1269
  /**
1248
1270
  * Fetch a transaction details for a confirmed transaction
1249
1271
  */
@@ -1265,6 +1287,7 @@ declare module '@solana/web3.js' {
1265
1287
  /**
1266
1288
  * Fetch a list of all the confirmed signatures for transactions involving an address
1267
1289
  * within a specified slot range. Max range allowed is 10,000 slots.
1290
+ * @deprecated Deprecated since v1.3. Use `Connection.getConfirmedSignaturesForAddress2()` instead.
1268
1291
  *
1269
1292
  * @param address queried address
1270
1293
  * @param startSlot start slot, inclusive
package/lib/index.esm.js CHANGED
@@ -2704,11 +2704,6 @@ const StakeActivationResult = type({
2704
2704
  active: number(),
2705
2705
  inactive: number()
2706
2706
  });
2707
- /**
2708
- * Expected JSON RPC response for the "getConfirmedSignaturesForAddress" message
2709
- */
2710
-
2711
- const GetConfirmedSignaturesForAddressRpcResult = jsonRpcResult(array(string()));
2712
2707
  /**
2713
2708
  * Expected JSON RPC response for the "getConfirmedSignaturesForAddress2" message
2714
2709
  */
@@ -2953,6 +2948,17 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
2953
2948
  }))),
2954
2949
  blockTime: nullable(number())
2955
2950
  })));
2951
+ /**
2952
+ * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
2953
+ */
2954
+
2955
+ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
2956
+ blockhash: string(),
2957
+ previousBlockhash: string(),
2958
+ parentSlot: number(),
2959
+ signatures: array(string()),
2960
+ blockTime: nullable(number())
2961
+ })));
2956
2962
  /**
2957
2963
  * Expected JSON RPC response for the "getConfirmedTransaction" message
2958
2964
  */
@@ -3715,20 +3721,21 @@ class Connection {
3715
3721
  }
3716
3722
  /**
3717
3723
  * Fetch the current total currency supply of the cluster in lamports
3724
+ * @deprecated Deprecated since v1.2.8. Use `Connection.getSupply()` instead.
3718
3725
  */
3719
3726
 
3720
3727
 
3721
3728
  async getTotalSupply(commitment) {
3722
3729
  const args = this._buildArgs([], commitment);
3723
3730
 
3724
- const unsafeRes = await this._rpcRequest('getTotalSupply', args);
3725
- const res = create(unsafeRes, jsonRpcResult(number()));
3731
+ const unsafeRes = await this._rpcRequest('getSupply', args);
3732
+ const res = create(unsafeRes, GetSupplyRpcResult);
3726
3733
 
3727
3734
  if ('error' in res) {
3728
3735
  throw new Error('failed to get total supply: ' + res.error.message);
3729
3736
  }
3730
3737
 
3731
- return res.result;
3738
+ return res.result.value.total;
3732
3739
  }
3733
3740
  /**
3734
3741
  * Fetch the cluster InflationGovernor parameters
@@ -3925,6 +3932,30 @@ class Connection {
3925
3932
 
3926
3933
  return result;
3927
3934
  }
3935
+ /**
3936
+ * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
3937
+ */
3938
+
3939
+
3940
+ async getConfirmedBlockSignatures(slot) {
3941
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', [slot, {
3942
+ transactionDetails: 'signatures',
3943
+ rewards: false
3944
+ }]);
3945
+ const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
3946
+
3947
+ if ('error' in res) {
3948
+ throw new Error('failed to get confirmed block: ' + res.error.message);
3949
+ }
3950
+
3951
+ const result = res.result;
3952
+
3953
+ if (!result) {
3954
+ throw new Error('Confirmed block ' + slot + ' not found');
3955
+ }
3956
+
3957
+ return result;
3958
+ }
3928
3959
  /**
3929
3960
  * Fetch a transaction details for a confirmed transaction
3930
3961
  */
@@ -3982,6 +4013,7 @@ class Connection {
3982
4013
  /**
3983
4014
  * Fetch a list of all the confirmed signatures for transactions involving an address
3984
4015
  * within a specified slot range. Max range allowed is 10,000 slots.
4016
+ * @deprecated Deprecated since v1.3. Use `Connection.getConfirmedSignaturesForAddress2()` instead.
3985
4017
  *
3986
4018
  * @param address queried address
3987
4019
  * @param startSlot start slot, inclusive
@@ -3990,14 +4022,57 @@ class Connection {
3990
4022
 
3991
4023
 
3992
4024
  async getConfirmedSignaturesForAddress(address, startSlot, endSlot) {
3993
- const unsafeRes = await this._rpcRequest('getConfirmedSignaturesForAddress', [address.toBase58(), startSlot, endSlot]);
3994
- const res = create(unsafeRes, GetConfirmedSignaturesForAddressRpcResult);
4025
+ let options = {};
4026
+ let firstAvailableBlock = await this.getFirstAvailableBlock();
3995
4027
 
3996
- if ('error' in res) {
3997
- throw new Error('failed to get confirmed signatures for address: ' + res.error.message);
4028
+ while (!('until' in options)) {
4029
+ startSlot--;
4030
+
4031
+ if (startSlot <= 0 || startSlot < firstAvailableBlock) {
4032
+ break;
4033
+ }
4034
+
4035
+ try {
4036
+ const block = await this.getConfirmedBlockSignatures(startSlot);
4037
+
4038
+ if (block.signatures.length > 0) {
4039
+ options.until = block.signatures[block.signatures.length - 1].toString();
4040
+ }
4041
+ } catch (err) {
4042
+ if (err.message.includes('skipped')) {
4043
+ continue;
4044
+ } else {
4045
+ throw err;
4046
+ }
4047
+ }
3998
4048
  }
3999
4049
 
4000
- return res.result;
4050
+ let highestConfirmedRoot = await this.getSlot('finalized');
4051
+
4052
+ while (!('before' in options)) {
4053
+ endSlot++;
4054
+
4055
+ if (endSlot > highestConfirmedRoot) {
4056
+ break;
4057
+ }
4058
+
4059
+ try {
4060
+ const block = await this.getConfirmedBlockSignatures(endSlot);
4061
+
4062
+ if (block.signatures.length > 0) {
4063
+ options.before = block.signatures[block.signatures.length - 1].toString();
4064
+ }
4065
+ } catch (err) {
4066
+ if (err.message.includes('skipped')) {
4067
+ continue;
4068
+ } else {
4069
+ throw err;
4070
+ }
4071
+ }
4072
+ }
4073
+
4074
+ const confirmedSignatureInfo = await this.getConfirmedSignaturesForAddress2(address, options);
4075
+ return confirmedSignatureInfo.map(info => info.signature);
4001
4076
  }
4002
4077
  /**
4003
4078
  * Returns confirmed signatures for transactions involving an