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