@solana/web3.js 2.0.0-experimental.06517d7 → 2.0.0-experimental.07c30c1

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 (62) hide show
  1. package/dist/index.browser.cjs +114 -855
  2. package/dist/index.browser.cjs.map +1 -1
  3. package/dist/index.browser.js +97 -834
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.development.js +3900 -3182
  6. package/dist/index.development.js.map +1 -1
  7. package/dist/index.native.js +97 -823
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +114 -844
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +97 -823
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/index.production.min.js +278 -277
  14. package/dist/types/airdrop-internal.d.ts +16 -0
  15. package/dist/types/airdrop-internal.d.ts.map +1 -0
  16. package/dist/types/airdrop.d.ts +7 -16
  17. package/dist/types/airdrop.d.ts.map +1 -1
  18. package/dist/types/decode-transaction.d.ts +1 -2
  19. package/dist/types/decode-transaction.d.ts.map +1 -1
  20. package/dist/types/index.d.ts +2 -7
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/send-transaction-internal.d.ts +27 -0
  23. package/dist/types/send-transaction-internal.d.ts.map +1 -0
  24. package/dist/types/send-transaction.d.ts +16 -30
  25. package/dist/types/send-transaction.d.ts.map +1 -1
  26. package/package.json +24 -45
  27. package/dist/types/airdrop-confirmer.d.ts +0 -19
  28. package/dist/types/airdrop-confirmer.d.ts.map +0 -1
  29. package/dist/types/cached-abortable-iterable.d.ts +0 -11
  30. package/dist/types/cached-abortable-iterable.d.ts.map +0 -1
  31. package/dist/types/rpc-default-config.d.ts +0 -3
  32. package/dist/types/rpc-default-config.d.ts.map +0 -1
  33. package/dist/types/rpc-integer-overflow-error.d.ts +0 -4
  34. package/dist/types/rpc-integer-overflow-error.d.ts.map +0 -1
  35. package/dist/types/rpc-request-coalescer.d.ts +0 -5
  36. package/dist/types/rpc-request-coalescer.d.ts.map +0 -1
  37. package/dist/types/rpc-request-deduplication.d.ts +0 -2
  38. package/dist/types/rpc-request-deduplication.d.ts.map +0 -1
  39. package/dist/types/rpc-subscription-coalescer.d.ts +0 -10
  40. package/dist/types/rpc-subscription-coalescer.d.ts.map +0 -1
  41. package/dist/types/rpc-transport.d.ts +0 -9
  42. package/dist/types/rpc-transport.d.ts.map +0 -1
  43. package/dist/types/rpc-websocket-autopinger.d.ts +0 -8
  44. package/dist/types/rpc-websocket-autopinger.d.ts.map +0 -1
  45. package/dist/types/rpc-websocket-connection-sharding.d.ts +0 -13
  46. package/dist/types/rpc-websocket-connection-sharding.d.ts.map +0 -1
  47. package/dist/types/rpc-websocket-transport.d.ts +0 -16
  48. package/dist/types/rpc-websocket-transport.d.ts.map +0 -1
  49. package/dist/types/rpc.d.ts +0 -13
  50. package/dist/types/rpc.d.ts.map +0 -1
  51. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +0 -14
  52. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +0 -1
  53. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +0 -13
  54. package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +0 -1
  55. package/dist/types/transaction-confirmation-strategy-racer.d.ts +0 -14
  56. package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +0 -1
  57. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +0 -11
  58. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +0 -1
  59. package/dist/types/transaction-confirmation-strategy-timeout.d.ts +0 -8
  60. package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +0 -1
  61. package/dist/types/transaction-confirmation.d.ts +0 -32
  62. package/dist/types/transaction-confirmation.d.ts.map +0 -1
@@ -1,181 +1,62 @@
1
1
  import { fetchJsonParsedAccounts, assertAccountsDecoded, assertAccountsExist } from '@solana/accounts';
2
2
  export * from '@solana/accounts';
3
3
  export * from '@solana/addresses';
4
- import { getBase58Decoder, getBase64Encoder } from '@solana/codecs';
5
4
  export * from '@solana/codecs';
6
- import { pipe } from '@solana/functional';
7
5
  export * from '@solana/functional';
8
6
  export * from '@solana/instructions';
9
7
  export * from '@solana/keys';
10
8
  export * from '@solana/programs';
9
+ export * from '@solana/rpc';
11
10
  export * from '@solana/rpc-parsed-types';
11
+ export * from '@solana/rpc-subscriptions';
12
12
  import { commitmentComparator } from '@solana/rpc-types';
13
13
  export * from '@solana/rpc-types';
