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