@solana/web3.js 1.41.9 → 1.43.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.
@@ -1,6 +1,9 @@
1
1
  import type {Buffer} from 'buffer';
2
2
 
3
- import {Connection} from '../connection';
3
+ import {
4
+ BlockheightBasedTransactionConfirmationStrategy,
5
+ Connection,
6
+ } from '../connection';
4
7
  import type {TransactionSignature} from '../transaction';
5
8
  import type {ConfirmOptions} from '../connection';
6
9
 
@@ -11,14 +14,57 @@ import type {ConfirmOptions} from '../connection';
11
14
  *
12
15
  * @param {Connection} connection
13
16
  * @param {Buffer} rawTransaction
17
+ * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
14
18
  * @param {ConfirmOptions} [options]
15
19
  * @returns {Promise<TransactionSignature>}
16
20
  */
17
21
  export async function sendAndConfirmRawTransaction(
18
22
  connection: Connection,
19
23
  rawTransaction: Buffer,
24
+ confirmationStrategy: BlockheightBasedTransactionConfirmationStrategy,
20
25
  options?: ConfirmOptions,
26
+ ): Promise<TransactionSignature>;
27
+
28
+ /**
29
+ * @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
30
+ * is no longer supported and will be removed in a future version.
31
+ */
32
+ // eslint-disable-next-line no-redeclare
33
+ export async function sendAndConfirmRawTransaction(
34
+ connection: Connection,
35
+ rawTransaction: Buffer,
36
+ options?: ConfirmOptions,
37
+ ): Promise<TransactionSignature>;
38
+
39
+ // eslint-disable-next-line no-redeclare
40
+ export async function sendAndConfirmRawTransaction(
41
+ connection: Connection,
42
+ rawTransaction: Buffer,
43
+ confirmationStrategyOrConfirmOptions:
44
+ | BlockheightBasedTransactionConfirmationStrategy
45
+ | ConfirmOptions
46
+ | undefined,
47
+ maybeConfirmOptions?: ConfirmOptions,
21
48
  ): Promise<TransactionSignature> {
49
+ let confirmationStrategy:
50
+ | BlockheightBasedTransactionConfirmationStrategy
51
+ | undefined;
52
+ let options: ConfirmOptions | undefined;
53
+ if (
54
+ confirmationStrategyOrConfirmOptions &&
55
+ Object.prototype.hasOwnProperty.call(
56
+ confirmationStrategyOrConfirmOptions,
57
+ 'lastValidBlockHeight',
58
+ )
59
+ ) {
60
+ confirmationStrategy =
61
+ confirmationStrategyOrConfirmOptions as BlockheightBasedTransactionConfirmationStrategy;
62
+ options = maybeConfirmOptions;
63
+ } else {
64
+ options = confirmationStrategyOrConfirmOptions as
65
+ | ConfirmOptions
66
+ | undefined;
67
+ }
22
68
  const sendOptions = options && {
23
69
  skipPreflight: options.skipPreflight,
24
70
  preflightCommitment: options.preflightCommitment || options.commitment,
@@ -29,12 +75,11 @@ export async function sendAndConfirmRawTransaction(
29
75
  sendOptions,
30
76
  );
31
77
 
32
- const status = (
33
- await connection.confirmTransaction(
34
- signature,
35
- options && options.commitment,
36
- )
37
- ).value;
78
+ const commitment = options && options.commitment;
79
+ const confirmationPromise = confirmationStrategy
80
+ ? connection.confirmTransaction(confirmationStrategy, commitment)
81
+ : connection.confirmTransaction(signature, commitment);
82
+ const status = (await confirmationPromise).value;
38
83
 
39
84
  if (status.err) {
40
85
  throw new Error(
@@ -33,12 +33,25 @@ export async function sendAndConfirmTransaction(
33
33
  sendOptions,
34
34
  );
35
35
 
36
- const status = (
37
- await connection.confirmTransaction(
38
- signature,
39
- options && options.commitment,
40
- )
41
- ).value;
36
+ const status =
37
+ transaction.recentBlockhash != null &&
38
+ transaction.lastValidBlockHeight != null
39
+ ? (
40
+ await connection.confirmTransaction(
41
+ {
42
+ signature: signature,
43
+ blockhash: transaction.recentBlockhash,
44
+ lastValidBlockHeight: transaction.lastValidBlockHeight,
45
+ },
46
+ options && options.commitment,
47
+ )
48
+ ).value
49
+ : (
50
+ await connection.confirmTransaction(
51
+ signature,
52
+ options && options.commitment,
53
+ )
54
+ ).value;
42
55
 
43
56
  if (status.err) {
44
57
  throw new Error(
@@ -0,0 +1,35 @@
1
+ export class TransactionExpiredBlockheightExceededError extends Error {
2
+ signature: string;
3
+
4
+ constructor(signature: string) {
5
+ super(`Signature ${signature} has expired: block height exceeded.`);
6
+ this.signature = signature;
7
+ }
8
+ }
9
+
10
+ Object.defineProperty(
11
+ TransactionExpiredBlockheightExceededError.prototype,
12
+ 'name',
13
+ {
14
+ value: 'TransactionExpiredBlockheightExceededError',
15
+ },
16
+ );
17
+
18
+ export class TransactionExpiredTimeoutError extends Error {
19
+ signature: string;
20
+
21
+ constructor(signature: string, timeoutSeconds: number) {
22
+ super(
23
+ `Transaction was not confirmed in ${timeoutSeconds.toFixed(
24
+ 2,
25
+ )} seconds. It is ` +
26
+ 'unknown if it succeeded or failed. Check signature ' +
27
+ `${signature} using the Solana Explorer or CLI tools.`,
28
+ );
29
+ this.signature = signature;
30
+ }
31
+ }
32
+
33
+ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
34
+ value: 'TransactionExpiredTimeoutError',
35
+ });