14
14
  export * from '@solana/signers';
15
- import { getCompiledTransactionDecoder, decompileTransaction, getSignatureFromTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';
15
+ import { getCompiledTransactionDecoder, decompileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';
16
16
  export * from '@solana/transactions';
17
- import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE } from '@solana/rpc-core';
18
- import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
19
- import fastStableStringify from 'fast-stable-stringify';
20
- import { SolanaError, SOLANA_ERROR__RPC_INTEGER_OVERFLOW } from '@solana/errors';
17
+ import { createRecentSignatureConfirmationPromiseFactory, createNonceInvalidationPromiseFactory, createBlockHeightExceedencePromiseFactory, waitForRecentTransactionConfirmationUntilTimeout, getTimeoutPromise, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation } from '@solana/transaction-confirmation';
21
18
 
22
- // ../build-scripts/env-shim.ts
23
- var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
19
+ // src/index.ts
24
20
 
25
- // src/transaction-confirmation-strategy-racer.ts
26
- async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
27
- const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
28
- callerAbortSignal?.throwIfAborted();
29
- const abortController = new AbortController();
30
- if (callerAbortSignal) {
31
- const handleAbort = () => {
32
- abortController.abort();
33
- };
34
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
35
- }
36
- try {
37
- const specificStrategies = getSpecificStrategiesForRace({
38
- ...config,
39
- abortSignal: abortController.signal
40
- });
41
- return await Promise.race([
42
- getRecentSignatureConfirmationPromise({
43
- abortSignal: abortController.signal,
44
- commitment,
45
- signature
46
- }),
47
- ...specificStrategies
48
- ]);
49
- } finally {
50
- abortController.abort();
51
- }
52
- }
53
- function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
54
- return async function getRecentSignatureConfirmationPromise({
55
- abortSignal: callerAbortSignal,
21
+ // src/airdrop-internal.ts
22
+ async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
23
+ abortSignal,
24
+ commitment,
25
+ confirmSignatureOnlyTransaction,
26
+ lamports,
27
+ recipientAddress,
28
+ rpc
29
+ }) {
30
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
31
+ await confirmSignatureOnlyTransaction({
32
+ abortSignal,
56
33
  commitment,
57
- signature
58
- }) {
59
- const abortController = new AbortController();
60
- function handleAbort() {
61
- abortController.abort();
62
- }
63
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
64
- const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
65
- const signatureDidCommitPromise = (async () => {
66
- for await (const signatureStatusNotification of signatureStatusNotifications) {
67
- if (signatureStatusNotification.value.err) {
68
- throw new Error(`The transaction with signature \`${signature}\` failed.`, {
69
- cause: signatureStatusNotification.value.err
70
- });
71
- } else {
72
- return;
73
- }
74
- }
75
- })();
76
- const signatureStatusLookupPromise = (async () => {
77
- const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
78
- const signatureStatus = signatureStatusResults[0];
79
- if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
80
- return;
81
- } else {
82
- await new Promise(() => {
83
- });
84
- }
85
- })();
86
- try {
87
- return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
88
- } finally {
89
- abortController.abort();
90
- }
91
- };
92
- }
93
-
94
- // src/transaction-confirmation-strategy-timeout.ts
95
- async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
96
- return await new Promise((_, reject) => {
97
- const handleAbort = (e) => {
98
- clearTimeout(timeoutId);
99
- const abortError = new DOMException(e.target.reason, "AbortError");
100
- reject(abortError);
101
- };
102
- callerAbortSignal.addEventListener("abort", handleAbort);
103
- const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
104
- const startMs = performance.now();
105
- const timeoutId = (
106
- // We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
107
- // elapsed time instead of active time.
108
- // See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
109
- setTimeout(() => {
110
- const elapsedMs = performance.now() - startMs;
111
- reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
112
- }, timeoutMs)
113
- );
34
+ signature: airdropTransactionSignature
114
35
  });
36
+ return airdropTransactionSignature;
115
37
  }
116
38
 
