@solana/web3.js 1.13.1 → 1.14.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
@@ -1040,6 +1040,43 @@ declare module "@solana/web3.js" {
1040
1040
  ...
1041
1041
  };
1042
1042
 
1043
+ /**
1044
+ * A processed transaction from the RPC API
1045
+ */
1046
+ declare export type TransactionResponse = {
1047
+ /**
1048
+ * The slot during which the transaction was processed
1049
+ */
1050
+ slot: number,
1051
+
1052
+ /**
1053
+ * The transaction
1054
+ */
1055
+ transaction: {
1056
+ /**
1057
+ * The transaction message
1058
+ */
1059
+ message: Message,
1060
+
1061
+ /**
1062
+ * The transaction signatures
1063
+ */
1064
+ signatures: string[],
1065
+ ...
1066
+ },
1067
+
1068
+ /**
1069
+ * Metadata produced from the transaction
1070
+ */
1071
+ meta: ConfirmedTransactionMeta | null,
1072
+
1073
+ /**
1074
+ * The unix timestamp of when the transaction was processed
1075
+ */
1076
+ blockTime?: number | null,
1077
+ ...
1078
+ };
1079
+
1043
1080
  /**
1044
1081
  * A confirmed transaction on the ledger
1045
1082
  */
@@ -1192,6 +1229,85 @@ declare module "@solana/web3.js" {
1192
1229
  ...
1193
1230
  };
1194
1231
 
1232
+ /**
1233
+ * A processed block fetched from the RPC API
1234
+ */
1235
+ declare export type BlockResponse = {
1236
+ /**
1237
+ * Blockhash of this block
1238
+ */
1239
+ blockhash: Blockhash,
1240
+
1241
+ /**
1242
+ * Blockhash of this block's parent
1243
+ */
1244
+ previousBlockhash: Blockhash,
1245
+
1246
+ /**
1247
+ * Slot index of this block's parent
1248
+ */
1249
+ parentSlot: number,
1250
+
1251
+ /**
1252
+ * Vector of transactions with status meta and original message
1253
+ */
1254
+ transactions: Array<{
1255
+ /**
1256
+ * The transaction
1257
+ */
1258
+ transaction: {
1259
+ /**
1260
+ * The transaction message
1261
+ */
1262
+ message: Message,
1263
+
1264
+ /**
1265
+ * The transaction signatures
1266
+ */
1267
+ signatures: string[],
1268
+ ...
1269
+ },
1270
+
1271
+ /**
1272
+ * Metadata produced from the transaction
1273
+ */
1274
+ meta: ConfirmedTransactionMeta | null,
1275
+ ...
1276
+ }>,
1277
+
1278
+ /**
1279
+ * Vector of block rewards
1280
+ */
1281
+ rewards?: Array<{
1282
+ /**
1283
+ * Public key of reward recipient
1284
+ */
1285
+ pubkey: string,
1286
+
1287
+ /**
1288
+ * Reward value in lamports
1289
+ */
1290
+ lamports: number,
1291
+
1292
+ /**
1293
+ * Account balance after reward is applied
1294
+ */
1295
+ postBalance: number | null,
1296
+
1297
+ /**
1298
+ * Type of reward received
1299
+ */
1300
+ rewardType: string | null,
1301
+ ...
1302
+ }>,
1303
+
1304
+ /**
1305
+ * The unix timestamp of when the block was processed
1306
+ */
1307
+ blockTime: number | null,
1308
+ ...
1309
+ };
1310
+
1195
1311
  /**
1196
1312
  * A ConfirmedBlock on the ledger
1197
1313
  */
@@ -2116,7 +2232,7 @@ account: AccountInfo<Buffer | ParsedAccountData>,...
2116
2232
 
2117
2233
  /**
2118
2234
  * Fetch the current total currency supply of the cluster in lamports
2119
- * @deprecated Deprecated since v1.2.8. Use `Connection.getSupply()` instead.
2235
+ * @deprecated Deprecated since v1.2.8. Please use {@link getSupply} instead.
2120
2236
  */
