@solana/web3.js 2.0.0-experimental.acab173 → 2.0.0-experimental.ad9c23c

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