@solana/web3.js 2.0.0-experimental.a8f1f88 → 2.0.0-experimental.a9e6db3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/dist/index.browser.cjs +572 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +566 -20
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2196 -853
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +555 -20
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +563 -18
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +555 -20
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +52 -32
- package/dist/types/airdrop-confirmer.d.ts +20 -0
- package/dist/types/airdrop.d.ts +18 -0
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
- package/dist/types/rpc-websocket-transport.d.ts +6 -0
- package/dist/types/rpc.d.ts +2 -1
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +10 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
- package/dist/types/transaction-confirmation.d.ts +37 -0
- package/package.json +15 -13
package/dist/index.browser.js
CHANGED
|
@@ -1,12 +1,160 @@
|
|
|
1
1
|
export * from '@solana/addresses';
|
|
2
2
|
export * from '@solana/instructions';
|
|
3
3
|
export * from '@solana/keys';
|
|
4
|
+
import { getSignatureFromTransaction } from '@solana/transactions';
|
|
4
5
|
export * from '@solana/transactions';
|
|
5
|
-
import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi } from '@solana/rpc-core';
|
|
6
|
+
import { commitmentComparator, createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE } from '@solana/rpc-core';
|
|
7
|
+
import { pipe } from '@solana/functional';
|
|
6
8
|
import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
|
|
7
9
|
import fastStableStringify from 'fast-stable-stringify';
|
|
10
|
+
import { base64, base58 } from '@metaplex-foundation/umi-serializers';
|
|
8
11
|
|
|
9
|
-
//
|
|
12
|
+
// ../build-scripts/env-shim.ts
|
|
13
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
14
|
+
|
|
15
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
16
|
+
async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
|
|
17
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
18
|
+
callerAbortSignal.throwIfAborted();
|
|
19
|
+
const abortController = new AbortController();
|
|
20
|
+
function handleAbort() {
|
|
21
|
+
abortController.abort();
|
|
22
|
+
}
|
|
23
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
24
|
+
try {
|
|
25
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
26
|
+
...config,
|
|
27
|
+
abortSignal: abortController.signal
|
|
28
|
+
});
|
|
29
|
+
return await Promise.race([
|
|
30
|
+
getRecentSignatureConfirmationPromise({
|
|
31
|
+
abortSignal: abortController.signal,
|
|
32
|
+
commitment,
|
|
33
|
+
signature
|
|
34
|
+
}),
|
|
35
|
+
...specificStrategies
|
|
36
|
+
]);
|
|
37
|
+
} finally {
|
|
38
|
+
abortController.abort();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
42
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
43
|
+
abortSignal: callerAbortSignal,
|
|
44
|
+
commitment,
|
|
45
|
+
signature
|
|
46
|
+
}) {
|
|
47
|
+
const abortController = new AbortController();
|
|
48
|
+
function handleAbort() {
|
|
49
|
+
abortController.abort();
|
|
50
|
+
}
|
|
51
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
52
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
53
|
+
const signatureDidCommitPromise = (async () => {
|
|
54
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
55
|
+
if (signatureStatusNotification.value.err) {
|
|
56
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
57
|
+
cause: signatureStatusNotification.value.err
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})();
|
|
64
|
+
const signatureStatusLookupPromise = (async () => {
|
|
65
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
66
|
+
const signatureStatus = signatureStatusResults[0];
|
|
67
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
68
|
+
return;
|
|
69
|
+
} else {
|
|
70
|
+
await new Promise(() => {
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
try {
|
|
75
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
76
|
+
} finally {
|
|
77
|
+
abortController.abort();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
83
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
84
|
+
return await new Promise((_, reject) => {
|
|
85
|
+
const handleAbort = (e) => {
|
|
86
|
+
clearTimeout(timeoutId);
|
|
87
|
+
const abortError = new DOMException(e.target.reason, "AbortError");
|
|
88
|
+
reject(abortError);
|
|
89
|
+
};
|
|
90
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
91
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
92
|
+
const startMs = performance.now();
|
|
93
|
+
const timeoutId = (
|
|
94
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
95
|
+
// elapsed time instead of active time.
|
|
96
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
const elapsedMs = performance.now() - startMs;
|
|
99
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
100
|
+
}, timeoutMs)
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/airdrop-confirmer.ts
|
|
106
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
107
|
+
rpc,
|
|
108
|
+
rpcSubscriptions
|
|
109
|
+
}) {
|
|
110
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
111
|
+
rpc,
|
|
112
|
+
rpcSubscriptions
|
|
113
|
+
);
|
|
114
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
115
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
116
|
+
...config,
|
|
117
|
+
getRecentSignatureConfirmationPromise,
|
|
118
|
+
getTimeoutPromise
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
123
|
+
await raceStrategies(
|
|
124
|
+
config.signature,
|
|
125
|
+
config,
|
|
126
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
127
|
+
return [
|
|
128
|
+
getTimeoutPromise2({
|
|
129
|
+
abortSignal,
|
|
130
|
+
commitment
|
|
131
|
+
})
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/airdrop.ts
|
|
138
|
+
async function requestAndConfirmAirdrop({
|
|
139
|
+
abortSignal,
|
|
140
|
+
commitment,
|
|
141
|
+
lamports,
|
|
142
|
+
recipientAddress,
|
|
143
|
+
rpc,
|
|
144
|
+
rpcSubscriptions
|
|
145
|
+
}) {
|
|
146
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
147
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
148
|
+
rpc,
|
|
149
|
+
rpcSubscriptions
|
|
150
|
+
});
|
|
151
|
+
await confirmSignatureOnlyTransaction({
|
|
152
|
+
abortSignal,
|
|
153
|
+
commitment,
|
|
154
|
+
signature: airdropTransactionSignature
|
|
155
|
+
});
|
|
156
|
+
return airdropTransactionSignature;
|
|
157
|
+
}
|
|
10
158
|
|
|
11
159
|
// src/rpc-integer-overflow-error.ts
|
|
12
160
|
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
@@ -44,6 +192,193 @@ var DEFAULT_RPC_CONFIG = {
|
|
|
44
192
|
}
|
|
45
193
|
};
|
|
46
194
|
|
|
195
|
+
// src/cached-abortable-iterable.ts
|
|
196
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
197
|
+
(async () => {
|
|
198
|
+
try {
|
|
199
|
+
for await (const _ of iterable)
|
|
200
|
+
;
|
|
201
|
+
} catch {
|
|
202
|
+
} finally {
|
|
203
|
+
cleanupFn();
|
|
204
|
+
}
|
|
205
|
+
})();
|
|
206
|
+
}
|
|
207
|
+
function getCachedAbortableIterableFactory({
|
|
208
|
+
getAbortSignalFromInputArgs,
|
|
209
|
+
getCacheEntryMissingError,
|
|
210
|
+
getCacheKeyFromInputArgs,
|
|
211
|
+
onCacheHit,
|
|
212
|
+
onCreateIterable
|
|
213
|
+
}) {
|
|
214
|
+
const cache = /* @__PURE__ */ new Map();
|
|
215
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
216
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
217
|
+
if (!currentCacheEntry) {
|
|
218
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
219
|
+
}
|
|
220
|
+
return currentCacheEntry;
|
|
221
|
+
}
|
|
222
|
+
return async (...args) => {
|
|
223
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
224
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
225
|
+
if (cacheKey === void 0) {
|
|
226
|
+
return await onCreateIterable(signal, ...args);
|
|
227
|
+
}
|
|
228
|
+
const cleanup = () => {
|
|
229
|
+
cache.delete(cacheKey);
|
|
230
|
+
signal.removeEventListener("abort", handleAbort);
|
|
231
|
+
};
|
|
232
|
+
const handleAbort = () => {
|
|
233
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
234
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
235
|
+
cacheEntry.purgeScheduled = true;
|
|
236
|
+
globalThis.queueMicrotask(() => {
|
|
237
|
+
cacheEntry.purgeScheduled = false;
|
|
238
|
+
if (cacheEntry.referenceCount === 0) {
|
|
239
|
+
cacheEntry.abortController.abort();
|
|
240
|
+
cleanup();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
cacheEntry.referenceCount--;
|
|
245
|
+
};
|
|
246
|
+
signal.addEventListener("abort", handleAbort);
|
|
247
|
+
try {
|
|
248
|
+
const cacheEntry = cache.get(cacheKey);
|
|
249
|
+
if (!cacheEntry) {
|
|
250
|
+
const singletonAbortController = new AbortController();
|
|
251
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
252
|
+
const newCacheEntry = {
|
|
253
|
+
abortController: singletonAbortController,
|
|
254
|
+
iterable: newIterablePromise,
|
|
255
|
+
purgeScheduled: false,
|
|
256
|
+
referenceCount: 1
|
|
257
|
+
};
|
|
258
|
+
cache.set(cacheKey, newCacheEntry);
|
|
259
|
+
const newIterable = await newIterablePromise;
|
|
260
|
+
registerIterableCleanup(newIterable, cleanup);
|
|
261
|
+
newCacheEntry.iterable = newIterable;
|
|
262
|
+
return newIterable;
|
|
263
|
+
} else {
|
|
264
|
+
cacheEntry.referenceCount++;
|
|
265
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
266
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
267
|
+
await onCacheHit(cachedIterable, ...args);
|
|
268
|
+
return cachedIterable;
|
|
269
|
+
}
|
|
270
|
+
} catch (e) {
|
|
271
|
+
cleanup();
|
|
272
|
+
throw e;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/rpc-subscription-coalescer.ts
|
|
278
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
279
|
+
__DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
|
|
280
|
+
);
|
|
281
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
282
|
+
(async () => {
|
|
283
|
+
try {
|
|
284
|
+
for await (const _ of iterable)
|
|
285
|
+
;
|
|
286
|
+
} catch {
|
|
287
|
+
} finally {
|
|
288
|
+
cleanupFn();
|
|
289
|
+
}
|
|
290
|
+
})();
|
|
291
|
+
}
|
|
292
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
293
|
+
getDeduplicationKey,
|
|
294
|
+
rpcSubscriptions
|
|
295
|
+
}) {
|
|
296
|
+
const cache = /* @__PURE__ */ new Map();
|
|
297
|
+
return new Proxy(rpcSubscriptions, {
|
|
298
|
+
defineProperty() {
|
|
299
|
+
return false;
|
|
300
|
+
},
|
|
301
|
+
deleteProperty() {
|
|
302
|
+
return false;
|
|
303
|
+
},
|
|
304
|
+
get(target, p, receiver) {
|
|
305
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
306
|
+
if (typeof subscriptionMethod !== "function") {
|
|
307
|
+
return subscriptionMethod;
|
|
308
|
+
}
|
|
309
|
+
return function(...rawParams) {
|
|
310
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
311
|
+
if (deduplicationKey === void 0) {
|
|
312
|
+
return subscriptionMethod(...rawParams);
|
|
313
|
+
}
|
|
314
|
+
if (cache.has(deduplicationKey)) {
|
|
315
|
+
return cache.get(deduplicationKey);
|
|
316
|
+
}
|
|
317
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
318
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
319
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
320
|
+
return new Error(
|
|
321
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
322
|
+
);
|
|
323
|
+
},
|
|
324
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
325
|
+
async onCacheHit(_iterable, _config) {
|
|
326
|
+
},
|
|
327
|
+
async onCreateIterable(abortSignal, config) {
|
|
328
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
329
|
+
...rawParams
|
|
330
|
+
);
|
|
331
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
332
|
+
...config,
|
|
333
|
+
abortSignal
|
|
334
|
+
});
|
|
335
|
+
registerIterableCleanup2(iterable, () => {
|
|
336
|
+
cache.delete(deduplicationKey);
|
|
337
|
+
});
|
|
338
|
+
return iterable;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
const pendingSubscription = {
|
|
342
|
+
async subscribe(...args) {
|
|
343
|
+
const iterable = await iterableFactory(...args);
|
|
344
|
+
const { abortSignal } = args[0];
|
|
345
|
+
let abortPromise;
|
|
346
|
+
return {
|
|
347
|
+
...iterable,
|
|
348
|
+
async *[Symbol.asyncIterator]() {
|
|
349
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
350
|
+
abortSignal.addEventListener("abort", () => {
|
|
351
|
+
reject(EXPLICIT_ABORT_TOKEN);
|
|
352
|
+
});
|
|
353
|
+
}));
|
|
354
|
+
try {
|
|
355
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
356
|
+
while (true) {
|
|
357
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
358
|
+
if (iteratorResult.done) {
|
|
359
|
+
return;
|
|
360
|
+
} else {
|
|
361
|
+
yield iteratorResult.value;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
} catch (e) {
|
|
365
|
+
if (e === EXPLICIT_ABORT_TOKEN) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
cache.delete(deduplicationKey);
|
|
369
|
+
throw e;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
376
|
+
return pendingSubscription;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
47
382
|
// src/rpc.ts
|
|
48
383
|
function createSolanaRpc(config) {
|
|
49
384
|
return createJsonRpc({
|
|
@@ -52,9 +387,21 @@ function createSolanaRpc(config) {
|
|
|
52
387
|
});
|
|
53
388
|
}
|
|
54
389
|
function createSolanaRpcSubscriptions(config) {
|
|
390
|
+
return pipe(
|
|
391
|
+
createJsonSubscriptionRpc({
|
|
392
|
+
...config,
|
|
393
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
394
|
+
}),
|
|
395
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
396
|
+
getDeduplicationKey: (...args) => fastStableStringify(args),
|
|
397
|
+
rpcSubscriptions
|
|
398
|
+
})
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
55
402
|
return createJsonSubscriptionRpc({
|
|
56
403
|
...config,
|
|
57
|
-
api:
|
|
404
|
+
api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
58
405
|
});
|
|
59
406
|
}
|
|
60
407
|
|
|
@@ -109,13 +456,14 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
109
456
|
}
|
|
110
457
|
};
|
|
111
458
|
}
|
|
112
|
-
function
|
|
459
|
+
function isJsonRpcPayload(payload) {
|
|
113
460
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
117
|
-
return fastStableStringify([payload.method, payload.params]);
|
|
461
|
+
return false;
|
|
118
462
|
}
|
|
463
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
464
|
+
}
|
|
465
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
466
|
+
return isJsonRpcPayload(payload) ? fastStableStringify([payload.method, payload.params]) : void 0;
|
|
119
467
|
}
|
|
120
468
|
|
|
121
469
|
// src/rpc-transport.ts
|
|
@@ -127,7 +475,7 @@ function normalizeHeaders(headers) {
|
|
|
127
475
|
return out;
|
|
128
476
|
}
|
|
129
477
|
function createDefaultRpcTransport(config) {
|
|
130
|
-
return
|
|
478
|
+
return pipe(
|
|
131
479
|
createHttpTransport({
|
|
132
480
|
...config,
|
|
133
481
|
headers: {
|
|
@@ -138,7 +486,7 @@ function createDefaultRpcTransport(config) {
|
|
|
138
486
|
}
|
|
139
487
|
}
|
|
140
488
|
}),
|
|
141
|
-
getSolanaRpcPayloadDeduplicationKey
|
|
489
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
142
490
|
);
|
|
143
491
|
}
|
|
144
492
|
|
|
@@ -152,11 +500,12 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
|
152
500
|
return async (...args) => {
|
|
153
501
|
const connection = await transport(...args);
|
|
154
502
|
let intervalId;
|
|
503
|
+
function sendPing() {
|
|
504
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
505
|
+
}
|
|
155
506
|
function restartPingTimer() {
|
|
156
507
|
clearInterval(intervalId);
|
|
157
|
-
intervalId = setInterval(
|
|
158
|
-
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
159
|
-
}, intervalMs);
|
|
508
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
160
509
|
}
|
|
161
510
|
if (pingableConnections.has(connection) === false) {
|
|
162
511
|
pingableConnections.set(connection, {
|
|
@@ -175,27 +524,224 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
|
175
524
|
} finally {
|
|
176
525
|
pingableConnections.delete(connection);
|
|
177
526
|
clearInterval(intervalId);
|
|
527
|
+
if (handleOffline) {
|
|
528
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
529
|
+
}
|
|
530
|
+
if (handleOnline) {
|
|
531
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
532
|
+
}
|
|
178
533
|
}
|
|
179
534
|
})();
|
|
180
|
-
|
|
535
|
+
if (globalThis.navigator.onLine) {
|
|
536
|
+
restartPingTimer();
|
|
537
|
+
}
|
|
538
|
+
let handleOffline;
|
|
539
|
+
let handleOnline;
|
|
540
|
+
{
|
|
541
|
+
handleOffline = () => {
|
|
542
|
+
clearInterval(intervalId);
|
|
543
|
+
};
|
|
544
|
+
handleOnline = () => {
|
|
545
|
+
sendPing();
|
|
546
|
+
restartPingTimer();
|
|
547
|
+
};
|
|
548
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
549
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
550
|
+
}
|
|
181
551
|
}
|
|
182
552
|
return pingableConnections.get(connection);
|
|
183
553
|
};
|
|
184
554
|
}
|
|
185
555
|
|
|
556
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
557
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
558
|
+
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
559
|
+
);
|
|
560
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
561
|
+
return getCachedAbortableIterableFactory({
|
|
562
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
563
|
+
getCacheEntryMissingError(shardKey) {
|
|
564
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
565
|
+
},
|
|
566
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
567
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
568
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
569
|
+
...config,
|
|
570
|
+
signal: abortSignal
|
|
571
|
+
})
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
186
575
|
// src/rpc-websocket-transport.ts
|
|
187
576
|
function createDefaultRpcSubscriptionsTransport(config) {
|
|
188
|
-
const { intervalMs, ...rest } = config;
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
transport: createWebSocketTransport({
|
|
577
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
578
|
+
return pipe(
|
|
579
|
+
createWebSocketTransport({
|
|
192
580
|
...rest,
|
|
193
581
|
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
194
582
|
131072
|
|
583
|
+
}),
|
|
584
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
585
|
+
intervalMs: intervalMs ?? 5e3,
|
|
586
|
+
transport
|
|
587
|
+
}),
|
|
588
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
589
|
+
getShard,
|
|
590
|
+
transport
|
|
195
591
|
})
|
|
196
|
-
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
596
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
597
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
598
|
+
const abortController = new AbortController();
|
|
599
|
+
function handleAbort() {
|
|
600
|
+
abortController.abort();
|
|
601
|
+
}
|
|
602
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
603
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
604
|
+
try {
|
|
605
|
+
for await (const slotNotification of slotNotifications) {
|
|
606
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
607
|
+
throw new Error(
|
|
608
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
} finally {
|
|
613
|
+
abortController.abort();
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
618
|
+
4 + // state(u32)
|
|
619
|
+
32;
|
|
620
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
621
|
+
return async function getNonceInvalidationPromise({
|
|
622
|
+
abortSignal: callerAbortSignal,
|
|
623
|
+
commitment,
|
|
624
|
+
currentNonceValue,
|
|
625
|
+
nonceAccountAddress
|
|
626
|
+
}) {
|
|
627
|
+
const abortController = new AbortController();
|
|
628
|
+
function handleAbort() {
|
|
629
|
+
abortController.abort();
|
|
630
|
+
}
|
|
631
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
632
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
633
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
634
|
+
const data = base64.serialize(base64EncodedBytes);
|
|
635
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
636
|
+
return base58.deserialize(nonceValueBytes)[0];
|
|
637
|
+
}
|
|
638
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
639
|
+
for await (const accountNotification of accountNotifications) {
|
|
640
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
641
|
+
if (nonceValue !== currentNonceValue) {
|
|
642
|
+
throw new Error(
|
|
643
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
})();
|
|
648
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
649
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
650
|
+
commitment,
|
|
651
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
652
|
+
encoding: "base58"
|
|
653
|
+
}).send({ abortSignal: abortController.signal });
|
|
654
|
+
if (!nonceAccount) {
|
|
655
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
656
|
+
}
|
|
657
|
+
const nonceValue = (
|
|
658
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
659
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
660
|
+
nonceAccount.data[0]
|
|
661
|
+
);
|
|
662
|
+
if (nonceValue !== currentNonceValue) {
|
|
663
|
+
throw new Error(
|
|
664
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
665
|
+
);
|
|
666
|
+
} else {
|
|
667
|
+
await new Promise(() => {
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
})();
|
|
671
|
+
try {
|
|
672
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
673
|
+
} finally {
|
|
674
|
+
abortController.abort();
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// src/transaction-confirmation.ts
|
|
680
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
681
|
+
rpc,
|
|
682
|
+
rpcSubscriptions
|
|
683
|
+
}) {
|
|
684
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
685
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
686
|
+
rpc,
|
|
687
|
+
rpcSubscriptions
|
|
688
|
+
);
|
|
689
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
690
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
691
|
+
...config,
|
|
692
|
+
getNonceInvalidationPromise,
|
|
693
|
+
getRecentSignatureConfirmationPromise
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function createDefaultRecentTransactionConfirmer({
|
|
698
|
+
rpc,
|
|
699
|
+
rpcSubscriptions
|
|
700
|
+
}) {
|
|
701
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
702
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
703
|
+
rpc,
|
|
704
|
+
rpcSubscriptions
|
|
705
|
+
);
|
|
706
|
+
return async function confirmRecentTransaction(config) {
|
|
707
|
+
await waitForRecentTransactionConfirmation({
|
|
708
|
+
...config,
|
|
709
|
+
getBlockHeightExceedencePromise,
|
|
710
|
+
getRecentSignatureConfirmationPromise
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
715
|
+
await raceStrategies(
|
|
716
|
+
getSignatureFromTransaction(config.transaction),
|
|
717
|
+
config,
|
|
718
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
719
|
+
return [
|
|
720
|
+
getNonceInvalidationPromise({
|
|
721
|
+
abortSignal,
|
|
722
|
+
commitment,
|
|
723
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
724
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
725
|
+
})
|
|
726
|
+
];
|
|
727
|
+
}
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
731
|
+
await raceStrategies(
|
|
732
|
+
getSignatureFromTransaction(config.transaction),
|
|
733
|
+
config,
|
|
734
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
735
|
+
return [
|
|
736
|
+
getBlockHeightExceedencePromise({
|
|
737
|
+
abortSignal,
|
|
738
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
739
|
+
})
|
|
740
|
+
];
|
|
741
|
+
}
|
|
742
|
+
);
|
|
197
743
|
}
|
|
198
744
|
|
|
199
|
-
export { createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createSolanaRpc, createSolanaRpcSubscriptions };
|
|
745
|
+
export { createBlockHeightExceedencePromiseFactory, createDefaultDurableNonceTransactionConfirmer, createDefaultRecentTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createNonceInvalidationPromiseFactory, createRecentSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, requestAndConfirmAirdrop, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation };
|
|
200
746
|
//# sourceMappingURL=out.js.map
|
|
201
747
|
//# sourceMappingURL=index.browser.js.map
|