@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.node.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,631 +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
|
-
{
|
|
562
|
-
restartPingTimer();
|
|
563
|
-
}
|
|
564
|
-
let handleOffline;
|
|
565
|
-
let handleOnline;
|
|
566
|
-
}
|
|
567
|
-
return pingableConnections.get(connection);
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// src/rpc-websocket-connection-sharding.ts
|
|
572
|
-
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
573
|
-
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
574
|
-
);
|
|
575
|
-
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
576
|
-
return getCachedAbortableIterableFactory({
|
|
577
|
-
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
578
|
-
getCacheEntryMissingError(shardKey) {
|
|
579
|
-
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
580
|
-
},
|
|
581
|
-
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
582
|
-
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
583
|
-
onCreateIterable: (abortSignal, config) => transport({
|
|
584
|
-
...config,
|
|
585
|
-
signal: abortSignal
|
|
586
|
-
})
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// src/rpc-websocket-transport.ts
|
|
591
|
-
function createDefaultRpcSubscriptionsTransport(config) {
|
|
592
|
-
const { getShard, intervalMs, ...rest } = config;
|
|
593
|
-
return functional.pipe(
|
|
594
|
-
rpcTransport.createWebSocketTransport({
|
|
595
|
-
...rest,
|
|
596
|
-
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
597
|
-
131072
|
|
598
|
-
}),
|
|
599
|
-
(transport) => getWebSocketTransportWithAutoping({
|
|
600
|
-
intervalMs: intervalMs ?? 5e3,
|
|
601
|
-
transport
|
|
602
|
-
}),
|
|
603
|
-
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
604
|
-
getShard,
|
|
605
|
-
transport
|
|
606
|
-
})
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// src/transaction-confirmation-strategy-blockheight.ts
|
|
611
|
-
function createBlockHeightExceedencePromiseFactory({
|
|
612
|
-
rpc,
|
|
613
|
-
rpcSubscriptions
|
|
614
|
-
}) {
|
|
615
|
-
return async function getBlockHeightExceedencePromise({
|
|
616
|
-
abortSignal: callerAbortSignal,
|
|
617
|
-
commitment,
|
|
618
|
-
lastValidBlockHeight
|
|
619
|
-
}) {
|
|
620
|
-
const abortController = new AbortController();
|
|
621
|
-
const handleAbort = () => {
|
|
622
|
-
abortController.abort();
|
|
623
|
-
};
|
|
624
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
625
|
-
async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
|
|
626
|
-
const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
|
|
627
|
-
return {
|
|
628
|
-
blockHeight,
|
|
629
|
-
differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
try {
|
|
633
|
-
const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
|
|
634
|
-
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
|
|
635
|
-
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
|
|
636
|
-
]);
|
|
637
|
-
if (blockHeight <= lastValidBlockHeight) {
|
|
638
|
-
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
|
|
639
|
-
for await (const slotNotification of slotNotifications) {
|
|
640
|
-
const { slot } = slotNotification;
|
|
641
|
-
if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
|
|
642
|
-
const {
|
|
643
|
-
blockHeight: currentBlockHeight,
|
|
644
|
-
differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
|
|
645
|
-
} = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
|
|
646
|
-
if (currentBlockHeight > lastValidBlockHeight) {
|
|
647
|
-
break;
|
|
648
|
-
} else {
|
|
649
|
-
lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
throw new Error(
|
|
655
|
-
"The network has progressed past the last block for which this transaction could have been committed."
|
|
656
|
-
);
|
|
657
|
-
} finally {
|
|
658
|
-
abortController.abort();
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
663
|
-
4 + // state(u32)
|
|
664
|
-
32;
|
|
665
|
-
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
666
|
-
return async function getNonceInvalidationPromise({
|
|
667
|
-
abortSignal: callerAbortSignal,
|
|
668
|
-
commitment,
|
|
669
|
-
currentNonceValue,
|
|
670
|
-
nonceAccountAddress
|
|
671
|
-
}) {
|
|
672
|
-
const abortController = new AbortController();
|
|
673
|
-
function handleAbort() {
|
|
674
|
-
abortController.abort();
|
|
675
|
-
}
|
|
676
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
677
|
-
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
678
|
-
const base58Decoder = codecsStrings.getBase58Decoder();
|
|
679
|
-
const base64Encoder = codecsStrings.getBase64Encoder();
|
|
680
|
-
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
681
|
-
const data = base64Encoder.encode(base64EncodedBytes);
|
|
682
|
-
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
683
|
-
return base58Decoder.decode(nonceValueBytes);
|
|
684
|
-
}
|
|
685
|
-
const nonceAccountDidAdvancePromise = (async () => {
|
|
686
|
-
for await (const accountNotification of accountNotifications) {
|
|
687
|
-
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
688
|
-
if (nonceValue !== currentNonceValue) {
|
|
689
|
-
throw new Error(
|
|
690
|
-
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
691
|
-
);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
})();
|
|
695
|
-
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
696
|
-
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
697
|
-
commitment,
|
|
698
|
-
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
699
|
-
encoding: "base58"
|
|
700
|
-
}).send({ abortSignal: abortController.signal });
|
|
701
|
-
if (!nonceAccount) {
|
|
702
|
-
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
703
|
-
}
|
|
704
|
-
const nonceValue = (
|
|
705
|
-
// This works because we asked for the exact slice of data representing the nonce
|
|
706
|
-
// value, and furthermore asked for it in `base58` encoding.
|
|
707
|
-
nonceAccount.data[0]
|
|
708
|
-
);
|
|
709
|
-
if (nonceValue !== currentNonceValue) {
|
|
710
|
-
throw new Error(
|
|
711
|
-
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
712
|
-
);
|
|
713
|
-
} else {
|
|
714
|
-
await new Promise(() => {
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
})();
|
|
718
|
-
try {
|
|
719
|
-
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
720
|
-
} finally {
|
|
721
|
-
abortController.abort();
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// src/transaction-confirmation.ts
|
|
727
|
-
function createDefaultDurableNonceTransactionConfirmer({
|
|
728
|
-
rpc,
|
|
729
|
-
rpcSubscriptions
|
|
730
|
-
}) {
|
|
731
|
-
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
732
|
-
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
38
|
+
// src/airdrop.ts
|
|
39
|
+
function airdropFactory({ rpc, rpcSubscriptions }) {
|
|
40
|
+
const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
|
|
733
41
|
rpc,
|
|
734
42
|
rpcSubscriptions
|
|
735
43
|
);
|
|
736
|
-
|
|
737
|
-
await
|
|
44
|
+
async function confirmSignatureOnlyTransaction(config) {
|
|
45
|
+
await transactionConfirmation.waitForRecentTransactionConfirmationUntilTimeout({
|
|
738
46
|
...config,
|
|
739
|
-
|
|
740
|
-
|
|
47
|
+
getRecentSignatureConfirmationPromise,
|
|
48
|
+
getTimeoutPromise: transactionConfirmation.getTimeoutPromise
|
|
741
49
|
});
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
rpc,
|
|
746
|
-
rpcSubscriptions
|
|
747
|
-
}) {
|
|
748
|
-
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
749
|
-
rpc,
|
|
750
|
-
rpcSubscriptions
|
|
751
|
-
});
|
|
752
|
-
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
753
|
-
rpc,
|
|
754
|
-
rpcSubscriptions
|
|
755
|
-
);
|
|
756
|
-
return async function confirmRecentTransaction(config) {
|
|
757
|
-
await waitForRecentTransactionConfirmation({
|
|
50
|
+
}
|
|
51
|
+
return async function airdrop(config) {
|
|
52
|
+
return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
758
53
|
...config,
|
|
759
|
-
|
|
760
|
-
|
|
54
|
+
confirmSignatureOnlyTransaction,
|
|
55
|
+
rpc
|
|
761
56
|
});
|
|
762
57
|
};
|
|
763
58
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
getNonceInvalidationPromise({
|
|
771
|
-
abortSignal,
|
|
772
|
-
commitment,
|
|
773
|
-
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
774
|
-
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
775
|
-
})
|
|
776
|
-
];
|
|
777
|
-
}
|
|
778
|
-
);
|
|
779
|
-
}
|
|
780
|
-
async function waitForRecentTransactionConfirmation(config) {
|
|
781
|
-
await raceStrategies(
|
|
782
|
-
transactions.getSignatureFromTransaction(config.transaction),
|
|
783
|
-
config,
|
|
784
|
-
function getSpecificStrategiesForRace({
|
|
785
|
-
abortSignal,
|
|
786
|
-
commitment,
|
|
787
|
-
getBlockHeightExceedencePromise,
|
|
788
|
-
transaction
|
|
789
|
-
}) {
|
|
790
|
-
return [
|
|
791
|
-
getBlockHeightExceedencePromise({
|
|
792
|
-
abortSignal,
|
|
793
|
-
commitment,
|
|
794
|
-
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
795
|
-
})
|
|
796
|
-
];
|
|
797
|
-
}
|
|
59
|
+
var compiledTransactionDecoder = void 0;
|
|
60
|
+
async function fetchLookupTables(lookupTableAddresses, rpc, config) {
|
|
61
|
+
const fetchedLookupTables = await accounts.fetchJsonParsedAccounts(
|
|
62
|
+
rpc,
|
|
63
|
+
lookupTableAddresses,
|
|
64
|
+
config
|
|
798
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
|
+
});
|
|
799
88
|
}
|
|
800
|
-
|
|
801
|
-
// src/send-transaction.ts
|
|
802
89
|
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
803
90
|
if (
|
|
804
91
|
// The developer has supplied no value for `preflightCommitment`.
|
|
@@ -820,7 +107,7 @@ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, con
|
|
|
820
107
|
}
|
|
821
108
|
return config;
|
|
822
109
|
}
|
|
823
|
-
async function
|
|
110
|
+
async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
824
111
|
abortSignal,
|
|
825
112
|
commitment,
|
|
826
113
|
rpc,
|
|
@@ -833,41 +120,7 @@ async function sendTransaction_INTERNAL({
|
|
|
833
120
|
encoding: "base64"
|
|
834
121
|
}).send({ abortSignal });
|
|
835
122
|
}
|
|
836
|
-
function
|
|
837
|
-
rpc,
|
|
838
|
-
rpcSubscriptions
|
|
839
|
-
}) {
|
|
840
|
-
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
841
|
-
rpc,
|
|
842
|
-
rpcSubscriptions
|
|
843
|
-
});
|
|
844
|
-
return async function sendDurableNonceTransaction(transaction, config) {
|
|
845
|
-
await sendAndConfirmDurableNonceTransaction({
|
|
846
|
-
...config,
|
|
847
|
-
confirmDurableNonceTransaction,
|
|
848
|
-
rpc,
|
|
849
|
-
transaction
|
|
850
|
-
});
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
function createDefaultTransactionSender({
|
|
854
|
-
rpc,
|
|
855
|
-
rpcSubscriptions
|
|
856
|
-
}) {
|
|
857
|
-
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
858
|
-
rpc,
|
|
859
|
-
rpcSubscriptions
|
|
860
|
-
});
|
|
861
|
-
return async function sendTransaction(transaction, config) {
|
|
862
|
-
await sendAndConfirmTransaction({
|
|
863
|
-
...config,
|
|
864
|
-
confirmRecentTransaction,
|
|
865
|
-
rpc,
|
|
866
|
-
transaction
|
|
867
|
-
});
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
async function sendAndConfirmDurableNonceTransaction({
|
|
123
|
+
async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
871
124
|
abortSignal,
|
|
872
125
|
commitment,
|
|
873
126
|
confirmDurableNonceTransaction,
|
|
@@ -875,7 +128,7 @@ async function sendAndConfirmDurableNonceTransaction({
|
|
|
875
128
|
transaction,
|
|
876
129
|
...sendTransactionConfig
|
|
877
130
|
}) {
|
|
878
|
-
const transactionSignature = await
|
|
131
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
879
132
|
...sendTransactionConfig,
|
|
880
133
|
abortSignal,
|
|
881
134
|
commitment,
|
|
@@ -889,7 +142,7 @@ async function sendAndConfirmDurableNonceTransaction({
|
|
|
889
142
|
});
|
|
890
143
|
return transactionSignature;
|
|
891
144
|
}
|
|
892
|
-
async function
|
|
145
|
+
async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
893
146
|
abortSignal,
|
|
894
147
|
commitment,
|
|
895
148
|
confirmRecentTransaction,
|
|
@@ -897,7 +150,7 @@ async function sendAndConfirmTransaction({
|
|
|
897
150
|
transaction,
|
|
898
151
|
...sendTransactionConfig
|
|
899
152
|
}) {
|
|
900
|
-
const transactionSignature = await
|
|
153
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
901
154
|
...sendTransactionConfig,
|
|
902
155
|
abortSignal,
|
|
903
156
|
commitment,
|
|
@@ -912,24 +165,77 @@ async function sendAndConfirmTransaction({
|
|
|
912
165
|
return transactionSignature;
|
|
913
166
|
}
|
|
914
167
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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;
|
|
933
239
|
Object.keys(accounts).forEach(function (k) {
|
|
934
240
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
935
241
|
enumerable: true,
|
|
@@ -942,6 +248,12 @@ Object.keys(addresses).forEach(function (k) {
|
|
|
942
248
|
get: function () { return addresses[k]; }
|
|
943
249
|
});
|
|
944
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
|
+
});
|
|
945
257
|
Object.keys(functional).forEach(function (k) {
|
|
946
258
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
947
259
|
enumerable: true,
|
|
@@ -960,12 +272,42 @@ Object.keys(keys).forEach(function (k) {
|
|
|
960
272
|
get: function () { return keys[k]; }
|
|
961
273
|
});
|
|
962
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
|
+
});
|
|
963
299
|
Object.keys(rpcTypes).forEach(function (k) {
|
|
964
300
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
965
301
|
enumerable: true,
|
|
966
302
|
get: function () { return rpcTypes[k]; }
|
|
967
303
|
});
|
|
968
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
|
+
});
|
|
969
311
|
Object.keys(transactions).forEach(function (k) {
|
|
970
312
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
971
313
|
enumerable: true,
|