2121
2237
  getTotalSupply(commitment?: Commitment): Promise<number>;
2122
2238
 
@@ -2206,9 +2322,32 @@ feeCalculator: FeeCalculator,...
2206
2322
  */
2207
2323
  getVersion(): Promise<Version>;
2208
2324
 
2325
+ /**
2326
+ * Fetch a processed block from the cluster.
2327
+ */
2328
+ getBlock(
2329
+ slot: number,
2330
+ opts?: {
2331
+ commitment?: Finality,
2332
+ ...
2333
+ }
2334
+ ): Promise<BlockResponse | null>;
2335
+
2336
+ /**
2337
+ * Fetch a processed transaction from the cluster.
2338
+ */
2339
+ getTransaction(
2340
+ signature: string,
2341
+ opts?: {
2342
+ commitment?: Finality,
2343
+ ...
2344
+ }
2345
+ ): Promise<TransactionResponse | null>;
2346
+
2209
2347
  /**
2210
2348
  * Fetch a list of Transactions and transaction statuses from the cluster
2211
- * for a confirmed block
2349
+ * for a confirmed block.
2350
+ * @deprecated Deprecated since v1.13.0. Please use {@link getBlock} instead.
2212
2351
  */
2213
2352
  getConfirmedBlock(
2214
2353
  slot: number,
@@ -2250,7 +2389,7 @@ feeCalculator: FeeCalculator,...
2250
2389
  /**
2251
2390
  * Fetch a list of all the confirmed signatures for transactions involving an address
2252
2391
  * within a specified slot range. Max range allowed is 10,000 slots.
2253
- * @deprecated Deprecated since v1.3. Use `Connection.getConfirmedSignaturesForAddress2()` instead.
2392
+ * @deprecated Deprecated since v1.3. Please use {@link getConfirmedSignaturesForAddress2} instead.
2254
2393
  * @param address queried address
2255
2394
  * @param startSlot start slot, inclusive
2256
2395
  * @param endSlot end slot, inclusive
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.13.1",
3
+ "version": "1.14.1",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
package/src/connection.ts CHANGED
@@ -510,6 +510,25 @@ export type ConfirmedTransactionMeta = {
510
510
  err: TransactionError | null;
511
511
  };
512
512
 
513
+ /**
514
+ * A processed transaction from the RPC API
515
+ */
516
+ export type TransactionResponse = {
517
+ /** The slot during which the transaction was processed */
518
+ slot: number;
519
+ /** The transaction */
520
+ transaction: {
521
+ /** The transaction message */
522
+ message: Message;
523
+ /** The transaction signatures */
524
+ signatures: string[];
525
+ };
526
+ /** Metadata produced from the transaction */
527
+ meta: ConfirmedTransactionMeta | null;
528
+ /** The unix timestamp of when the transaction was processed */
529
+ blockTime?: number | null;
530
+ };
531
+
513
532
  /**
514
533
  * A confirmed transaction on the ledger
515
534
  */
@@ -596,6 +615,43 @@ export type ParsedConfirmedTransaction = {
596
615
  blockTime?: number | null;
597
616
  };
598
617
 
618
+ /**
619
+ * A processed block fetched from the RPC API
620
+ */
621
+ export type BlockResponse = {
622
+ /** Blockhash of this block */
623
+ blockhash: Blockhash;
624
+ /** Blockhash of this block's parent */
625
+ previousBlockhash: Blockhash;
626
+ /** Slot index of this block's parent */
627
+ parentSlot: number;
628
+ /** Vector of transactions with status meta and original message */
629
+ transactions: Array<{
630
+ /** The transaction */
631
+ transaction: {
632
+ /** The transaction message */
633
+ message: Message;
634
+ /** The transaction signatures */
635
+ signatures: string[];
636
+ };
637
+ /** Metadata produced from the transaction */
638
+ meta: ConfirmedTransactionMeta | null;
639
+ }>;
640
+ /** Vector of block rewards */
641
+ rewards?: Array<{
642
+ /** Public key of reward recipient */
643
+ pubkey: string;
644
+ /** Reward value in lamports */
645
+ lamports: number;
646
+ /** Account balance after reward is applied */
647
+ postBalance: number | null;
648
+ /** Type of reward received */
649
+ rewardType: string | null;
650
+ }>;
651
+ /** The unix timestamp of when the block was processed */
652
+ blockTime: number | null;
653
+ };
654
+
599
655
  /**
600
656
  * A ConfirmedBlock on the ledger
601
657
  */
@@ -1234,9 +1290,6 @@ const GetSignatureStatusesRpcResult = jsonRpcResultAndContext(
1234
1290
  */
1235
1291
  const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult(number());
1236
1292
 
1237
- /**
1238
- * @internal
1239
- */
1240
1293
  const ConfirmedTransactionResult = pick({
1241
1294
  signatures: array(string()),
1242
1295
  message: pick({
@@ -1257,15 +1310,6 @@ const ConfirmedTransactionResult = pick({
1257
1310
  }),
1258
1311
  });
1259
1312
 
1260
- const TransactionFromConfirmed = coerce(
1261
- instance(Transaction),
1262
- ConfirmedTransactionResult,
1263
- result => {
1264
- const {message, signatures} = result;
1265
- return Transaction.populate(new Message(message), signatures);
1266
- },
1267
- );
1268
-
1269
1313
  const ParsedInstructionResult = pick({
1270
1314
  parsed: unknown(),
1271
1315
  program: string(),
@@ -1395,7 +1439,7 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(
1395
1439
  parentSlot: number(),
1396
1440
  transactions: array(
1397
1441
  pick({
1398
- transaction: TransactionFromConfirmed,
1442
+ transaction: ConfirmedTransactionResult,
1399
1443
  meta: nullable(ConfirmedTransactionMetaResult),
1400
1444
  }),
1401
1445
  ),
@@ -1436,9 +1480,9 @@ const GetConfirmedTransactionRpcResult = jsonRpcResult(
1436
1480
  nullable(
1437
1481
  pick({
1438
1482
  slot: number(),
1439
- transaction: TransactionFromConfirmed,
1440
1483
  meta: ConfirmedTransactionMetaResult,
1441
1484
  blockTime: optional(nullable(number())),
1485
+ transaction: ConfirmedTransactionResult,
1442
1486
  }),
1443
1487
  ),
1444
1488
  );
@@ -2668,7 +2712,8 @@ export class Connection {
2668
2712
 
2669
2713
  /**
2670
2714
  * Fetch the current total currency supply of the cluster in lamports
2671
- * @deprecated Deprecated since v1.2.8. Use `Connection.getSupply()` instead.
2715
+ *
2716
+ * @deprecated Deprecated since v1.2.8. Please use {@link getSupply} instead.
2672
2717
  */
2673
2718
  async getTotalSupply(commitment?: Commitment): Promise<number> {
2674
2719
  const args = this._buildArgs([], commitment);
@@ -2870,24 +2915,99 @@ export class Connection {
2870
2915
  }
2871
2916
 
2872
2917
  /**
2873
- * Fetch a list of Transactions and transaction statuses from the cluster
2874
- * for a confirmed block
2918
+ * Fetch a processed block from the cluster.
2875
2919
  */
2876
- async getConfirmedBlock(
2920
+ async getBlock(
2877
2921
  slot: number,
2878
- commitment?: Finality,
2879
- ): Promise<ConfirmedBlock> {
2880
- const args = this._buildArgsAtLeastConfirmed([slot], commitment);
2922
+ opts?: {commitment?: Finality},
2923
+ ): Promise<BlockResponse | null> {
2924
+ const args = this._buildArgsAtLeastConfirmed(
2925
+ [slot],
2926
+ opts && opts.commitment,
2927
+ );
2881
2928
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
2882
2929
  const res = create(unsafeRes, GetConfirmedBlockRpcResult);
2930
+
2883
2931
  if ('error' in res) {
2884
2932
  throw new Error('failed to get confirmed block: ' + res.error.message);
2885
2933
  }
2934
+
2935
+ const result = res.result;
2936
+ if (!result) return result;
2937
+
2938
+ return {
2939
+ ...result,
2940
+ transactions: result.transactions.map(({transaction, meta}) => {
2941
+ const message = new Message(transaction.message);
2942
+ return {
2943
+ meta,
2944
+ transaction: {
2945
+ ...transaction,
2946
+ message,
2947
+ },
2948
+ };
2949
+ }),
2950
+ };
2951
+ }
2952
+
2953
+ /**
2954
+ * Fetch a processed transaction from the cluster.
2955
+ */
2956
+ async getTransaction(
2957
+ signature: string,
2958
+ opts?: {commitment?: Finality},
2959
+ ): Promise<TransactionResponse | null> {
2960
+ const args = this._buildArgsAtLeastConfirmed(
2961
+ [signature],
2962
+ opts && opts.commitment,
2963
+ );
2964
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
2965
+ const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
2966
+ if ('error' in res) {
2967
+ throw new Error(
2968
+ 'failed to get confirmed transaction: ' + res.error.message,
2969
+ );
2970
+ }
2971
+
2886
2972
  const result = res.result;
2973
+ if (!result) return result;
2974
+
2975
+ return {
2976
+ ...result,
2977
+ transaction: {
2978
+ ...result.transaction,
2979
+ message: new Message(result.transaction.message),
2980
+ },
2981
+ };
2982
+ }
2983
+
2984
+ /**
2985
+ * Fetch a list of Transactions and transaction statuses from the cluster
2986
+ * for a confirmed block.
2987
+ *
2988
+ * @deprecated Deprecated since v1.13.0. Please use {@link getBlock} instead.
2989
+ */
2990
+ async getConfirmedBlock(
2991
+ slot: number,
2992
+ commitment?: Finality,
2993
+ ): Promise<ConfirmedBlock> {
2994
+ const result = await this.getBlock(slot, {commitment});
2887
2995
  if (!result) {
2888
2996
  throw new Error('Confirmed block ' + slot + ' not found');
2889
2997
  }
2890
- return result;
2998
+
2999
+ return {
3000
+ ...result,
3001
+ transactions: result.transactions.map(({transaction, meta}) => {
3002
+ return {
3003
+ meta,
3004
+ transaction: Transaction.populate(
3005
+ transaction.message,
3006
+ transaction.signatures,
3007
+ ),
3008
+ };
3009
+ }),
3010
+ };
2891
3011
  }
2892
3012
 
2893
3013
  /**
@@ -2925,15 +3045,13 @@ export class Connection {
2925
3045
  signature: TransactionSignature,
2926
3046
  commitment?: Finality,
2927
3047
  ): Promise<ConfirmedTransaction | null> {
2928
- const args = this._buildArgsAtLeastConfirmed([signature], commitment);
2929
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
2930
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
2931
- if ('error' in res) {
2932
- throw new Error(
2933
- 'failed to get confirmed transaction: ' + res.error.message,
2934
- );
2935
- }
2936
- return res.result;
3048
+ const result = await this.getTransaction(signature, {commitment});
3049
+ if (!result) return result;
3050
+ const {message, signatures} = result.transaction;
3051
+ return {
3052
+ ...result,
3053
+ transaction: Transaction.populate(message, signatures),
3054
+ };
2937
3055
  }
2938
3056
 
2939
3057
  /**
@@ -2994,7 +3112,8 @@ export class Connection {
2994
3112
  /**
2995
3113
  * Fetch a list of all the confirmed signatures for transactions involving an address
2996
3114
  * within a specified slot range. Max range allowed is 10,000 slots.
2997
- * @deprecated Deprecated since v1.3. Use `Connection.getConfirmedSignaturesForAddress2()` instead.
3115
+ *
3116
+ * @deprecated Deprecated since v1.3. Please use {@link getConfirmedSignaturesForAddress2} instead.
2998
3117
  *
2999
3118
  * @param address queried address
3000
3119
  * @param startSlot start slot, inclusive