117
- // src/airdrop-confirmer.ts
118
- function createDefaultSignatureOnlyRecentTransactionConfirmer({
119
- rpc,
120
- rpcSubscriptions
121
- }) {
39
+ // src/airdrop.ts
40
+ function airdropFactory({ rpc, rpcSubscriptions }) {
122
41
  const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
123
42
  rpc,
124
43
  rpcSubscriptions
125
44
  );
126
- return async function confirmSignatureOnlyRecentTransaction(config) {
45
+ async function confirmSignatureOnlyTransaction(config) {
127
46
  await waitForRecentTransactionConfirmationUntilTimeout({
128
47
  ...config,
129
48
  getRecentSignatureConfirmationPromise,
130
49
  getTimeoutPromise
131
50
  });
132
- };
133
- }
134
- async function waitForRecentTransactionConfirmationUntilTimeout(config) {
135
- await raceStrategies(
136
- config.signature,
137
- config,
138
- function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
139
- return [
140
- getTimeoutPromise2({
141
- abortSignal,
142
- commitment
143
- })
144
- ];
145
- }
146
- );
147
- }
148
-
149
- // src/airdrop.ts
150
- function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
151
- const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
152
- rpc,
153
- rpcSubscriptions
154
- });
155
- return async function requestAirdrop(config) {
156
- return await requestAndConfirmAirdrop({
51
+ }
52
+ return async function airdrop(config) {
53
+ return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
157
54
  ...config,
158
55
  confirmSignatureOnlyTransaction,
159
56
  rpc
160
57
  });
161
58
  };
162
59
  }
163
- async function requestAndConfirmAirdrop({
164
- abortSignal,
165
- commitment,
166
- confirmSignatureOnlyTransaction,
167
- lamports,
168
- recipientAddress,
169
- rpc
170
- }) {
171
- const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
172
- await confirmSignatureOnlyTransaction({
173
- abortSignal,
174
- commitment,
175
- signature: airdropTransactionSignature
176
- });
177
- return airdropTransactionSignature;
178
- }
179
60
  var compiledTransactionDecoder = void 0;
180
61
  async function fetchLookupTables(lookupTableAddresses, rpc, config) {
181
62
  const fetchedLookupTables = await fetchJsonParsedAccounts(
@@ -206,656 +87,6 @@ async function decodeTransaction(encodedTransaction, rpc, config) {
206
87
  lastValidBlockHeight
207
88
  });
208
89
  }
