@solana/web3.js 2.0.0-experimental.e0b865d → 2.0.0-experimental.e15a66f

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 (39) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1153 -43
  3. package/dist/index.browser.cjs +260 -427
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +205 -419
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +4865 -1992
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +205 -408
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +260 -416
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +205 -408
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +278 -36
  16. package/dist/types/airdrop-internal.d.ts +16 -0
  17. package/dist/types/airdrop-internal.d.ts.map +1 -0
  18. package/dist/types/airdrop.d.ts +12 -0
  19. package/dist/types/airdrop.d.ts.map +1 -0
  20. package/dist/types/decode-transaction.d.ts +9 -0
  21. package/dist/types/decode-transaction.d.ts.map +1 -0
  22. package/dist/types/index.d.ts +12 -3
  23. package/dist/types/index.d.ts.map +1 -0
  24. package/dist/types/send-transaction-internal.d.ts +27 -0
  25. package/dist/types/send-transaction-internal.d.ts.map +1 -0
  26. package/dist/types/send-transaction.d.ts +23 -0
  27. package/dist/types/send-transaction.d.ts.map +1 -0
  28. package/package.json +27 -41
  29. package/dist/types/cached-abortable-iterable.d.ts +0 -11
  30. package/dist/types/rpc-default-config.d.ts +0 -3
  31. package/dist/types/rpc-integer-overflow-error.d.ts +0 -8
  32. package/dist/types/rpc-request-coalescer.d.ts +0 -5
  33. package/dist/types/rpc-request-deduplication.d.ts +0 -2
  34. package/dist/types/rpc-subscription-coalescer.d.ts +0 -10
  35. package/dist/types/rpc-transport.d.ts +0 -4
  36. package/dist/types/rpc-websocket-autopinger.d.ts +0 -8
  37. package/dist/types/rpc-websocket-connection-sharding.d.ts +0 -13
  38. package/dist/types/rpc-websocket-transport.d.ts +0 -13
  39. package/dist/types/rpc.d.ts +0 -7
@@ -1,451 +1,237 @@
1
+ import { fetchJsonParsedAccounts, assertAccountsDecoded, assertAccountsExist } from '@solana/accounts';
2
+ export * from '@solana/accounts';
1
3
  export * from '@solana/addresses';
4
+ export * from '@solana/codecs';
5
+ export * from '@solana/functional';
2
6
  export * from '@solana/instructions';
3
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';
12
+ import { commitmentComparator } from '@solana/rpc-types';
13
+ export * from '@solana/rpc-types';
14
+ export * from '@solana/signers';
15
+ import { getCompiledTransactionDecoder, decompileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';
4
16
  export * from '@solana/transactions';
5
- import { pipe } from '@solana/functional';
6
- import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE } from '@solana/rpc-core';
7
- import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
8
- import fastStableStringify from 'fast-stable-stringify';
17
+ import { createRecentSignatureConfirmationPromiseFactory, createNonceInvalidationPromiseFactory, createBlockHeightExceedencePromiseFactory, waitForRecentTransactionConfirmationUntilTimeout, getTimeoutPromise, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation } from '@solana/transaction-confirmation';
9
18
 
10
- // ../build-scripts/env-shim.ts
11
- var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
19
+ // src/index.ts
12
20
 
13
- // src/rpc-integer-overflow-error.ts
14
- var SolanaJsonRpcIntegerOverflowError = class extends Error {
15
- constructor(methodName, keyPath, value) {
16
- const argPosition = (typeof keyPath[0] === "number" ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;
17
- let ordinal = "";
18
- const lastDigit = argPosition % 10;
19
- const lastTwoDigits = argPosition % 100;
20
- if (lastDigit == 1 && lastTwoDigits != 11) {
21
- ordinal = argPosition + "st";
22
- } else if (lastDigit == 2 && lastTwoDigits != 12) {
23
- ordinal = argPosition + "nd";
24
- } else if (lastDigit == 3 && lastTwoDigits != 13) {
25
- ordinal = argPosition + "rd";
26
- } else {
27
- ordinal = argPosition + "th";
28
- }
29
- const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
30
- super(
31
- `The ${ordinal} 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\`.`
32
- );
33
- this.keyPath = keyPath;
34
- this.methodName = methodName;
35
- this.value = value;
36
- }
37
- get name() {
38
- return "SolanaJsonRpcIntegerOverflowError";
39
- }
40
- };
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,
33
+ commitment,
34
+ signature: airdropTransactionSignature
35
+ });
36
+ return airdropTransactionSignature;
37
+ }
41
38
 
