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