@solana/web3.js 2.0.0-experimental.a8f1f88 → 2.0.0-experimental.a9e6db3

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.
@@ -5,14 +5,161 @@ var instructions = require('@solana/instructions');
5
5
  var keys = require('@solana/keys');
6
6
  var transactions = require('@solana/transactions');
7
7
  var rpcCore = require('@solana/rpc-core');
8
+ var functional = require('@solana/functional');
8
9
  var rpcTransport = require('@solana/rpc-transport');
9
10
  var fastStableStringify = require('fast-stable-stringify');
11
+ var umiSerializers = require('@metaplex-foundation/umi-serializers');
10
12
 
11
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
14
 
13
15
  var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableStringify);
14
16
 
15
- // src/index.ts
17
+ // ../build-scripts/env-shim.ts
18
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
19
+
20
+ // src/transaction-confirmation-strategy-racer.ts
21
+ async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
22
+ const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
23
+ callerAbortSignal.throwIfAborted();
24
+ const abortController = new AbortController();
25
+ function handleAbort() {
26
+ abortController.abort();
27
+ }
28
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
29
+ try {
30
+ const specificStrategies = getSpecificStrategiesForRace({
31
+ ...config,
32
+ abortSignal: abortController.signal
33
+ });
34
+ return await Promise.race([
35
+ getRecentSignatureConfirmationPromise({
36
+ abortSignal: abortController.signal,
37
+ commitment,
38
+ signature
39
+ }),
40
+ ...specificStrategies
41
+ ]);
42
+ } finally {
43
+ abortController.abort();
44
+ }
45
+ }
46
+ function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
47
+ return async function getRecentSignatureConfirmationPromise({
48
+ abortSignal: callerAbortSignal,
49
+ commitment,
50
+ signature
51
+ }) {
52
+ const abortController = new AbortController();
53
+ function handleAbort() {
54
+ abortController.abort();
55
+ }
56
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
57
+ const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
58
+ const signatureDidCommitPromise = (async () => {
59
+ for await (const signatureStatusNotification of signatureStatusNotifications) {
60
+ if (signatureStatusNotification.value.err) {
61
+ throw new Error(`The transaction with signature \`${signature}\` failed.`, {
62
+ cause: signatureStatusNotification.value.err
63
+ });
64
+ } else {
65
+ return;
66
+ }
67
+ }
68
+ })();
69
+ const signatureStatusLookupPromise = (async () => {
70
+ const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
71
+ const signatureStatus = signatureStatusResults[0];
72
+ if (signatureStatus && signatureStatus.confirmationStatus && rpcCore.commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
73
+ return;
74
+ } else {
75
+ await new Promise(() => {
76
+ });
77
+ }
78
+ })();
79
+ try {
80
+ return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
81
+ } finally {
82
+ abortController.abort();
83
+ }
84
+ };
85
+ }
86
+
87
+ // src/transaction-confirmation-strategy-timeout.ts
88
+ async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
89
+ return await new Promise((_, reject) => {
90
+ const handleAbort = (e) => {
91
+ clearTimeout(timeoutId);
92
+ const abortError = new DOMException(e.target.reason, "AbortError");
93
+ reject(abortError);
94
+ };
95
+ callerAbortSignal.addEventListener("abort", handleAbort);
96
+ const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
97
+ const startMs = performance.now();
98
+ const timeoutId = (
99
+ // We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
100
+ // elapsed time instead of active time.
101
+ // See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
102
+ setTimeout(() => {
103
+ const elapsedMs = performance.now() - startMs;
104
+ reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
105
+ }, timeoutMs)
106
+ );
107
+ });
108
+ }
109
+
110
+ // src/airdrop-confirmer.ts
111
+ function createDefaultSignatureOnlyRecentTransactionConfirmer({
112
+ rpc,
113
+ rpcSubscriptions
114
+ }) {
115
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
116
+ rpc,
117
+ rpcSubscriptions
118
+ );
119
+ return async function confirmSignatureOnlyRecentTransaction(config) {
120
+ await waitForRecentTransactionConfirmationUntilTimeout({
121
+ ...config,
122
+ getRecentSignatureConfirmationPromise,
123
+ getTimeoutPromise
124
+ });
125
+ };
126
+ }
127
+ async function waitForRecentTransactionConfirmationUntilTimeout(config) {
128
+ await raceStrategies(
129
+ config.signature,
130
+ config,
131
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
132
+ return [
133
+ getTimeoutPromise2({
134
+ abortSignal,
135
+ commitment
136
+ })
137
+ ];
138
+ }
139
+ );
140
+ }
141
+
142
+ // src/airdrop.ts
143
+ async function requestAndConfirmAirdrop({
144
+ abortSignal,
145
+ commitment,
146
+ lamports,
147
+ recipientAddress,
148
+ rpc,
149
+ rpcSubscriptions
150
+ }) {
151
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
152
+ const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
153
+ rpc,
154
+ rpcSubscriptions
155
+ });
156
+ await confirmSignatureOnlyTransaction({
157
+ abortSignal,
158
+ commitment,
159
+ signature: airdropTransactionSignature
160
+ });
161
+ return airdropTransactionSignature;
162
+ }
16
163
 
