@solana/web3.js 2.0.0-experimental.20e2b21 → 2.0.0-experimental.21e994f

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