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