17
164
  // src/rpc-integer-overflow-error.ts
18
165
  var SolanaJsonRpcIntegerOverflowError = class extends Error {
@@ -50,6 +197,193 @@ var DEFAULT_RPC_CONFIG = {
50
197
  }
51
198
  };
52
199
 
200
+ // src/cached-abortable-iterable.ts
201
+ function registerIterableCleanup(iterable, cleanupFn) {
202
+ (async () => {
203
+ try {
204
+ for await (const _ of iterable)
205
+ ;
206
+ } catch {
207
+ } finally {
208
+ cleanupFn();
209
+ }
210
+ })();
211
+ }
212
+ function getCachedAbortableIterableFactory({
213
+ getAbortSignalFromInputArgs,
214
+ getCacheEntryMissingError,
215
+ getCacheKeyFromInputArgs,
216
+ onCacheHit,
217
+ onCreateIterable
218
+ }) {
219
+ const cache = /* @__PURE__ */ new Map();
220
+ function getCacheEntryOrThrow(cacheKey) {
221
+ const currentCacheEntry = cache.get(cacheKey);
222
+ if (!currentCacheEntry) {
223
+ throw getCacheEntryMissingError(cacheKey);
224
+ }
225
+ return currentCacheEntry;
226
+ }
227
+ return async (...args) => {
228
+ const cacheKey = getCacheKeyFromInputArgs(...args);
229
+ const signal = getAbortSignalFromInputArgs(...args);
230
+ if (cacheKey === void 0) {
231
+ return await onCreateIterable(signal, ...args);
232
+ }
233
+ const cleanup = () => {
234
+ cache.delete(cacheKey);
235
+ signal.removeEventListener("abort", handleAbort);
236
+ };
237
+ const handleAbort = () => {
238
+ const cacheEntry = getCacheEntryOrThrow(cacheKey);
239
+ if (cacheEntry.purgeScheduled !== true) {
240
+ cacheEntry.purgeScheduled = true;
241
+ globalThis.queueMicrotask(() => {
242
+ cacheEntry.purgeScheduled = false;
243
+ if (cacheEntry.referenceCount === 0) {
244
+ cacheEntry.abortController.abort();
245
+ cleanup();
246
+ }
247
+ });
248
+ }
249
+ cacheEntry.referenceCount--;
250
+ };
251
+ signal.addEventListener("abort", handleAbort);
252
+ try {
253
+ const cacheEntry = cache.get(cacheKey);
254
+ if (!cacheEntry) {
255
+ const singletonAbortController = new AbortController();
256
+ const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
257
+ const newCacheEntry = {
258
+ abortController: singletonAbortController,
259
+ iterable: newIterablePromise,
260
+ purgeScheduled: false,
261
+ referenceCount: 1
262
+ };
263
+ cache.set(cacheKey, newCacheEntry);
264
+ const newIterable = await newIterablePromise;
265
+ registerIterableCleanup(newIterable, cleanup);
266
+ newCacheEntry.iterable = newIterable;
267
+ return newIterable;
268
+ } else {
269
+ cacheEntry.referenceCount++;
270
+ const iterableOrIterablePromise = cacheEntry.iterable;
271
+ const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
272
+ await onCacheHit(cachedIterable, ...args);
273
+ return cachedIterable;
274
+ }
275
+ } catch (e) {
276
+ cleanup();
277
+ throw e;
278
+ }
279
+ };
280
+ }
281
+
282
+ // src/rpc-subscription-coalescer.ts
283
+ var EXPLICIT_ABORT_TOKEN = Symbol(
284
+ __DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
285
+ );
286
+ function registerIterableCleanup2(iterable, cleanupFn) {
287
+ (async () => {
288
+ try {
289
+ for await (const _ of iterable)
290
+ ;
291
+ } catch {
292
+ } finally {
293
+ cleanupFn();
294
+ }
295
+ })();
296
+ }
297
+ function getRpcSubscriptionsWithSubscriptionCoalescing({
298
+ getDeduplicationKey,
299
+ rpcSubscriptions
300
+ }) {
301
+ const cache = /* @__PURE__ */ new Map();
302
+ return new Proxy(rpcSubscriptions, {
303
+ defineProperty() {
304
+ return false;
305
+ },
306
+ deleteProperty() {
307
+ return false;
308
+ },
309
+ get(target, p, receiver) {
310
+ const subscriptionMethod = Reflect.get(target, p, receiver);
311
+ if (typeof subscriptionMethod !== "function") {
312
+ return subscriptionMethod;
313
+ }
314
+ return function(...rawParams) {
315
+ const deduplicationKey = getDeduplicationKey(p, rawParams);
316
+ if (deduplicationKey === void 0) {
317
+ return subscriptionMethod(...rawParams);
318
+ }
319
+ if (cache.has(deduplicationKey)) {
320
+ return cache.get(deduplicationKey);
321
+ }
322
+ const iterableFactory = getCachedAbortableIterableFactory({
323
+ getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
324
+ getCacheEntryMissingError(deduplicationKey2) {
325
+ return new Error(
326
+ `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
327
+ );
328
+ },
329
+ getCacheKeyFromInputArgs: () => deduplicationKey,
330
+ async onCacheHit(_iterable, _config) {
331
+ },
332
+ async onCreateIterable(abortSignal, config) {
333
+ const pendingSubscription2 = subscriptionMethod(
334
+ ...rawParams
335
+ );
336
+ const iterable = await pendingSubscription2.subscribe({
337
+ ...config,
338
+ abortSignal
339
+ });
340
+ registerIterableCleanup2(iterable, () => {
341
+ cache.delete(deduplicationKey);
342
+ });
343
+ return iterable;
344
+ }
345
+ });
346
+ const pendingSubscription = {
347
+ async subscribe(...args) {
348
+ const iterable = await iterableFactory(...args);
349
+ const { abortSignal } = args[0];
350
+ let abortPromise;
351
+ return {
352
+ ...iterable,
353
+ async *[Symbol.asyncIterator]() {
354
+ abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
355
+ abortSignal.addEventListener("abort", () => {
356
+ reject(EXPLICIT_ABORT_TOKEN);
357
+ });
358
+ }));
359
+ try {
360
+ const iterator = iterable[Symbol.asyncIterator]();
361
+ while (true) {
362
+ const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
363
+ if (iteratorResult.done) {
364
+ return;
365
+ } else {
366
+ yield iteratorResult.value;
367
+ }
368
+ }
369
+ } catch (e) {
370
+ if (e === EXPLICIT_ABORT_TOKEN) {
371
+ return;
372
+ }
373
+ cache.delete(deduplicationKey);
374
+ throw e;
375
+ }
376
+ }
377
+ };
378
+ }
379
+ };
380
+ cache.set(deduplicationKey, pendingSubscription);
381
+ return pendingSubscription;
382
+ };
383
+ }
384
+ });
385
+ }
386
+
53
387
  // src/rpc.ts
54
388
  function createSolanaRpc(config) {
55
389
  return rpcTransport.createJsonRpc({
@@ -58,9 +392,21 @@ function createSolanaRpc(config) {
58
392
  });
59
393
  }
60
394
  function createSolanaRpcSubscriptions(config) {
395
+ return functional.pipe(
396
+ rpcTransport.createJsonSubscriptionRpc({
397
+ ...config,
398
+ api: rpcCore.createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
399
+ }),
400
+ (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
401
+ getDeduplicationKey: (...args) => fastStableStringify__default.default(args),
402
+ rpcSubscriptions
403
+ })
404
+ );
405
+ }
406
+ function createSolanaRpcSubscriptions_UNSTABLE(config) {
61
407
  return rpcTransport.createJsonSubscriptionRpc({
62
408
  ...config,
63
- api: rpcCore.createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
409
+ api: rpcCore.createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
64
410
  });
65
411
  }
66
412
 
@@ -115,13 +461,14 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
115
461
  }
116
462
  };
117
463
  }
118
- function getSolanaRpcPayloadDeduplicationKey(payload) {
464
+ function isJsonRpcPayload(payload) {
119
465
  if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
120
- return;
121
- }
122
- if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
123
- return fastStableStringify__default.default([payload.method, payload.params]);
466
+ return false;
124
467
  }
468
+ return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
469
+ }
470
+ function getSolanaRpcPayloadDeduplicationKey(payload) {
471
+ return isJsonRpcPayload(payload) ? fastStableStringify__default.default([payload.method, payload.params]) : void 0;
125
472
  }
126
473
 
127
474
  // src/rpc-transport.ts
@@ -133,7 +480,7 @@ function normalizeHeaders(headers) {
133
480
  return out;
134
481
  }
135
482
  function createDefaultRpcTransport(config) {
136
- return getRpcTransportWithRequestCoalescing(
483
+ return functional.pipe(
137
484
  rpcTransport.createHttpTransport({
138
485
  ...config,
139
486
  headers: {
@@ -144,7 +491,7 @@ function createDefaultRpcTransport(config) {
144
491
  }
145
492
  }
146
493
  }),
147
- getSolanaRpcPayloadDeduplicationKey
494
+ (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
148
495
  );
149
496
  }
150
497
 
@@ -158,11 +505,12 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
158
505
  return async (...args) => {
159
506
  const connection = await transport(...args);
160
507
  let intervalId;
508
+ function sendPing() {
509
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
510
+ }
161
511
  function restartPingTimer() {
162
512
  clearInterval(intervalId);
163
- intervalId = setInterval(() => {
164
- connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
165
- }, intervalMs);
513
+ intervalId = setInterval(sendPing, intervalMs);
166
514
  }
167
515
  if (pingableConnections.has(connection) === false) {
168
516
  pingableConnections.set(connection, {
@@ -181,31 +529,226 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
181
529
  } finally {
182
530
  pingableConnections.delete(connection);
183
531
  clearInterval(intervalId);
532
+ if (handleOffline) {
533
+ globalThis.window.removeEventListener("offline", handleOffline);
534
+ }
535
+ if (handleOnline) {
536
+ globalThis.window.removeEventListener("online", handleOnline);
537
+ }
184
538
  }
185
539
  })();
186
- restartPingTimer();
540
+ {
541
+ restartPingTimer();
542
+ }
543
+ let handleOffline;
544
+ let handleOnline;
187
545
  }
188
546
  return pingableConnections.get(connection);
189
547
  };
190
548
  }
191
549
 
550
+ // src/rpc-websocket-connection-sharding.ts
551
+ var NULL_SHARD_CACHE_KEY = Symbol(
552
+ __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
553
+ );
554
+ function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
555
+ return getCachedAbortableIterableFactory({
556
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
557
+ getCacheEntryMissingError(shardKey) {
558
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
559
+ },
560
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
561
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
562
+ onCreateIterable: (abortSignal, config) => transport({
563
+ ...config,
564
+ signal: abortSignal
565
+ })
566
+ });
567
+ }
568
+
192
569
  // src/rpc-websocket-transport.ts
193
570
  function createDefaultRpcSubscriptionsTransport(config) {
194
- const { intervalMs, ...rest } = config;
195
- return getWebSocketTransportWithAutoping({
196
- intervalMs: intervalMs ?? 5e3,
197
- transport: rpcTransport.createWebSocketTransport({
571
+ const { getShard, intervalMs, ...rest } = config;
572
+ return functional.pipe(
573
+ rpcTransport.createWebSocketTransport({
198
574
  ...rest,
199
575
  sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
200
576
  131072
577
+ }),
578
+ (transport) => getWebSocketTransportWithAutoping({
579
+ intervalMs: intervalMs ?? 5e3,
580
+ transport
581
+ }),
582
+ (transport) => getWebSocketTransportWithConnectionSharding({
583
+ getShard,
584
+ transport
201
585
  })
202
- });
586
+ );
587
+ }
588
+
589
+ // src/transaction-confirmation-strategy-blockheight.ts
590
+ function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
591
+ return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
592
+ const abortController = new AbortController();
593
+ function handleAbort() {
594
+ abortController.abort();
595
+ }
596
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
597
+ const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
598
+ try {
599
+ for await (const slotNotification of slotNotifications) {
600
+ if (slotNotification.slot > lastValidBlockHeight) {
601
+ throw new Error(
602
+ "The network has progressed past the last block for which this transaction could have committed."
603
+ );
604
+ }
605
+ }
606
+ } finally {
607
+ abortController.abort();
608
+ }
609
+ };
610
+ }
611
+ var NONCE_VALUE_OFFSET = 4 + // version(u32)
612
+ 4 + // state(u32)
613
+ 32;
614
+ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
615
+ return async function getNonceInvalidationPromise({
616
+ abortSignal: callerAbortSignal,
617
+ commitment,
618
+ currentNonceValue,
619
+ nonceAccountAddress
620
+ }) {
621
+ const abortController = new AbortController();
622
+ function handleAbort() {
623
+ abortController.abort();
624
+ }
625
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
626
+ const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
627
+ function getNonceFromAccountData([base64EncodedBytes]) {
628
+ const data = umiSerializers.base64.serialize(base64EncodedBytes);
629
+ const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
630
+ return umiSerializers.base58.deserialize(nonceValueBytes)[0];
631
+ }
632
+ const nonceAccountDidAdvancePromise = (async () => {
633
+ for await (const accountNotification of accountNotifications) {
634
+ const nonceValue = getNonceFromAccountData(accountNotification.value.data);
635
+ if (nonceValue !== currentNonceValue) {
636
+ throw new Error(
637
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
638
+ );
639
+ }
640
+ }
641
+ })();
642
+ const nonceIsAlreadyInvalidPromise = (async () => {
643
+ const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
644
+ commitment,
645
+ dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
646
+ encoding: "base58"
647
+ }).send({ abortSignal: abortController.signal });
648
+ if (!nonceAccount) {
649
+ throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
650
+ }
651
+ const nonceValue = (
652
+ // This works because we asked for the exact slice of data representing the nonce
653
+ // value, and furthermore asked for it in `base58` encoding.
654
+ nonceAccount.data[0]
655
+ );
656
+ if (nonceValue !== currentNonceValue) {
657
+ throw new Error(
658
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
659
+ );
660
+ } else {
661
+ await new Promise(() => {
662
+ });
663
+ }
664
+ })();
665
+ try {
666
+ return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
667
+ } finally {
668
+ abortController.abort();
669
+ }
670
+ };
671
+ }
672
+
673
+ // src/transaction-confirmation.ts
674
+ function createDefaultDurableNonceTransactionConfirmer({
675
+ rpc,
676
+ rpcSubscriptions
677
+ }) {
678
+ const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
679
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
680
+ rpc,
681
+ rpcSubscriptions
682
+ );
683
+ return async function confirmDurableNonceTransaction(config) {
684
+ await waitForDurableNonceTransactionConfirmation({
685
+ ...config,
686
+ getNonceInvalidationPromise,
687
+ getRecentSignatureConfirmationPromise
688
+ });
689
+ };
690
+ }
691
+ function createDefaultRecentTransactionConfirmer({
692
+ rpc,
693
+ rpcSubscriptions
694
+ }) {
695
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
696
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
697
+ rpc,
698
+ rpcSubscriptions
699
+ );
700
+ return async function confirmRecentTransaction(config) {
701
+ await waitForRecentTransactionConfirmation({
702
+ ...config,
703
+ getBlockHeightExceedencePromise,
704
+ getRecentSignatureConfirmationPromise
705
+ });
706
+ };
707
+ }
708
+ async function waitForDurableNonceTransactionConfirmation(config) {
709
+ await raceStrategies(
710
+ transactions.getSignatureFromTransaction(config.transaction),
711
+ config,
712
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
713
+ return [
714
+ getNonceInvalidationPromise({
715
+ abortSignal,
716
+ commitment,
717
+ currentNonceValue: transaction.lifetimeConstraint.nonce,
718
+ nonceAccountAddress: transaction.instructions[0].accounts[0].address
719
+ })
720
+ ];
721
+ }
722
+ );
723
+ }
724
+ async function waitForRecentTransactionConfirmation(config) {
725
+ await raceStrategies(
726
+ transactions.getSignatureFromTransaction(config.transaction),
727
+ config,
728
+ function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
729
+ return [
730
+ getBlockHeightExceedencePromise({
731
+ abortSignal,
732
+ lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
733
+ })
734
+ ];
735
+ }
736
+ );
203
737
  }
204
738
 
739
+ exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
740
+ exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
741
+ exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
205
742
  exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
206
743
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
744
+ exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
745
+ exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
207
746
  exports.createSolanaRpc = createSolanaRpc;
208
747
  exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
748
+ exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
749
+ exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
750
+ exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
751
+ exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
209
752
  Object.keys(addresses).forEach(function (k) {
210
753
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
211
754
  enumerable: true,
@@ -230,3 +773,5 @@ Object.keys(transactions).forEach(function (k) {
230
773
  get: function () { return transactions[k]; }
231
774
  });
232
775
  });
776
+ //# sourceMappingURL=out.js.map
777
+ //# sourceMappingURL=index.node.cjs.map