209
- function createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value) {
210
- let argumentLabel = "";
211
- if (typeof keyPath[0] === "number") {
212
- const argPosition = keyPath[0] + 1;
213
- const lastDigit = argPosition % 10;
214
- const lastTwoDigits = argPosition % 100;
215
- if (lastDigit == 1 && lastTwoDigits != 11) {
216
- argumentLabel = argPosition + "st";
217
- } else if (lastDigit == 2 && lastTwoDigits != 12) {
218
- argumentLabel = argPosition + "nd";
219
- } else if (lastDigit == 3 && lastTwoDigits != 13) {
220
- argumentLabel = argPosition + "rd";
221
- } else {
222
- argumentLabel = argPosition + "th";
223
- }
224
- } else {
225
- argumentLabel = `\`${keyPath[0].toString()}\``;
226
- }
227
- const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : void 0;
228
- const error = new SolanaError(SOLANA_ERROR__RPC_INTEGER_OVERFLOW, {
229
- argumentLabel,
230
- keyPath,
231
- methodName,
232
- optionalPathLabel: path ? ` at path \`${path}\`` : "",
233
- value,
234
- ...path !== void 0 ? { path } : void 0
235
- });
236
- if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
237
- Error.captureStackTrace(error, createSolanaJsonRpcIntegerOverflowError);
238
- }
239
- return error;
240
- }
241
-
242
- // src/rpc-default-config.ts
243
- var DEFAULT_RPC_CONFIG = {
244
- defaultCommitment: "confirmed",
245
- onIntegerOverflow(methodName, keyPath, value) {
246
- throw createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
247
- }
248
- };
249
-
250
- // src/cached-abortable-iterable.ts
251
- function registerIterableCleanup(iterable, cleanupFn) {
252
- (async () => {
253
- try {
254
- for await (const _ of iterable)
255
- ;
256
- } catch {
257
- } finally {
258
- cleanupFn();
259
- }
260
- })();
261
- }
262
- function getCachedAbortableIterableFactory({
263
- getAbortSignalFromInputArgs,
264
- getCacheEntryMissingError,
265
- getCacheKeyFromInputArgs,
266
- onCacheHit,
267
- onCreateIterable
268
- }) {
269
- const cache = /* @__PURE__ */ new Map();
270
- function getCacheEntryOrThrow(cacheKey) {
271
- const currentCacheEntry = cache.get(cacheKey);
272
- if (!currentCacheEntry) {
273
- throw getCacheEntryMissingError(cacheKey);
274
- }
275
- return currentCacheEntry;
276
- }
277
- return async (...args) => {
278
- const cacheKey = getCacheKeyFromInputArgs(...args);
279
- const signal = getAbortSignalFromInputArgs(...args);
280
- if (cacheKey === void 0) {
281
- return await onCreateIterable(signal, ...args);
282
- }
283
- const cleanup = () => {
284
- cache.delete(cacheKey);
285
- signal.removeEventListener("abort", handleAbort);
286
- };
287
- const handleAbort = () => {
288
- const cacheEntry = getCacheEntryOrThrow(cacheKey);
289
- if (cacheEntry.purgeScheduled !== true) {
290
- cacheEntry.purgeScheduled = true;
291
- globalThis.queueMicrotask(() => {
292
- cacheEntry.purgeScheduled = false;
293
- if (cacheEntry.referenceCount === 0) {
294
- cacheEntry.abortController.abort();
295
- cleanup();
296
- }
297
- });
298
- }
299
- cacheEntry.referenceCount--;
300
- };
301
- signal.addEventListener("abort", handleAbort);
302
- try {
303
- const cacheEntry = cache.get(cacheKey);
304
- if (!cacheEntry) {
305
- const singletonAbortController = new AbortController();
306
- const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
307
- const newCacheEntry = {
308
- abortController: singletonAbortController,
309
- iterable: newIterablePromise,
310
- purgeScheduled: false,
311
- referenceCount: 1
312
- };
313
- cache.set(cacheKey, newCacheEntry);
314
- const newIterable = await newIterablePromise;
315
- registerIterableCleanup(newIterable, cleanup);
316
- newCacheEntry.iterable = newIterable;
317
- return newIterable;
318
- } else {
319
- cacheEntry.referenceCount++;
320
- const iterableOrIterablePromise = cacheEntry.iterable;
321
- const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
322
- await onCacheHit(cachedIterable, ...args);
323
- return cachedIterable;
324
- }
325
- } catch (e) {
326
- cleanup();
327
- throw e;
328
- }
329
- };
330
- }
331
-
332
- // src/rpc-subscription-coalescer.ts
333
- var EXPLICIT_ABORT_TOKEN = Symbol(
334
- __DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
335
- );
336
- function registerIterableCleanup2(iterable, cleanupFn) {
337
- (async () => {
338
- try {
339
- for await (const _ of iterable)
340
- ;
341
- } catch {
342
- } finally {
343
- cleanupFn();
344
- }
345
- })();
346
- }
347
- function getRpcSubscriptionsWithSubscriptionCoalescing({
348
- getDeduplicationKey,
349
- rpcSubscriptions
350
- }) {
351
- const cache = /* @__PURE__ */ new Map();
352
- return new Proxy(rpcSubscriptions, {
353
- defineProperty() {
354
- return false;
355
- },
356
- deleteProperty() {
357
- return false;
358
- },
359
- get(target, p, receiver) {
360
- const subscriptionMethod = Reflect.get(target, p, receiver);
361
- if (typeof subscriptionMethod !== "function") {
362
- return subscriptionMethod;
363
- }
364
- return function(...rawParams) {
365
- const deduplicationKey = getDeduplicationKey(p, rawParams);
366
- if (deduplicationKey === void 0) {
367
- return subscriptionMethod(...rawParams);
368
- }
369
- if (cache.has(deduplicationKey)) {
370
- return cache.get(deduplicationKey);
371
- }
372
- const iterableFactory = getCachedAbortableIterableFactory({
373
- getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
374
- getCacheEntryMissingError(deduplicationKey2) {
375
- return new Error(
376
- `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
377
- );
378
- },
379
- getCacheKeyFromInputArgs: () => deduplicationKey,
380
- async onCacheHit(_iterable, _config) {
381
- },
382
- async onCreateIterable(abortSignal, config) {
383
- const pendingSubscription2 = subscriptionMethod(
384
- ...rawParams
385
- );
386
- const iterable = await pendingSubscription2.subscribe({
387
- ...config,
388
- abortSignal
389
- });
390
- registerIterableCleanup2(iterable, () => {
391
- cache.delete(deduplicationKey);
392
- });
393
- return iterable;
394
- }
395
- });
396
- const pendingSubscription = {
397
- async subscribe(...args) {
398
- const iterable = await iterableFactory(...args);
399
- const { abortSignal } = args[0];
400
- let abortPromise;
401
- return {
402
- ...iterable,
403
- async *[Symbol.asyncIterator]() {
404
- abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
405
- abortSignal.addEventListener("abort", () => {
406
- reject(EXPLICIT_ABORT_TOKEN);
407
- });
408
- });
409
- try {
410
- const iterator = iterable[Symbol.asyncIterator]();
411
- while (true) {
412
- const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
413
- if (iteratorResult.done) {
414
- return;
415
- } else {
416
- yield iteratorResult.value;
417
- }
418
- }
419
- } catch (e) {
420
- if (e === EXPLICIT_ABORT_TOKEN) {
421
- return;
422
- }
423
- cache.delete(deduplicationKey);
424
- throw e;
425
- }
426
- }
427
- };
428
- }
429
- };
430
- cache.set(deduplicationKey, pendingSubscription);
431
- return pendingSubscription;
432
- };
433
- }
434
- });
435
- }
436
-
437
- // src/rpc.ts
438
- function createSolanaRpc(config) {
439
- const api = createSolanaRpcApi(DEFAULT_RPC_CONFIG);
440
- return createJsonRpc({
441
- ...config,
442
- api
443
- });
444
- }
445
- function createSolanaRpcSubscriptions(config) {
446
- return pipe(
447
- createJsonSubscriptionRpc({
448
- ...config,
449
- api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
450
- }),
451
- (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
452
- getDeduplicationKey: (...args) => fastStableStringify(args),
453
- rpcSubscriptions
454
- })
455
- );
456
- }
457
- function createSolanaRpcSubscriptions_UNSTABLE(config) {
458
- return createJsonSubscriptionRpc({
459
- ...config,
460
- api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
461
- });
462
- }
463
-
464
- // src/rpc-request-coalescer.ts
465
- function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
466
- let coalescedRequestsByDeduplicationKey;
467
- return async function makeCoalescedHttpRequest(config) {
468
- const { payload, signal } = config;
469
- const deduplicationKey = getDeduplicationKey(payload);
470
- if (deduplicationKey === void 0) {
471
- return await transport(config);
472
- }
473
- if (!coalescedRequestsByDeduplicationKey) {
474
- Promise.resolve().then(() => {
475
- coalescedRequestsByDeduplicationKey = void 0;
476
- });
477
- coalescedRequestsByDeduplicationKey = {};
478
- }
479
- if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
480
- const abortController = new AbortController();
481
- const responsePromise = (async () => {
482
- try {
483
- return await transport({
484
- ...config,
485
- signal: abortController.signal
486
- });
487
- } catch (e) {
488
- if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
489
- return;
490
- }
491
- throw e;
492
- }
493
- })();
494
- coalescedRequestsByDeduplicationKey[deduplicationKey] = {
495
- abortController,
496
- numConsumers: 0,
497
- responsePromise
498
- };
499
- }
500
- const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
501
- coalescedRequest.numConsumers++;
502
- if (signal) {
503
- const responsePromise = coalescedRequest.responsePromise;
504
- return await new Promise((resolve, reject) => {
505
- const handleAbort = (e) => {
506
- signal.removeEventListener("abort", handleAbort);
507
- coalescedRequest.numConsumers -= 1;
508
- if (coalescedRequest.numConsumers === 0) {
509
- const abortController = coalescedRequest.abortController;
510
- abortController.abort();
511
- }
512
- const abortError = new DOMException(e.target.reason, "AbortError");
513
- reject(abortError);
514
- };
515
- signal.addEventListener("abort", handleAbort);
516
- responsePromise.then(resolve).finally(() => {
517
- signal.removeEventListener("abort", handleAbort);
518
- });
519
- });
520
- } else {
521
- return await coalescedRequest.responsePromise;
522
- }
523
- };
524
- }
525
- function isJsonRpcPayload(payload) {
526
- if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
527
- return false;
528
- }
529
- return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
530
- }
531
- function getSolanaRpcPayloadDeduplicationKey(payload) {
532
- return isJsonRpcPayload(payload) ? fastStableStringify([payload.method, payload.params]) : void 0;
533
- }
534
-
535
- // src/rpc-transport.ts
536
- function normalizeHeaders(headers) {
537
- const out = {};
538
- for (const headerName in headers) {
539
- out[headerName.toLowerCase()] = headers[headerName];
540
- }
541
- return out;
542
- }
543
- function createDefaultRpcTransport(config) {
544
- return pipe(
545
- createHttpTransport({
546
- ...config,
547
- headers: {
548
- ...config.headers ? normalizeHeaders(config.headers) : void 0,
549
- ...{
550
- // Keep these headers lowercase so they will override any user-supplied headers above.
551
- "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
552
- }
553
- }
554
- }),
555
- (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
556
- );
557
- }
558
-
559
- // src/rpc-websocket-autopinger.ts
560
- var PING_PAYLOAD = {
561
- jsonrpc: "2.0",
562
- method: "ping"
563
- };
564
- function getWebSocketTransportWithAutoping({
565
- intervalMs,
566
- transport
567
- }) {
568
- const pingableConnections = /* @__PURE__ */ new Map();
569
- return async (...args) => {
570
- const connection = await transport(...args);
571
- let intervalId;
572
- function sendPing() {
573
- connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
574
- }
575
- function restartPingTimer() {
576
- clearInterval(intervalId);
577
- intervalId = setInterval(sendPing, intervalMs);
578
- }
579
- if (pingableConnections.has(connection) === false) {
580
- pingableConnections.set(connection, {
581
- [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
582
- send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
583
- restartPingTimer();
584
- return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
585
- }
586
- });
587
- (async () => {
588
- try {
589
- for await (const _ of connection) {
590
- restartPingTimer();
591
- }
592
- } catch {
593
- } finally {
594
- pingableConnections.delete(connection);
595
- clearInterval(intervalId);
596
- if (handleOffline) {
597
- globalThis.window.removeEventListener("offline", handleOffline);
598
- }
599
- if (handleOnline) {
600
- globalThis.window.removeEventListener("online", handleOnline);
601
- }
602
- }
603
- })();
604
- if (globalThis.navigator.onLine) {
605
- restartPingTimer();
606
- }
607
- let handleOffline;
608
- let handleOnline;
609
- {
610
- handleOffline = () => {
611
- clearInterval(intervalId);
612
- };
613
- handleOnline = () => {
614
- sendPing();
615
- restartPingTimer();
616
- };
617
- globalThis.window.addEventListener("offline", handleOffline);
618
- globalThis.window.addEventListener("online", handleOnline);
619
- }
620
- }
621
- return pingableConnections.get(connection);
622
- };
623
- }
624
-
625
- // src/rpc-websocket-connection-sharding.ts
626
- var NULL_SHARD_CACHE_KEY = Symbol(
627
- __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
628
- );
629
- function getWebSocketTransportWithConnectionSharding({
630
- getShard,
631
- transport
632
- }) {
633
- return getCachedAbortableIterableFactory({
634
- getAbortSignalFromInputArgs: ({ signal }) => signal,
635
- getCacheEntryMissingError(shardKey) {
636
- return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
637
- },
638
- getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
639
- onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
640
- onCreateIterable: (abortSignal, config) => transport({
641
- ...config,
642
- signal: abortSignal
643
- })
644
- });
645
- }
646
-
647
- // src/rpc-websocket-transport.ts
648
- function createDefaultRpcSubscriptionsTransport(config) {
649
- const { getShard, intervalMs, ...rest } = config;
650
- return pipe(
651
- createWebSocketTransport({
652
- ...rest,
653
- sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
654
- 131072
655
- }),
656
- (transport) => getWebSocketTransportWithAutoping({
657
- intervalMs: intervalMs ?? 5e3,
658
- transport
659
- }),
660
- (transport) => getWebSocketTransportWithConnectionSharding({
661
- getShard,
662
- transport
663
- })
664
- );
665
- }
666
-
667
- // src/transaction-confirmation-strategy-blockheight.ts
668
- function createBlockHeightExceedencePromiseFactory({
669
- rpc,
670
- rpcSubscriptions
671
- }) {
672
- return async function getBlockHeightExceedencePromise({
673
- abortSignal: callerAbortSignal,
674
- commitment,
675
- lastValidBlockHeight
676
- }) {
677
- const abortController = new AbortController();
678
- const handleAbort = () => {
679
- abortController.abort();
680
- };
681
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
682
- async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
683
- const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
684
- return {
685
- blockHeight,
686
- differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
687
- };
688
- }
689
- try {
690
- const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
691
- rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
692
- getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
693
- ]);
694
- if (blockHeight <= lastValidBlockHeight) {
695
- let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
696
- for await (const slotNotification of slotNotifications) {
697
- const { slot } = slotNotification;
698
- if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
699
- const {
700
- blockHeight: currentBlockHeight,
701
- differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
702
- } = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
703
- if (currentBlockHeight > lastValidBlockHeight) {
704
- break;
705
- } else {
706
- lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
707
- }
708
- }
709
- }
710
- }
711
- throw new Error(
712
- "The network has progressed past the last block for which this transaction could have been committed."
713
- );
714
- } finally {
715
- abortController.abort();
716
- }
717
- };
718
- }
719
- var NONCE_VALUE_OFFSET = 4 + // version(u32)
720
- 4 + // state(u32)
721
- 32;
722
- function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
723
- return async function getNonceInvalidationPromise({
724
- abortSignal: callerAbortSignal,
725
- commitment,
726
- currentNonceValue,
727
- nonceAccountAddress
728
- }) {
729
- const abortController = new AbortController();
730
- function handleAbort() {
731
- abortController.abort();
732
- }
733
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
734
- const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
735
- const base58Decoder = getBase58Decoder();
736
- const base64Encoder = getBase64Encoder();
737
- function getNonceFromAccountData([base64EncodedBytes]) {
738
- const data = base64Encoder.encode(base64EncodedBytes);
739
- const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
740
- return base58Decoder.decode(nonceValueBytes);
741
- }
742
- const nonceAccountDidAdvancePromise = (async () => {
743
- for await (const accountNotification of accountNotifications) {
744
- const nonceValue = getNonceFromAccountData(accountNotification.value.data);
745
- if (nonceValue !== currentNonceValue) {
746
- throw new Error(
747
- `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
748
- );
749
- }
750
- }
751
- })();
752
- const nonceIsAlreadyInvalidPromise = (async () => {
753
- const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
754
- commitment,
755
- dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
756
- encoding: "base58"
757
- }).send({ abortSignal: abortController.signal });
758
- if (!nonceAccount) {
759
- throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
760
- }
761
- const nonceValue = (
762
- // This works because we asked for the exact slice of data representing the nonce
763
- // value, and furthermore asked for it in `base58` encoding.
764
- nonceAccount.data[0]
765
- );
766
- if (nonceValue !== currentNonceValue) {
767
- throw new Error(
768
- `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
769
- );
770
- } else {
771
- await new Promise(() => {
772
- });
773
- }
774
- })();
775
- try {
776
- return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
777
- } finally {
778
- abortController.abort();
779
- }
780
- };
781
- }
782
-
783
- // src/transaction-confirmation.ts
784
- function createDefaultDurableNonceTransactionConfirmer({
785
- rpc,
786
- rpcSubscriptions
787
- }) {
788
- const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
789
- const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
790
- rpc,
791
- rpcSubscriptions
792
- );
793
- return async function confirmDurableNonceTransaction(config) {
794
- await waitForDurableNonceTransactionConfirmation({
795
- ...config,
796
- getNonceInvalidationPromise,
797
- getRecentSignatureConfirmationPromise
798
- });
799
- };
800
- }
801
- function createDefaultRecentTransactionConfirmer({
802
- rpc,
803
- rpcSubscriptions
804
- }) {
805
- const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
806
- rpc,
807
- rpcSubscriptions
808
- });
809
- const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
810
- rpc,
811
- rpcSubscriptions
812
- );
813
- return async function confirmRecentTransaction(config) {
814
- await waitForRecentTransactionConfirmation({
815
- ...config,
816
- getBlockHeightExceedencePromise,
817
- getRecentSignatureConfirmationPromise
818
- });
819
- };
820
- }
821
- async function waitForDurableNonceTransactionConfirmation(config) {
822
- await raceStrategies(
823
- getSignatureFromTransaction(config.transaction),
824
- config,
825
- function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
826
- return [
827
- getNonceInvalidationPromise({
828
- abortSignal,
829
- commitment,
830
- currentNonceValue: transaction.lifetimeConstraint.nonce,
831
- nonceAccountAddress: transaction.instructions[0].accounts[0].address
832
- })
833
- ];
834
- }
835
- );
836
- }
837
- async function waitForRecentTransactionConfirmation(config) {
838
- await raceStrategies(
839
- getSignatureFromTransaction(config.transaction),
840
- config,
841
- function getSpecificStrategiesForRace({
842
- abortSignal,
843
- commitment,
844
- getBlockHeightExceedencePromise,
845
- transaction
846
- }) {
847
- return [
848
- getBlockHeightExceedencePromise({
849
- abortSignal,
850
- commitment,
851
- lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
852
- })
853
- ];
854
- }
855
- );
856
- }
857
-
858
- // src/send-transaction.ts
859
90
  function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
860
91
  if (
861
92
  // The developer has supplied no value for `preflightCommitment`.
@@ -877,7 +108,7 @@ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, con
877
108
  }
878
109
  return config;
879
110
  }
880
- async function sendTransaction_INTERNAL({
111
+ async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
881
112
  abortSignal,
882
113
  commitment,
883
114
  rpc,
@@ -890,41 +121,7 @@ async function sendTransaction_INTERNAL({
890
121
  encoding: "base64"
891
122
  }).send({ abortSignal });
892
123
  }
893
- function createDefaultDurableNonceTransactionSender({
894
- rpc,
895
- rpcSubscriptions
896
- }) {
897
- const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
898
- rpc,
899
- rpcSubscriptions
900
- });
901
- return async function sendDurableNonceTransaction(transaction, config) {
902
- await sendAndConfirmDurableNonceTransaction({
903
- ...config,
904
- confirmDurableNonceTransaction,
905
- rpc,
906
- transaction
907
- });
908
- };
909
- }
910
- function createDefaultTransactionSender({
911
- rpc,
912
- rpcSubscriptions
913
- }) {
914
- const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
915
- rpc,
916
- rpcSubscriptions
917
- });
918
- return async function sendTransaction(transaction, config) {
919
- await sendAndConfirmTransaction({
920
- ...config,
921
- confirmRecentTransaction,
922
- rpc,
923
- transaction
924
- });
925
- };
926
- }
927
- async function sendAndConfirmDurableNonceTransaction({
124
+ async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
928
125
  abortSignal,
929
126
  commitment,
930
127
  confirmDurableNonceTransaction,
@@ -932,7 +129,7 @@ async function sendAndConfirmDurableNonceTransaction({
932
129
  transaction,
933
130
  ...sendTransactionConfig
934
131
  }) {
935
- const transactionSignature = await sendTransaction_INTERNAL({
132
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
936
133
  ...sendTransactionConfig,
937
134
  abortSignal,
938
135
  commitment,
@@ -946,7 +143,7 @@ async function sendAndConfirmDurableNonceTransaction({
946
143
  });
947
144
  return transactionSignature;
948
145
  }
949
- async function sendAndConfirmTransaction({
146
+ async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
950
147
  abortSignal,
951
148
  commitment,
952
149
  confirmRecentTransaction,
@@ -954,7 +151,7 @@ async function sendAndConfirmTransaction({
954
151
  transaction,
955
152
  ...sendTransactionConfig
956
153
  }) {
957
- const transactionSignature = await sendTransaction_INTERNAL({
154
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
958
155
  ...sendTransactionConfig,
959
156
  abortSignal,
960
157
  commitment,
@@ -969,6 +166,72 @@ async function sendAndConfirmTransaction({
969
166
  return transactionSignature;
970
167
  }
971
168
 
972
- export { createBlockHeightExceedencePromiseFactory, createDefaultAirdropRequester, createDefaultDurableNonceTransactionConfirmer, createDefaultDurableNonceTransactionSender, createDefaultRecentTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createDefaultTransactionSender, createNonceInvalidationPromiseFactory, createRecentSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, decodeTransaction, requestAndConfirmAirdrop, sendAndConfirmDurableNonceTransaction, sendAndConfirmTransaction, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation };
169
+ // src/send-transaction.ts
170
+ function sendTransactionWithoutConfirmingFactory({
171
+ rpc
172
+ }) {
173
+ return async function sendTransactionWithoutConfirming(transaction, config) {
174
+ await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
175
+ ...config,
176
+ rpc,
177
+ transaction
178
+ });
179
+ };
180
+ }
181
+ function sendAndConfirmDurableNonceTransactionFactory({
182
+ rpc,
183
+ rpcSubscriptions
184
+ }) {
185
+ const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
186
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
187
+ rpc,
188
+ rpcSubscriptions
189
+ );
190
+ async function confirmDurableNonceTransaction(config) {
191
+ await waitForDurableNonceTransactionConfirmation({
192
+ ...config,
193
+ getNonceInvalidationPromise,
194
+ getRecentSignatureConfirmationPromise
195
+ });
196
+ }
197
+ return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
198
+ await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
199
+ ...config,
200
+ confirmDurableNonceTransaction,
201
+ rpc,
202
+ transaction
203
+ });
204
+ };
205
+ }
206
+ function sendAndConfirmTransactionFactory({
207
+ rpc,
208
+ rpcSubscriptions
209
+ }) {
210
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
211
+ rpc,
212
+ rpcSubscriptions
213
+ });
214
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
215
+ rpc,
216
+ rpcSubscriptions
217
+ );
218
+ async function confirmRecentTransaction(config) {
219
+ await waitForRecentTransactionConfirmation({
220
+ ...config,
221
+ getBlockHeightExceedencePromise,
222
+ getRecentSignatureConfirmationPromise
223
+ });
224
+ }
225
+ return async function sendAndConfirmTransaction(transaction, config) {
226
+ await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
227
+ ...config,
228
+ confirmRecentTransaction,
229
+ rpc,
230
+ transaction
231
+ });
232
+ };
233
+ }
234
+
235
+ export { airdropFactory, decodeTransaction, sendAndConfirmDurableNonceTransactionFactory, sendAndConfirmTransactionFactory, sendTransactionWithoutConfirmingFactory };
973
236
  //# sourceMappingURL=out.js.map
974
237
  //# sourceMappingURL=index.browser.js.map