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