@solana/web3.js 2.0.0-experimental.ed7c7b8 → 2.0.0-experimental.ee4214c

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 (34) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -4
  3. package/dist/index.browser.cjs +624 -9
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +595 -11
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +3223 -209
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +584 -11
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +613 -11
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +584 -13
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +53 -4
  16. package/dist/types/cached-abortable-iterable.d.ts +11 -0
  17. package/dist/types/index.d.ts +8 -0
  18. package/dist/types/rpc-request-coalescer.d.ts +5 -0
  19. package/dist/types/rpc-request-deduplication.d.ts +2 -0
  20. package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
  21. package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
  22. package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
  23. package/dist/types/rpc-websocket-transport.d.ts +13 -0
  24. package/dist/types/rpc.d.ts +5 -3
  25. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
  26. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
  27. package/dist/types/transaction-confirmation-strategy-signature.d.ts +13 -0
  28. package/dist/types/transaction-confirmation.d.ts +39 -0
  29. package/package.json +26 -23
  30. package/dist/types/index.d.ts.map +0 -1
  31. package/dist/types/rpc-default-config.d.ts.map +0 -1
  32. package/dist/types/rpc-integer-overflow-error.d.ts.map +0 -1
  33. package/dist/types/rpc-transport.d.ts.map +0 -1
  34. package/dist/types/rpc.d.ts.map +0 -1
@@ -1,8 +1,16 @@
1
+ export * from '@solana/addresses';
2
+ export * from '@solana/instructions';
1
3
  export * from '@solana/keys';
2
- import { createSolanaRpcApi } from '@solana/rpc-core';
3
- import { createJsonRpc, createHttpTransport } from '@solana/rpc-transport';
4
+ import { getSignatureFromTransaction } from '@solana/transactions';
5
+ export * from '@solana/transactions';
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';
9
+ import fastStableStringify from 'fast-stable-stringify';
10
+ import { base64, base58 } from '@metaplex-foundation/umi-serializers';
4
11
 
5
- // src/index.ts
12
+ // ../build-scripts/env-shim.ts
13
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
6
14
 
7
15
  // src/rpc-integer-overflow-error.ts
