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