@solana/web3.js 2.0.0-experimental.7e66ec4 → 2.0.0-experimental.819a6f7

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.
Files changed (42) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -4
  3. package/dist/index.browser.cjs +546 -8
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +540 -11
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +2484 -698
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +529 -11
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +535 -8
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +529 -13
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +52 -30
  16. package/dist/types/cached-abortable-iterable.d.ts +11 -0
  17. package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
  18. package/dist/types/index.d.ts +5 -0
  19. package/dist/types/index.d.ts.map +1 -1
  20. package/dist/types/rpc-request-deduplication.d.ts.map +1 -1
  21. package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
  22. package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -0
  23. package/dist/types/rpc-transport.d.ts.map +1 -1
  24. package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
  25. package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
  26. package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
  27. package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
  28. package/dist/types/rpc-websocket-transport.d.ts +13 -0
  29. package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
  30. package/dist/types/rpc.d.ts +5 -3
  31. package/dist/types/rpc.d.ts.map +1 -1
  32. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
  33. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
  34. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
  35. package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -0
  36. package/dist/types/transaction-confirmation-strategy-racer.d.ts +10 -0
  37. package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +1 -0
  38. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
  39. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -0
  40. package/dist/types/transaction-confirmation.d.ts +37 -0
  41. package/dist/types/transaction-confirmation.d.ts.map +1 -0
  42. package/package.json +20 -17
@@ -1,12 +1,16 @@
1
1
  export * from '@solana/addresses';
2
2
  export * from '@solana/instructions';
3
3
  export * from '@solana/keys';
4
+ import { getSignatureFromTransaction } from '@solana/transactions';
4
5
  export * from '@solana/transactions';
5
- import { createSolanaRpcApi } from '@solana/rpc-core';
6
- import { createJsonRpc, createHttpTransport } from '@solana/rpc-transport';
6
+ import { pipe } from '@solana/functional';
7
+ import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE, commitmentComparator } from '@solana/rpc-core';
8
+ import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
7
9
  import fastStableStringify from 'fast-stable-stringify';
10
+ import { base64, base58 } from '@metaplex-foundation/umi-serializers';
8
11
 
9
- // src/index.ts
12
+ // ../build-scripts/env-shim.ts
13
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
10
14
 
11
15
  // src/rpc-integer-overflow-error.ts
12
16
  var SolanaJsonRpcIntegerOverflowError = class extends Error {
@@ -44,6 +48,193 @@ var DEFAULT_RPC_CONFIG = {
44
48
  }
45
49
  };
46
50
 