8
16
  var SolanaJsonRpcIntegerOverflowError = class extends Error {
@@ -39,12 +47,282 @@ var DEFAULT_RPC_CONFIG = {
39
47
  throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
40
48
  }
41
49
  };
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
+
238
+ // src/rpc.ts
42
239
  function createSolanaRpc(config) {
43
240
  return createJsonRpc({
44
241
  ...config,
45
242
  api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
46
243
  });
47
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
+ }
263
+
264
+ // src/rpc-request-coalescer.ts
265
+ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
266
+ let coalescedRequestsByDeduplicationKey;
267
+ return async function makeCoalescedHttpRequest(config) {
268
+ const { payload, signal } = config;
269
+ const deduplicationKey = getDeduplicationKey(payload);
270
+ if (deduplicationKey === void 0) {
271
+ return await transport(config);
272
+ }
273
+ if (!coalescedRequestsByDeduplicationKey) {
274
+ Promise.resolve().then(() => {
275
+ coalescedRequestsByDeduplicationKey = void 0;
276
+ });
277
+ coalescedRequestsByDeduplicationKey = {};
278
+ }
279
+ if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
280
+ const abortController = new AbortController();
281
+ coalescedRequestsByDeduplicationKey[deduplicationKey] = {
282
+ abortController,
283
+ numConsumers: 0,
284
+ responsePromise: transport({
285
+ ...config,
286
+ signal: abortController.signal
287
+ })
288
+ };
289
+ }
290
+ const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
291
+ coalescedRequest.numConsumers++;
292
+ if (signal) {
293
+ const responsePromise = coalescedRequest.responsePromise;
294
+ return await new Promise((resolve, reject) => {
295
+ const handleAbort = (e) => {
296
+ signal.removeEventListener("abort", handleAbort);
297
+ coalescedRequest.numConsumers -= 1;
298
+ if (coalescedRequest.numConsumers === 0) {
299
+ const abortController = coalescedRequest.abortController;
300
+ abortController.abort();
301
+ }
302
+ const abortError = new DOMException(e.target.reason, "AbortError");
303
+ reject(abortError);
304
+ };
305
+ signal.addEventListener("abort", handleAbort);
306
+ responsePromise.then(resolve).finally(() => {
307
+ signal.removeEventListener("abort", handleAbort);
308
+ });
309
+ });
310
+ } else {
311
+ return await coalescedRequest.responsePromise;
312
+ }
313
+ };
314
+ }
315
+ function isJsonRpcPayload(payload) {
316
+ if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
317
+ return false;
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;
323
+ }
324
+
325
+ // src/rpc-transport.ts
48
326
  function normalizeHeaders(headers) {
49
327
  const out = {};
50
328
  for (const headerName in headers) {
@@ -53,18 +331,324 @@ function normalizeHeaders(headers) {
53
331
  return out;
54
332
  }
55
333
  function createDefaultRpcTransport(config) {
56
- return createHttpTransport({
57
- ...config,
58
- headers: {
59
- ...config.headers ? normalizeHeaders(config.headers) : void 0,
60
- ...{
61
- // Keep these headers lowercase so they will override any user-supplied headers above.
62
- "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
334
+ return pipe(
335
+ createHttpTransport({
336
+ ...config,
337
+ headers: {
338
+ ...config.headers ? normalizeHeaders(config.headers) : void 0,
339
+ ...{
340
+ // Keep these headers lowercase so they will override any user-supplied headers above.
341
+ "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
342
+ }
343
+ }
344
+ }),
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
+ if (globalThis.navigator.onLine) {
392
+ restartPingTimer();
393
+ }
394
+ let handleOffline;
395
+ let handleOnline;
396
+ {
397
+ handleOffline = () => {
398
+ clearInterval(intervalId);
399
+ };
400
+ handleOnline = () => {
401
+ sendPing();
402
+ restartPingTimer();
403
+ };
404
+ globalThis.window.addEventListener("offline", handleOffline);
405
+ globalThis.window.addEventListener("online", handleOnline);
63
406
  }
64
407
  }
408
+ return pingableConnections.get(connection);
409
+ };
410
+ }
411
+
412
+ // src/rpc-websocket-connection-sharding.ts
413
+ var NULL_SHARD_CACHE_KEY = Symbol(
414
+ __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
415
+ );
416
+ function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
417
+ return getCachedAbortableIterableFactory({
418
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
419
+ getCacheEntryMissingError(shardKey) {
420
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
421
+ },
422
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
423
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
424
+ onCreateIterable: (abortSignal, config) => transport({
425
+ ...config,
426
+ signal: abortSignal
427
+ })
65
428
  });
66
429
  }
67
430
 
68
- export { createDefaultRpcTransport, createSolanaRpc };
431
+ // src/rpc-websocket-transport.ts
432
+ function createDefaultRpcSubscriptionsTransport(config) {
433
+ const { getShard, intervalMs, ...rest } = config;
434
+ return pipe(
435
+ createWebSocketTransport({
436
+ ...rest,
437
+ sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
438
+ 131072
439
+ }),
440
+ (transport) => getWebSocketTransportWithAutoping({
441
+ intervalMs: intervalMs ?? 5e3,
442
+ transport
443
+ }),
444
+ (transport) => getWebSocketTransportWithConnectionSharding({
445
+ getShard,
446
+ transport
447
+ })
448
+ );
449
+ }
450
+
451
+ // src/transaction-confirmation-strategy-blockheight.ts
452
+ function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
453
+ return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
454
+ const abortController = new AbortController();
455
+ function handleAbort() {
456
+ abortController.abort();
457
+ }
458
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
459
+ const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
460
+ try {
461
+ for await (const slotNotification of slotNotifications) {
462
+ if (slotNotification.slot > lastValidBlockHeight) {
463
+ throw new Error(
464
+ "The network has progressed past the last block for which this transaction could have committed."
465
+ );
466
+ }
467
+ }
468
+ } finally {
469
+ abortController.abort();
470
+ }
471
+ };
472
+ }
473
+ var NONCE_VALUE_OFFSET = 4 + // version(u32)
474
+ 4 + // state(u32)
475
+ 32;
476
+ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
477
+ return async function getNonceInvalidationPromise({
478
+ abortSignal: callerAbortSignal,
479
+ commitment,
480
+ currentNonceValue,
481
+ nonceAccountAddress
482
+ }) {
483
+ const abortController = new AbortController();
484
+ function handleAbort() {
485
+ abortController.abort();
486
+ }
487
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
488
+ const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
489
+ function getNonceFromAccountData([base64EncodedBytes]) {
490
+ const data = base64.serialize(base64EncodedBytes);
491
+ const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
492
+ return base58.deserialize(nonceValueBytes)[0];
493
+ }
494
+ const nonceAccountDidAdvancePromise = (async () => {
495
+ for await (const accountNotification of accountNotifications) {
496
+ const nonceValue = getNonceFromAccountData(accountNotification.value.data);
497
+ if (nonceValue !== currentNonceValue) {
498
+ throw new Error(
499
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
500
+ );
501
+ }
502
+ }
503
+ })();
504
+ const nonceIsAlreadyInvalidPromise = (async () => {
505
+ const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
506
+ commitment,
507
+ dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
508
+ encoding: "base58"
509
+ }).send({ abortSignal: abortController.signal });
510
+ if (!nonceAccount) {
511
+ throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
512
+ }
513
+ const nonceValue = (
514
+ // This works because we asked for the exact slice of data representing the nonce
515
+ // value, and furthermore asked for it in `base58` encoding.
516
+ nonceAccount.data[0]
517
+ );
518
+ if (nonceValue !== currentNonceValue) {
519
+ throw new Error(
520
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
521
+ );
522
+ } else {
523
+ await new Promise(() => {
524
+ });
525
+ }
526
+ })();
527
+ try {
528
+ return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
529
+ } finally {
530
+ abortController.abort();
531
+ }
532
+ };
533
+ }
534
+ function createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
535
+ return async function getSignatureConfirmationPromise({ abortSignal: callerAbortSignal, commitment, signature }) {
536
+ const abortController = new AbortController();
537
+ function handleAbort() {
538
+ abortController.abort();
539
+ }
540
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
541
+ const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
542
+ const signatureDidCommitPromise = (async () => {
543
+ for await (const signatureStatusNotification of signatureStatusNotifications) {
544
+ if (signatureStatusNotification.value.err) {
545
+ throw new Error(`The transaction with signature \`${signature}\` failed.`, {
546
+ cause: signatureStatusNotification.value.err
547
+ });
548
+ } else {
549
+ return;
550
+ }
551
+ }
552
+ })();
553
+ const signatureStatusLookupPromise = (async () => {
554
+ const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
555
+ const signatureStatus = signatureStatusResults[0];
556
+ if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
557
+ return;
558
+ } else {
559
+ await new Promise(() => {
560
+ });
561
+ }
562
+ })();
563
+ try {
564
+ return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
565
+ } finally {
566
+ abortController.abort();
567
+ }
568
+ };
569
+ }
570
+
571
+ // src/transaction-confirmation.ts
572
+ async function raceStrategies(config, getSpecificStrategiesForRace) {
573
+ const { abortSignal: callerAbortSignal, commitment, getSignatureConfirmationPromise, transaction } = config;
574
+ callerAbortSignal.throwIfAborted();
575
+ const signature = getSignatureFromTransaction(transaction);
576
+ const abortController = new AbortController();
577
+ function handleAbort() {
578
+ abortController.abort();
579
+ }
580
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
581
+ try {
582
+ const specificStrategies = getSpecificStrategiesForRace({
583
+ ...config,
584
+ abortSignal: abortController.signal
585
+ });
586
+ return await Promise.race([
587
+ getSignatureConfirmationPromise({
588
+ abortSignal: abortController.signal,
589
+ commitment,
590
+ signature
591
+ }),
592
+ ...specificStrategies
593
+ ]);
594
+ } finally {
595
+ abortController.abort();
596
+ }
597
+ }
598
+ function createDefaultDurableNonceTransactionConfirmer({
599
+ rpc,
600
+ rpcSubscriptions
601
+ }) {
602
+ const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
603
+ const getSignatureConfirmationPromise = createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions);
604
+ return async function confirmTransaction(config) {
605
+ await waitForDurableNonceTransactionConfirmation({
606
+ ...config,
607
+ getNonceInvalidationPromise,
608
+ getSignatureConfirmationPromise
609
+ });
610
+ };
611
+ }
612
+ function createDefaultTransactionConfirmer({ rpc, rpcSubscriptions }) {
613
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
614
+ const getSignatureConfirmationPromise = createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions);
615
+ return async function confirmTransaction(config) {
616
+ await waitForTransactionConfirmation({
617
+ ...config,
618
+ getBlockHeightExceedencePromise,
619
+ getSignatureConfirmationPromise
620
+ });
621
+ };
622
+ }
623
+ async function waitForDurableNonceTransactionConfirmation(config) {
624
+ await raceStrategies(
625
+ config,
626
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
627
+ return [
628
+ getNonceInvalidationPromise({
629
+ abortSignal,
630
+ commitment,
631
+ currentNonceValue: transaction.lifetimeConstraint.nonce,
632
+ nonceAccountAddress: transaction.instructions[0].accounts[0].address
633
+ })
634
+ ];
635
+ }
636
+ );
637
+ }
638
+ async function waitForTransactionConfirmation(config) {
639
+ await raceStrategies(
640
+ config,
641
+ function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
642
+ return [
643
+ getBlockHeightExceedencePromise({
644
+ abortSignal,
645
+ lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
646
+ })
647
+ ];
648
+ }
649
+ );
650
+ }
651
+
652
+ export { createBlockHeightExceedencePromiseFactory, createDefaultDurableNonceTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createDefaultTransactionConfirmer, createNonceInvalidationPromiseFactory, createSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, waitForDurableNonceTransactionConfirmation, waitForTransactionConfirmation };
69
653
  //# sourceMappingURL=out.js.map
70
654
  //# sourceMappingURL=index.browser.js.map