42
- // src/rpc-default-config.ts
43
- var DEFAULT_RPC_CONFIG = {
44
- onIntegerOverflow(methodName, keyPath, value) {
45
- throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
39
+ // src/airdrop.ts
40
+ function airdropFactory({ rpc, rpcSubscriptions }) {
41
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
42
+ rpc,
43
+ rpcSubscriptions
44
+ );
45
+ async function confirmSignatureOnlyTransaction(config) {
46
+ await waitForRecentTransactionConfirmationUntilTimeout({
47
+ ...config,
48
+ getRecentSignatureConfirmationPromise,
49
+ getTimeoutPromise
50
+ });
46
51
  }
47
- };
48
-
49
- // src/cached-abortable-iterable.ts
50
- function registerIterableCleanup(iterable, cleanupFn) {
51
- (async () => {
52
- try {
53
- for await (const _ of iterable)
54
- ;
55
- } catch {
56
- } finally {
57
- cleanupFn();
58
- }
59
- })();
52
+ return async function airdrop(config) {
53
+ return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
54
+ ...config,
55
+ confirmSignatureOnlyTransaction,
56
+ rpc
57
+ });
58
+ };
60
59
  }
61
- function getCachedAbortableIterableFactory({
62
- getAbortSignalFromInputArgs,
63
- getCacheEntryMissingError,
64
- getCacheKeyFromInputArgs,
65
- onCacheHit,
66
- onCreateIterable
67
- }) {
68
- const cache = /* @__PURE__ */ new Map();
69
- function getCacheEntryOrThrow(cacheKey) {
70
- const currentCacheEntry = cache.get(cacheKey);
71
- if (!currentCacheEntry) {
72
- throw getCacheEntryMissingError(cacheKey);
73
- }
74
- return currentCacheEntry;
75
- }
76
- return async (...args) => {
77
- const cacheKey = getCacheKeyFromInputArgs(...args);
78
- const signal = getAbortSignalFromInputArgs(...args);
79
- if (cacheKey === void 0) {
80
- return await onCreateIterable(signal, ...args);
81
- }
82
- const cleanup = () => {
83
- cache.delete(cacheKey);
84
- signal.removeEventListener("abort", handleAbort);
60
+ var compiledTransactionDecoder = void 0;
61
+ async function fetchLookupTables(lookupTableAddresses, rpc, config) {
62
+ const fetchedLookupTables = await fetchJsonParsedAccounts(
63
+ rpc,
64
+ lookupTableAddresses,
65
+ config
66
+ );
67
+ assertAccountsDecoded(fetchedLookupTables);
68
+ assertAccountsExist(fetchedLookupTables);
69
+ return fetchedLookupTables.reduce((acc, lookup) => {
70
+ return {
71
+ ...acc,
72
+ [lookup.address]: lookup.data.addresses
85
73
  };
86
- const handleAbort = () => {
87
- const cacheEntry = getCacheEntryOrThrow(cacheKey);
88
- if (cacheEntry.purgeScheduled !== true) {
89
- cacheEntry.purgeScheduled = true;
90
- globalThis.queueMicrotask(() => {
91
- cacheEntry.purgeScheduled = false;
92
- if (cacheEntry.referenceCount === 0) {
93
- cacheEntry.abortController.abort();
94
- cleanup();
95
- }
96
- });
97
- }
98
- cacheEntry.referenceCount--;
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
+ });
89
+ }
90
+ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
91
+ if (
92
+ // The developer has supplied no value for `preflightCommitment`.
93
+ !config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
94
+ commitmentComparator(
95
+ commitment,
96
+ "finalized"
97
+ /* default value of `preflightCommitment` */
98
+ ) < 0
99
+ ) {
100
+ return {
101
+ ...config,
102
+ // In the common case, it is unlikely that you want to simulate a transaction at
103
+ // `finalized` commitment when your standard of commitment for confirming the
104
+ // transaction is lower. Cap the simulation commitment level to the level of the
105
+ // confirmation commitment.
106
+ preflightCommitment: commitment
99
107
  };
100
- signal.addEventListener("abort", handleAbort);
101
- try {
102
- const cacheEntry = cache.get(cacheKey);
103
- if (!cacheEntry) {
104
- const singletonAbortController = new AbortController();
105
- const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
106
- const newCacheEntry = {
107
- abortController: singletonAbortController,
108
- iterable: newIterablePromise,
109
- purgeScheduled: false,
110
- referenceCount: 1
111
- };
112
- cache.set(cacheKey, newCacheEntry);
113
- const newIterable = await newIterablePromise;
114
- registerIterableCleanup(newIterable, cleanup);
115
- newCacheEntry.iterable = newIterable;
116
- return newIterable;
117
- } else {
118
- cacheEntry.referenceCount++;
119
- const iterableOrIterablePromise = cacheEntry.iterable;
120
- const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
121
- await onCacheHit(cachedIterable, ...args);
122
- return cachedIterable;
123
- }
124
- } catch (e) {
125
- cleanup();
126
- throw e;
127
- }
128
- };
108
+ }
109
+ return config;
129
110
  }
130
-
131
- // src/rpc-subscription-coalescer.ts
132
- var EXPLICIT_ABORT_TOKEN = Symbol(
133
- __DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
134
- );
135
- function registerIterableCleanup2(iterable, cleanupFn) {
136
- (async () => {
137
- try {
138
- for await (const _ of iterable)
139
- ;
140
- } catch {
141
- } finally {
142
- cleanupFn();
143
- }
144
- })();
111
+ async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
112
+ abortSignal,
113
+ commitment,
114
+ rpc,
115
+ transaction,
116
+ ...sendTransactionConfig
117
+ }) {
118
+ const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
119
+ return await rpc.sendTransaction(base64EncodedWireTransaction, {
120
+ ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
121
+ encoding: "base64"
122
+ }).send({ abortSignal });
145
123
  }
146
- function getRpcSubscriptionsWithSubscriptionCoalescing({
147
- getDeduplicationKey,
148
- rpcSubscriptions
124
+ async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
125
+ abortSignal,
126
+ commitment,
127
+ confirmDurableNonceTransaction,
128
+ rpc,
129
+ transaction,
130
+ ...sendTransactionConfig
149
131
  }) {
150
- const cache = /* @__PURE__ */ new Map();
151
- return new Proxy(rpcSubscriptions, {
152
- defineProperty() {
153
- return false;
154
- },
155
- deleteProperty() {
156
- return false;
157
- },
158
- get(target, p, receiver) {
159
- const subscriptionMethod = Reflect.get(target, p, receiver);
160
- if (typeof subscriptionMethod !== "function") {
161
- return subscriptionMethod;
162
- }
163
- return function(...rawParams) {
164
- const deduplicationKey = getDeduplicationKey(p, rawParams);
165
- if (deduplicationKey === void 0) {
166
- return subscriptionMethod(...rawParams);
167
- }
168
- if (cache.has(deduplicationKey)) {
169
- return cache.get(deduplicationKey);
170
- }
171
- const iterableFactory = getCachedAbortableIterableFactory({
172
- getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
173
- getCacheEntryMissingError(deduplicationKey2) {
174
- return new Error(
175
- `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
176
- );
177
- },
178
- getCacheKeyFromInputArgs: () => deduplicationKey,
179
- async onCacheHit(_iterable, _config) {
180
- },
181
- async onCreateIterable(abortSignal, config) {
182
- const pendingSubscription2 = subscriptionMethod(
183
- ...rawParams
184
- );
185
- const iterable = await pendingSubscription2.subscribe({
186
- ...config,
187
- abortSignal
188
- });
189
- registerIterableCleanup2(iterable, () => {
190
- cache.delete(deduplicationKey);
191
- });
192
- return iterable;
193
- }
194
- });
195
- const pendingSubscription = {
196
- async subscribe(...args) {
197
- const iterable = await iterableFactory(...args);
198
- const { abortSignal } = args[0];
199
- let abortPromise;
200
- return {
201
- ...iterable,
202
- async *[Symbol.asyncIterator]() {
203
- abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
204
- abortSignal.addEventListener("abort", () => {
205
- reject(EXPLICIT_ABORT_TOKEN);
206
- });
207
- }));
208
- try {
209
- const iterator = iterable[Symbol.asyncIterator]();
210
- while (true) {
211
- const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
212
- if (iteratorResult.done) {
213
- return;
214
- } else {
215
- yield iteratorResult.value;
216
- }
217
- }
218
- } catch (e) {
219
- if (e === EXPLICIT_ABORT_TOKEN) {
220
- return;
221
- }
222
- cache.delete(deduplicationKey);
223
- throw e;
224
- }
225
- }
226
- };
227
- }
228
- };
229
- cache.set(deduplicationKey, pendingSubscription);
230
- return pendingSubscription;
231
- };
232
- }
132
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
133
+ ...sendTransactionConfig,
134
+ abortSignal,
135
+ commitment,
136
+ rpc,
137
+ transaction
233
138
  });
234
- }
235
-
236
- // src/rpc.ts
237
- function createSolanaRpc(config) {
238
- return createJsonRpc({
239
- ...config,
240
- api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
139
+ await confirmDurableNonceTransaction({
140
+ abortSignal,
141
+ commitment,
142
+ transaction
241
143
  });
144
+ return transactionSignature;
242
145
  }
243
- function createSolanaRpcSubscriptions(config) {
244
- return pipe(
245
- createJsonSubscriptionRpc({
246
- ...config,
247
- api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
248
- }),
249
- (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
250
- getDeduplicationKey: (...args) => fastStableStringify(args),
251
- rpcSubscriptions
252
- })
253
- );
254
- }
255
- function createSolanaRpcSubscriptions_UNSTABLE(config) {
256
- return createJsonSubscriptionRpc({
257
- ...config,
258
- api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
146
+ async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
147
+ abortSignal,
148
+ commitment,
149
+ confirmRecentTransaction,
150
+ rpc,
151
+ transaction,
152
+ ...sendTransactionConfig
153
+ }) {
154
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
155
+ ...sendTransactionConfig,
156
+ abortSignal,
157
+ commitment,
158
+ rpc,
159
+ transaction
160
+ });
161
+ await confirmRecentTransaction({
162
+ abortSignal,
163
+ commitment,
164
+ transaction
259
165
  });
166
+ return transactionSignature;
260
167
  }
261
168
 
262
- // src/rpc-request-coalescer.ts
263
- function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
264
- let coalescedRequestsByDeduplicationKey;
265
- return async function makeCoalescedHttpRequest(config) {
266
- const { payload, signal } = config;
267
- const deduplicationKey = getDeduplicationKey(payload);
268
- if (deduplicationKey === void 0) {
269
- return await transport(config);
270
- }
271
- if (!coalescedRequestsByDeduplicationKey) {
272
- Promise.resolve().then(() => {
273
- coalescedRequestsByDeduplicationKey = void 0;
274
- });
275
- coalescedRequestsByDeduplicationKey = {};
276
- }
277
- if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
278
- const abortController = new AbortController();
279
- coalescedRequestsByDeduplicationKey[deduplicationKey] = {
280
- abortController,
281
- numConsumers: 0,
282
- responsePromise: transport({
283
- ...config,
284
- signal: abortController.signal
285
- })
286
- };
287
- }
288
- const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
289
- coalescedRequest.numConsumers++;
290
- if (signal) {
291
- const responsePromise = coalescedRequest.responsePromise;
292
- return await new Promise((resolve, reject) => {
293
- const handleAbort = (e) => {
294
- signal.removeEventListener("abort", handleAbort);
295
- coalescedRequest.numConsumers -= 1;
296
- if (coalescedRequest.numConsumers === 0) {
297
- const abortController = coalescedRequest.abortController;
298
- abortController.abort();
299
- }
300
- const abortError = new DOMException(e.target.reason, "AbortError");
301
- reject(abortError);
302
- };
303
- signal.addEventListener("abort", handleAbort);
304
- responsePromise.then(resolve).finally(() => {
305
- signal.removeEventListener("abort", handleAbort);
306
- });
307
- });
308
- } else {
309
- return await coalescedRequest.responsePromise;
310
- }
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
+ });
311
179
  };
312
180
  }
313
- function isJsonRpcPayload(payload) {
314
- if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
315
- return false;
316
- }
317
- return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
318
- }
319
- function getSolanaRpcPayloadDeduplicationKey(payload) {
320
- return isJsonRpcPayload(payload) ? fastStableStringify([payload.method, payload.params]) : void 0;
321
- }
322
-
323
- // src/rpc-transport.ts
324
- function normalizeHeaders(headers) {
325
- const out = {};
326
- for (const headerName in headers) {
327
- out[headerName.toLowerCase()] = headers[headerName];
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
+ });
328
196
  }
329
- return out;
330
- }
331
- function createDefaultRpcTransport(config) {
332
- return pipe(
333
- createHttpTransport({
197
+ return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
198
+ await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
334
199
  ...config,
335
- headers: {
336
- ...config.headers ? normalizeHeaders(config.headers) : void 0,
337
- ...{
338
- // Keep these headers lowercase so they will override any user-supplied headers above.
339
- "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
340
- }
341
- }
342
- }),
343
- (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
344
- );
345
- }
346
-
347
- // src/rpc-websocket-autopinger.ts
348
- var PING_PAYLOAD = {
349
- jsonrpc: "2.0",
350
- method: "ping"
351
- };
352
- function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
353
- const pingableConnections = /* @__PURE__ */ new Map();
354
- return async (...args) => {
355
- const connection = await transport(...args);
356
- let intervalId;
357
- function sendPing() {
358
- connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
359
- }
360
- function restartPingTimer() {
361
- clearInterval(intervalId);
362
- intervalId = setInterval(sendPing, intervalMs);
363
- }
364
- if (pingableConnections.has(connection) === false) {
365
- pingableConnections.set(connection, {
366
- [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
367
- send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
368
- restartPingTimer();
369
- return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
370
- }
371
- });
372
- (async () => {
373
- try {
374
- for await (const _ of connection) {
375
- restartPingTimer();
376
- }
377
- } catch {
378
- } finally {
379
- pingableConnections.delete(connection);
380
- clearInterval(intervalId);
381
- if (handleOffline) {
382
- globalThis.window.removeEventListener("offline", handleOffline);
383
- }
384
- if (handleOnline) {
385
- globalThis.window.removeEventListener("online", handleOnline);
386
- }
387
- }
388
- })();
389
- if (globalThis.navigator.onLine) {
390
- restartPingTimer();
391
- }
392
- let handleOffline;
393
- let handleOnline;
394
- {
395
- handleOffline = () => {
396
- clearInterval(intervalId);
397
- };
398
- handleOnline = () => {
399
- sendPing();
400
- restartPingTimer();
401
- };
402
- globalThis.window.addEventListener("offline", handleOffline);
403
- globalThis.window.addEventListener("online", handleOnline);
404
- }
405
- }
406
- return pingableConnections.get(connection);
200
+ confirmDurableNonceTransaction,
201
+ rpc,
202
+ transaction
203
+ });
407
204
  };
408
205
  }
409
-
410
- // src/rpc-websocket-connection-sharding.ts
411
- var NULL_SHARD_CACHE_KEY = Symbol(
412
- __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
413
- );
414
- function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
415
- return getCachedAbortableIterableFactory({
416
- getAbortSignalFromInputArgs: ({ signal }) => signal,
417
- getCacheEntryMissingError(shardKey) {
418
- return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
419
- },
420
- getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
421
- onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
422
- onCreateIterable: (abortSignal, config) => transport({
423
- ...config,
424
- signal: abortSignal
425
- })
206
+ function sendAndConfirmTransactionFactory({
207
+ rpc,
208
+ rpcSubscriptions
209
+ }) {
210
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
211
+ rpc,
212
+ rpcSubscriptions
426
213
  });
427
- }
428
-
429
- // src/rpc-websocket-transport.ts
430
- function createDefaultRpcSubscriptionsTransport(config) {
431
- const { getShard, intervalMs, ...rest } = config;
432
- return pipe(
433
- createWebSocketTransport({
434
- ...rest,
435
- sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
436
- 131072
437
- }),
438
- (transport) => getWebSocketTransportWithAutoping({
439
- intervalMs: intervalMs ?? 5e3,
440
- transport
441
- }),
442
- (transport) => getWebSocketTransportWithConnectionSharding({
443
- getShard,
444
- transport
445
- })
214
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
215
+ rpc,
216
+ rpcSubscriptions
446
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
+ };
447
233
  }
448
234
 
449
- export { createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE };
235
+ export { airdropFactory, decodeTransaction, sendAndConfirmDurableNonceTransactionFactory, sendAndConfirmTransactionFactory, sendTransactionWithoutConfirmingFactory };
450
236
  //# sourceMappingURL=out.js.map
451
237
  //# sourceMappingURL=index.browser.js.map