51
+ // src/cached-abortable-iterable.ts
52
+ function registerIterableCleanup(iterable, cleanupFn) {
53
+ (async () => {
54
+ try {
55
+ for await (const _ of iterable)
56
+ ;
57
+ } catch {
58
+ } finally {
59
+ cleanupFn();
60
+ }
61
+ })();
62
+ }
63
+ function getCachedAbortableIterableFactory({
64
+ getAbortSignalFromInputArgs,
65
+ getCacheEntryMissingError,
66
+ getCacheKeyFromInputArgs,
67
+ onCacheHit,
68
+ onCreateIterable
69
+ }) {
70
+ const cache = /* @__PURE__ */ new Map();
71
+ function getCacheEntryOrThrow(cacheKey) {
72
+ const currentCacheEntry = cache.get(cacheKey);
73
+ if (!currentCacheEntry) {
74
+ throw getCacheEntryMissingError(cacheKey);
75
+ }
76
+ return currentCacheEntry;
77
+ }
78
+ return async (...args) => {
79
+ const cacheKey = getCacheKeyFromInputArgs(...args);
80
+ const signal = getAbortSignalFromInputArgs(...args);
81
+ if (cacheKey === void 0) {
82
+ return await onCreateIterable(signal, ...args);
83
+ }
84
+ const cleanup = () => {
85
+ cache.delete(cacheKey);
86
+ signal.removeEventListener("abort", handleAbort);
87
+ };
88
+ const handleAbort = () => {
89
+ const cacheEntry = getCacheEntryOrThrow(cacheKey);
90
+ if (cacheEntry.purgeScheduled !== true) {
91
+ cacheEntry.purgeScheduled = true;
92
+ globalThis.queueMicrotask(() => {
93
+ cacheEntry.purgeScheduled = false;
94
+ if (cacheEntry.referenceCount === 0) {
95
+ cacheEntry.abortController.abort();
96
+ cleanup();
97
+ }
98
+ });
99
+ }
100
+ cacheEntry.referenceCount--;
101
+ };
102
+ signal.addEventListener("abort", handleAbort);
103
+ try {
104
+ const cacheEntry = cache.get(cacheKey);
105
+ if (!cacheEntry) {
106
+ const singletonAbortController = new AbortController();
107
+ const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
108
+ const newCacheEntry = {
109
+ abortController: singletonAbortController,
110
+ iterable: newIterablePromise,
111
+ purgeScheduled: false,
112
+ referenceCount: 1
113
+ };
114
+ cache.set(cacheKey, newCacheEntry);
115
+ const newIterable = await newIterablePromise;
116
+ registerIterableCleanup(newIterable, cleanup);
117
+ newCacheEntry.iterable = newIterable;
118
+ return newIterable;
119
+ } else {
120
+ cacheEntry.referenceCount++;
121
+ const iterableOrIterablePromise = cacheEntry.iterable;
122
+ const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
123
+ await onCacheHit(cachedIterable, ...args);
124
+ return cachedIterable;
125
+ }
126
+ } catch (e) {
127
+ cleanup();
128
+ throw e;
129
+ }
130
+ };
131
+ }
132
+
133
+ // src/rpc-subscription-coalescer.ts
134
+ var EXPLICIT_ABORT_TOKEN = Symbol(
135
+ __DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
136
+ );
137
+ function registerIterableCleanup2(iterable, cleanupFn) {
138
+ (async () => {
139
+ try {
140
+ for await (const _ of iterable)
141
+ ;
142
+ } catch {
143
+ } finally {
144
+ cleanupFn();
145
+ }
146
+ })();
147
+ }
148
+ function getRpcSubscriptionsWithSubscriptionCoalescing({
149
+ getDeduplicationKey,
150
+ rpcSubscriptions
151
+ }) {
152
+ const cache = /* @__PURE__ */ new Map();
153
+ return new Proxy(rpcSubscriptions, {
154
+ defineProperty() {
155
+ return false;
156
+ },
157
+ deleteProperty() {
158
+ return false;
159
+ },
160
+ get(target, p, receiver) {
161
+ const subscriptionMethod = Reflect.get(target, p, receiver);
162
+ if (typeof subscriptionMethod !== "function") {
163
+ return subscriptionMethod;
164
+ }
165
+ return function(...rawParams) {
166
+ const deduplicationKey = getDeduplicationKey(p, rawParams);
167
+ if (deduplicationKey === void 0) {
168
+ return subscriptionMethod(...rawParams);
169
+ }
170
+ if (cache.has(deduplicationKey)) {
171
+ return cache.get(deduplicationKey);
172
+ }
173
+ const iterableFactory = getCachedAbortableIterableFactory({
174
+ getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
175
+ getCacheEntryMissingError(deduplicationKey2) {
176
+ return new Error(
177
+ `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
178
+ );
179
+ },
180
+ getCacheKeyFromInputArgs: () => deduplicationKey,
181
+ async onCacheHit(_iterable, _config) {
182
+ },
183
+ async onCreateIterable(abortSignal, config) {
184
+ const pendingSubscription2 = subscriptionMethod(
185
+ ...rawParams
186
+ );
187
+ const iterable = await pendingSubscription2.subscribe({
188
+ ...config,
189
+ abortSignal
190
+ });
191
+ registerIterableCleanup2(iterable, () => {
192
+ cache.delete(deduplicationKey);
193
+ });
194
+ return iterable;
195
+ }
196
+ });
197
+ const pendingSubscription = {
198
+ async subscribe(...args) {
199
+ const iterable = await iterableFactory(...args);
200
+ const { abortSignal } = args[0];
201
+ let abortPromise;
202
+ return {
203
+ ...iterable,
204
+ async *[Symbol.asyncIterator]() {
205
+ abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
206
+ abortSignal.addEventListener("abort", () => {
207
+ reject(EXPLICIT_ABORT_TOKEN);
208
+ });
209
+ }));
210
+ try {
211
+ const iterator = iterable[Symbol.asyncIterator]();
212
+ while (true) {
213
+ const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
214
+ if (iteratorResult.done) {
215
+ return;
216
+ } else {
217
+ yield iteratorResult.value;
218
+ }
219
+ }
220
+ } catch (e) {
221
+ if (e === EXPLICIT_ABORT_TOKEN) {
222
+ return;
223
+ }
224
+ cache.delete(deduplicationKey);
225
+ throw e;
226
+ }
227
+ }
228
+ };
229
+ }
230
+ };
231
+ cache.set(deduplicationKey, pendingSubscription);
232
+ return pendingSubscription;
233
+ };
234
+ }
235
+ });
236
+ }
237
+
47
238
  // src/rpc.ts
48
239
  function createSolanaRpc(config) {
49
240
  return createJsonRpc({
@@ -51,6 +242,24 @@ function createSolanaRpc(config) {
51
242
  api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
52
243
  });
53
244
  }
245
+ function createSolanaRpcSubscriptions(config) {
246
+ return pipe(
247
+ createJsonSubscriptionRpc({
248
+ ...config,
249
+ api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
250
+ }),
251
+ (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
252
+ getDeduplicationKey: (...args) => fastStableStringify(args),
253
+ rpcSubscriptions
254
+ })
255
+ );
256
+ }
257
+ function createSolanaRpcSubscriptions_UNSTABLE(config) {
258
+ return createJsonSubscriptionRpc({
259
+ ...config,
260
+ api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
261
+ });
262
+ }
54
263
 
55
264
  // src/rpc-request-coalescer.ts
56
265
  function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
@@ -103,13 +312,14 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
103
312
  }
104
313
  };
105
314
  }
106
- function getSolanaRpcPayloadDeduplicationKey(payload) {
315
+ function isJsonRpcPayload(payload) {
107
316
  if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
108
- return;
109
- }
110
- if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
111
- return fastStableStringify([payload.method, payload.params]);
317
+ return false;
112
318
  }
319
+ return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
320
+ }
321
+ function getSolanaRpcPayloadDeduplicationKey(payload) {
322
+ return isJsonRpcPayload(payload) ? fastStableStringify([payload.method, payload.params]) : void 0;
113
323
  }
114
324
 
115
325
  // src/rpc-transport.ts
@@ -121,7 +331,7 @@ function normalizeHeaders(headers) {
121
331
  return out;
122
332
  }
123
333
  function createDefaultRpcTransport(config) {
124
- return getRpcTransportWithRequestCoalescing(
334
+ return pipe(
125
335
  createHttpTransport({
126
336
  ...config,
127
337
  headers: {
@@ -132,10 +342,318 @@ function createDefaultRpcTransport(config) {
132
342
  }
133
343
  }
134
344
  }),
135
- getSolanaRpcPayloadDeduplicationKey
345
+ (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
346
+ );
347
+ }
348
+
349
+ // src/rpc-websocket-autopinger.ts
350
+ var PING_PAYLOAD = {
351
+ jsonrpc: "2.0",
352
+ method: "ping"
353
+ };
354
+ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
355
+ const pingableConnections = /* @__PURE__ */ new Map();
356
+ return async (...args) => {
357
+ const connection = await transport(...args);
358
+ let intervalId;
359
+ function sendPing() {
360
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
361
+ }
362
+ function restartPingTimer() {
363
+ clearInterval(intervalId);
364
+ intervalId = setInterval(sendPing, intervalMs);
365
+ }
366
+ if (pingableConnections.has(connection) === false) {
367
+ pingableConnections.set(connection, {
368
+ [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
369
+ send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
370
+ restartPingTimer();
371
+ return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
372
+ }
373
+ });
374
+ (async () => {
375
+ try {
376
+ for await (const _ of connection) {
377
+ restartPingTimer();
378
+ }
379
+ } catch {
380
+ } finally {
381
+ pingableConnections.delete(connection);
382
+ clearInterval(intervalId);
383
+ if (handleOffline) {
384
+ globalThis.window.removeEventListener("offline", handleOffline);
385
+ }
386
+ if (handleOnline) {
387
+ globalThis.window.removeEventListener("online", handleOnline);
388
+ }
389
+ }
390
+ })();
391
+ {
392
+ restartPingTimer();
393
+ }
394
+ let handleOffline;
395
+ let handleOnline;
396
+ }
397
+ return pingableConnections.get(connection);
398
+ };
399
+ }
400
+
401
+ // src/rpc-websocket-connection-sharding.ts
402
+ var NULL_SHARD_CACHE_KEY = Symbol(
403
+ __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
404
+ );
405
+ function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
406
+ return getCachedAbortableIterableFactory({
407
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
408
+ getCacheEntryMissingError(shardKey) {
409
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
410
+ },
411
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
412
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
413
+ onCreateIterable: (abortSignal, config) => transport({
414
+ ...config,
415
+ signal: abortSignal
416
+ })
417
+ });
418
+ }
419
+
420
+ // src/rpc-websocket-transport.ts
421
+ function createDefaultRpcSubscriptionsTransport(config) {
422
+ const { getShard, intervalMs, ...rest } = config;
423
+ return pipe(
424
+ createWebSocketTransport({
425
+ ...rest,
426
+ sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
427
+ 131072
428
+ }),
429
+ (transport) => getWebSocketTransportWithAutoping({
430
+ intervalMs: intervalMs ?? 5e3,
431
+ transport
432
+ }),
433
+ (transport) => getWebSocketTransportWithConnectionSharding({
434
+ getShard,
435
+ transport
436
+ })
437
+ );
438
+ }
439
+
440
+ // src/transaction-confirmation-strategy-blockheight.ts
441
+ function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
442
+ return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
443
+ const abortController = new AbortController();
444
+ function handleAbort() {
445
+ abortController.abort();
446
+ }
447
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
448
+ const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
449
+ try {
450
+ for await (const slotNotification of slotNotifications) {
451
+ if (slotNotification.slot > lastValidBlockHeight) {
452
+ throw new Error(
453
+ "The network has progressed past the last block for which this transaction could have committed."
454
+ );
455
+ }
456
+ }
457
+ } finally {
458
+ abortController.abort();
459
+ }
460
+ };
461
+ }
462
+ var NONCE_VALUE_OFFSET = 4 + // version(u32)
463
+ 4 + // state(u32)
464
+ 32;
465
+ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
466
+ return async function getNonceInvalidationPromise({
467
+ abortSignal: callerAbortSignal,
468
+ commitment,
469
+ currentNonceValue,
470
+ nonceAccountAddress
471
+ }) {
472
+ const abortController = new AbortController();
473
+ function handleAbort() {
474
+ abortController.abort();
475
+ }
476
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
477
+ const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
478
+ function getNonceFromAccountData([base64EncodedBytes]) {
479
+ const data = base64.serialize(base64EncodedBytes);
480
+ const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
481
+ return base58.deserialize(nonceValueBytes)[0];
482
+ }
483
+ const nonceAccountDidAdvancePromise = (async () => {
484
+ for await (const accountNotification of accountNotifications) {
485
+ const nonceValue = getNonceFromAccountData(accountNotification.value.data);
486
+ if (nonceValue !== currentNonceValue) {
487
+ throw new Error(
488
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
489
+ );
490
+ }
491
+ }
492
+ })();
493
+ const nonceIsAlreadyInvalidPromise = (async () => {
494
+ const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
495
+ commitment,
496
+ dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
497
+ encoding: "base58"
498
+ }).send({ abortSignal: abortController.signal });
499
+ if (!nonceAccount) {
500
+ throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
501
+ }
502
+ const nonceValue = (
503
+ // This works because we asked for the exact slice of data representing the nonce
504
+ // value, and furthermore asked for it in `base58` encoding.
505
+ nonceAccount.data[0]
506
+ );
507
+ if (nonceValue !== currentNonceValue) {
508
+ throw new Error(
509
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
510
+ );
511
+ } else {
512
+ await new Promise(() => {
513
+ });
514
+ }
515
+ })();
516
+ try {
517
+ return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
518
+ } finally {
519
+ abortController.abort();
520
+ }
521
+ };
522
+ }
523
+
524
+ // src/transaction-confirmation-strategy-racer.ts
525
+ async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
526
+ const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
527
+ callerAbortSignal.throwIfAborted();
528
+ const abortController = new AbortController();
529
+ function handleAbort() {
530
+ abortController.abort();
531
+ }
532
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
533
+ try {
534
+ const specificStrategies = getSpecificStrategiesForRace({
535
+ ...config,
536
+ abortSignal: abortController.signal
537
+ });
538
+ return await Promise.race([
539
+ getRecentSignatureConfirmationPromise({
540
+ abortSignal: abortController.signal,
541
+ commitment,
542
+ signature
543
+ }),
544
+ ...specificStrategies
545
+ ]);
546
+ } finally {
547
+ abortController.abort();
548
+ }
549
+ }
550
+ function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
551
+ return async function getRecentSignatureConfirmationPromise({
552
+ abortSignal: callerAbortSignal,
553
+ commitment,
554
+ signature
555
+ }) {
556
+ const abortController = new AbortController();
557
+ function handleAbort() {
558
+ abortController.abort();
559
+ }
560
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
561
+ const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
562
+ const signatureDidCommitPromise = (async () => {
563
+ for await (const signatureStatusNotification of signatureStatusNotifications) {
564
+ if (signatureStatusNotification.value.err) {
565
+ throw new Error(`The transaction with signature \`${signature}\` failed.`, {
566
+ cause: signatureStatusNotification.value.err
567
+ });
568
+ } else {
569
+ return;
570
+ }
571
+ }
572
+ })();
573
+ const signatureStatusLookupPromise = (async () => {
574
+ const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
575
+ const signatureStatus = signatureStatusResults[0];
576
+ if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
577
+ return;
578
+ } else {
579
+ await new Promise(() => {
580
+ });
581
+ }
582
+ })();
583
+ try {
584
+ return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
585
+ } finally {
586
+ abortController.abort();
587
+ }
588
+ };
589
+ }
590
+
591
+ // src/transaction-confirmation.ts
592
+ function createDefaultDurableNonceTransactionConfirmer({
593
+ rpc,
594
+ rpcSubscriptions
595
+ }) {
596
+ const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
597
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
598
+ rpc,
599
+ rpcSubscriptions
600
+ );
601
+ return async function confirmDurableNonceTransaction(config) {
602
+ await waitForDurableNonceTransactionConfirmation({
603
+ ...config,
604
+ getNonceInvalidationPromise,
605
+ getRecentSignatureConfirmationPromise
606
+ });
607
+ };
608
+ }
609
+ function createDefaultRecentTransactionConfirmer({
610
+ rpc,
611
+ rpcSubscriptions
612
+ }) {
613
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
614
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
615
+ rpc,
616
+ rpcSubscriptions
617
+ );
618
+ return async function confirmRecentTransaction(config) {
619
+ await waitForRecentTransactionConfirmation({
620
+ ...config,
621
+ getBlockHeightExceedencePromise,
622
+ getRecentSignatureConfirmationPromise
623
+ });
624
+ };
625
+ }
626
+ async function waitForDurableNonceTransactionConfirmation(config) {
627
+ await raceStrategies(
628
+ getSignatureFromTransaction(config.transaction),
629
+ config,
630
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
631
+ return [
632
+ getNonceInvalidationPromise({
633
+ abortSignal,
634
+ commitment,
635
+ currentNonceValue: transaction.lifetimeConstraint.nonce,
636
+ nonceAccountAddress: transaction.instructions[0].accounts[0].address
637
+ })
638
+ ];
639
+ }
640
+ );
641
+ }
642
+ async function waitForRecentTransactionConfirmation(config) {
643
+ await raceStrategies(
644
+ getSignatureFromTransaction(config.transaction),
645
+ config,
646
+ function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
647
+ return [
648
+ getBlockHeightExceedencePromise({
649
+ abortSignal,
650
+ lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
651
+ })
652
+ ];
653
+ }
136
654
  );
137
655
  }
138
656
 
139
- export { createDefaultRpcTransport, createSolanaRpc };
657
+ export { createBlockHeightExceedencePromiseFactory, createDefaultDurableNonceTransactionConfirmer, createDefaultRecentTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createNonceInvalidationPromiseFactory, createRecentSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation };
140
658
  //# sourceMappingURL=out.js.map
141
659
  //# sourceMappingURL=index.native.js.map