@solana/web3.js 2.0.0-experimental.7d44763 → 2.0.0-experimental.7d67615
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 +1153 -43
- package/dist/index.browser.cjs +238 -627
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +179 -609
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +5352 -2813
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +179 -598
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +238 -616
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +179 -598
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +277 -55
- 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 +12 -0
- package/dist/types/airdrop.d.ts.map +1 -0
- 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 +12 -7
- package/dist/types/index.d.ts.map +1 -0
- 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 +23 -0
- package/dist/types/send-transaction.d.ts.map +1 -0
- package/package.json +24 -39
- package/dist/types/cached-abortable-iterable.d.ts +0 -11
- package/dist/types/rpc-default-config.d.ts +0 -3
- package/dist/types/rpc-integer-overflow-error.d.ts +0 -8
- package/dist/types/rpc-request-coalescer.d.ts +0 -5
- package/dist/types/rpc-request-deduplication.d.ts +0 -2
- package/dist/types/rpc-subscription-coalescer.d.ts +0 -10
- package/dist/types/rpc-transport.d.ts +0 -4
- package/dist/types/rpc-websocket-autopinger.d.ts +0 -8
- package/dist/types/rpc-websocket-connection-sharding.d.ts +0 -13
- package/dist/types/rpc-websocket-transport.d.ts +0 -13
- package/dist/types/rpc.d.ts +0 -7
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +0 -10
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +0 -15
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +0 -13
- package/dist/types/transaction-confirmation.d.ts +0 -39
package/dist/index.browser.js
CHANGED
|
@@ -1,605 +1,184 @@
|
|
|
1
|
+
import { fetchJsonParsedAccounts, assertAccountsDecoded, assertAccountsExist } from '@solana/accounts';
|
|
2
|
+
export * from '@solana/accounts';
|
|
1
3
|
export * from '@solana/addresses';
|
|
4
|
+
export * from '@solana/codecs';
|
|
5
|
+
export * from '@solana/functional';
|
|
2
6
|
export * from '@solana/instructions';
|
|
3
7
|
export * from '@solana/keys';
|
|
4
|
-
|
|
8
|
+
export * from '@solana/programs';
|
|
9
|
+
export * from '@solana/rpc';
|
|
10
|
+
export * from '@solana/rpc-parsed-types';
|
|
11
|
+
export * from '@solana/rpc-subscriptions';
|
|
12
|
+
import { commitmentComparator } from '@solana/rpc-types';
|
|
13
|
+
export * from '@solana/rpc-types';
|
|
14
|
+
export * from '@solana/signers';
|
|
15
|
+
import { getCompiledTransactionDecoder, decompileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';
|
|
5
16
|
export * from '@solana/transactions';
|
|
6
|
-
import {
|
|
7
|
-
import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE, commitmentComparator } from '@solana/rpc-core';
|
|
8
|
-
import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
|
|
9
|
-
import fastStableStringify from 'fast-stable-stringify';
|
|
10
|
-
import { base64, base58 } from '@metaplex-foundation/umi-serializers';
|
|
17
|
+
import { createRecentSignatureConfirmationPromiseFactory, createNonceInvalidationPromiseFactory, createBlockHeightExceedencePromiseFactory, waitForRecentTransactionConfirmationUntilTimeout, getTimeoutPromise, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation } from '@solana/transaction-confirmation';
|
|
11
18
|
|
|
12
|
-
//
|
|
13
|
-
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
19
|
+
// src/index.ts
|
|
14
20
|
|
|
15
|
-
// src/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ordinal = argPosition + "st";
|
|
24
|
-
} else if (lastDigit == 2 && lastTwoDigits != 12) {
|
|
25
|
-
ordinal = argPosition + "nd";
|
|
26
|
-
} else if (lastDigit == 3 && lastTwoDigits != 13) {
|
|
27
|
-
ordinal = argPosition + "rd";
|
|
28
|
-
} else {
|
|
29
|
-
ordinal = argPosition + "th";
|
|
30
|
-
}
|
|
31
|
-
const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
|
|
32
|
-
super(
|
|
33
|
-
`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\`.`
|
|
34
|
-
);
|
|
35
|
-
this.keyPath = keyPath;
|
|
36
|
-
this.methodName = methodName;
|
|
37
|
-
this.value = value;
|
|
38
|
-
}
|
|
39
|
-
get name() {
|
|
40
|
-
return "SolanaJsonRpcIntegerOverflowError";
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// src/rpc-default-config.ts
|
|
45
|
-
var DEFAULT_RPC_CONFIG = {
|
|
46
|
-
onIntegerOverflow(methodName, keyPath, value) {
|
|
47
|
-
throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// src/cached-abortable-iterable.ts
|
|
52
|
-
function registerIterableCleanup(iterable, cleanupFn) {
|
|
53
|
-
(async () => {
|
|
54
|
-
try {
|
|
55
|
-
for await (const _ of iterable)
|
|
56
|
-
;
|
|
57
|
-
} catch {
|
|
58
|
-
} finally {
|
|
59
|
-
cleanupFn();
|
|
60
|
-
}
|
|
61
|
-
})();
|
|
62
|
-
}
|
|
63
|
-
function getCachedAbortableIterableFactory({
|
|
64
|
-
getAbortSignalFromInputArgs,
|
|
65
|
-
getCacheEntryMissingError,
|
|
66
|
-
getCacheKeyFromInputArgs,
|
|
67
|
-
onCacheHit,
|
|
68
|
-
onCreateIterable
|
|
69
|
-
}) {
|
|
70
|
-
const cache = /* @__PURE__ */ new Map();
|
|
71
|
-
function getCacheEntryOrThrow(cacheKey) {
|
|
72
|
-
const currentCacheEntry = cache.get(cacheKey);
|
|
73
|
-
if (!currentCacheEntry) {
|
|
74
|
-
throw getCacheEntryMissingError(cacheKey);
|
|
75
|
-
}
|
|
76
|
-
return currentCacheEntry;
|
|
77
|
-
}
|
|
78
|
-
return async (...args) => {
|
|
79
|
-
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
80
|
-
const signal = getAbortSignalFromInputArgs(...args);
|
|
81
|
-
if (cacheKey === void 0) {
|
|
82
|
-
return await onCreateIterable(signal, ...args);
|
|
83
|
-
}
|
|
84
|
-
const cleanup = () => {
|
|
85
|
-
cache.delete(cacheKey);
|
|
86
|
-
signal.removeEventListener("abort", handleAbort);
|
|
87
|
-
};
|
|
88
|
-
const handleAbort = () => {
|
|
89
|
-
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
90
|
-
if (cacheEntry.purgeScheduled !== true) {
|
|
91
|
-
cacheEntry.purgeScheduled = true;
|
|
92
|
-
globalThis.queueMicrotask(() => {
|
|
93
|
-
cacheEntry.purgeScheduled = false;
|
|
94
|
-
if (cacheEntry.referenceCount === 0) {
|
|
95
|
-
cacheEntry.abortController.abort();
|
|
96
|
-
cleanup();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
cacheEntry.referenceCount--;
|
|
101
|
-
};
|
|
102
|
-
signal.addEventListener("abort", handleAbort);
|
|
103
|
-
try {
|
|
104
|
-
const cacheEntry = cache.get(cacheKey);
|
|
105
|
-
if (!cacheEntry) {
|
|
106
|
-
const singletonAbortController = new AbortController();
|
|
107
|
-
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
108
|
-
const newCacheEntry = {
|
|
109
|
-
abortController: singletonAbortController,
|
|
110
|
-
iterable: newIterablePromise,
|
|
111
|
-
purgeScheduled: false,
|
|
112
|
-
referenceCount: 1
|
|
113
|
-
};
|
|
114
|
-
cache.set(cacheKey, newCacheEntry);
|
|
115
|
-
const newIterable = await newIterablePromise;
|
|
116
|
-
registerIterableCleanup(newIterable, cleanup);
|
|
117
|
-
newCacheEntry.iterable = newIterable;
|
|
118
|
-
return newIterable;
|
|
119
|
-
} else {
|
|
120
|
-
cacheEntry.referenceCount++;
|
|
121
|
-
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
122
|
-
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
123
|
-
await onCacheHit(cachedIterable, ...args);
|
|
124
|
-
return cachedIterable;
|
|
125
|
-
}
|
|
126
|
-
} catch (e) {
|
|
127
|
-
cleanup();
|
|
128
|
-
throw e;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/rpc-subscription-coalescer.ts
|
|
134
|
-
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
135
|
-
__DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
|
|
136
|
-
);
|
|
137
|
-
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
138
|
-
(async () => {
|
|
139
|
-
try {
|
|
140
|
-
for await (const _ of iterable)
|
|
141
|
-
;
|
|
142
|
-
} catch {
|
|
143
|
-
} finally {
|
|
144
|
-
cleanupFn();
|
|
145
|
-
}
|
|
146
|
-
})();
|
|
147
|
-
}
|
|
148
|
-
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
149
|
-
getDeduplicationKey,
|
|
150
|
-
rpcSubscriptions
|
|
21
|
+
// src/airdrop-internal.ts
|
|
22
|
+
async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
23
|
+
abortSignal,
|
|
24
|
+
commitment,
|
|
25
|
+
confirmSignatureOnlyTransaction,
|
|
26
|
+
lamports,
|
|
27
|
+
recipientAddress,
|
|
28
|
+
rpc
|
|
151
29
|
}) {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
deleteProperty() {
|
|
158
|
-
return false;
|
|
159
|
-
},
|
|
160
|
-
get(target, p, receiver) {
|
|
161
|
-
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
162
|
-
if (typeof subscriptionMethod !== "function") {
|
|
163
|
-
return subscriptionMethod;
|
|
164
|
-
}
|
|
165
|
-
return function(...rawParams) {
|
|
166
|
-
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
167
|
-
if (deduplicationKey === void 0) {
|
|
168
|
-
return subscriptionMethod(...rawParams);
|
|
169
|
-
}
|
|
170
|
-
if (cache.has(deduplicationKey)) {
|
|
171
|
-
return cache.get(deduplicationKey);
|
|
172
|
-
}
|
|
173
|
-
const iterableFactory = getCachedAbortableIterableFactory({
|
|
174
|
-
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
175
|
-
getCacheEntryMissingError(deduplicationKey2) {
|
|
176
|
-
return new Error(
|
|
177
|
-
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
178
|
-
);
|
|
179
|
-
},
|
|
180
|
-
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
181
|
-
async onCacheHit(_iterable, _config) {
|
|
182
|
-
},
|
|
183
|
-
async onCreateIterable(abortSignal, config) {
|
|
184
|
-
const pendingSubscription2 = subscriptionMethod(
|
|
185
|
-
...rawParams
|
|
186
|
-
);
|
|
187
|
-
const iterable = await pendingSubscription2.subscribe({
|
|
188
|
-
...config,
|
|
189
|
-
abortSignal
|
|
190
|
-
});
|
|
191
|
-
registerIterableCleanup2(iterable, () => {
|
|
192
|
-
cache.delete(deduplicationKey);
|
|
193
|
-
});
|
|
194
|
-
return iterable;
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
const pendingSubscription = {
|
|
198
|
-
async subscribe(...args) {
|
|
199
|
-
const iterable = await iterableFactory(...args);
|
|
200
|
-
const { abortSignal } = args[0];
|
|
201
|
-
let abortPromise;
|
|
202
|
-
return {
|
|
203
|
-
...iterable,
|
|
204
|
-
async *[Symbol.asyncIterator]() {
|
|
205
|
-
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
206
|
-
abortSignal.addEventListener("abort", () => {
|
|
207
|
-
reject(EXPLICIT_ABORT_TOKEN);
|
|
208
|
-
});
|
|
209
|
-
}));
|
|
210
|
-
try {
|
|
211
|
-
const iterator = iterable[Symbol.asyncIterator]();
|
|
212
|
-
while (true) {
|
|
213
|
-
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
214
|
-
if (iteratorResult.done) {
|
|
215
|
-
return;
|
|
216
|
-
} else {
|
|
217
|
-
yield iteratorResult.value;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
} catch (e) {
|
|
221
|
-
if (e === EXPLICIT_ABORT_TOKEN) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
cache.delete(deduplicationKey);
|
|
225
|
-
throw e;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
cache.set(deduplicationKey, pendingSubscription);
|
|
232
|
-
return pendingSubscription;
|
|
233
|
-
};
|
|
234
|
-
}
|
|
30
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
31
|
+
await confirmSignatureOnlyTransaction({
|
|
32
|
+
abortSignal,
|
|
33
|
+
commitment,
|
|
34
|
+
signature: airdropTransactionSignature
|
|
235
35
|
});
|
|
36
|
+
return airdropTransactionSignature;
|
|
236
37
|
}
|
|
237
38
|
|
|
238
|
-
// src/
|
|
239
|
-
function
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
function createSolanaRpcSubscriptions(config) {
|
|
246
|
-
return pipe(
|
|
247
|
-
createJsonSubscriptionRpc({
|
|
248
|
-
...config,
|
|
249
|
-
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
250
|
-
}),
|
|
251
|
-
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
252
|
-
getDeduplicationKey: (...args) => fastStableStringify(args),
|
|
253
|
-
rpcSubscriptions
|
|
254
|
-
})
|
|
39
|
+
// src/airdrop.ts
|
|
40
|
+
function airdropFactory({ rpc, rpcSubscriptions }) {
|
|
41
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
42
|
+
rpc,
|
|
43
|
+
rpcSubscriptions
|
|
255
44
|
);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/rpc-request-coalescer.ts
|
|
265
|
-
function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
266
|
-
let coalescedRequestsByDeduplicationKey;
|
|
267
|
-
return async function makeCoalescedHttpRequest(config) {
|
|
268
|
-
const { payload, signal } = config;
|
|
269
|
-
const deduplicationKey = getDeduplicationKey(payload);
|
|
270
|
-
if (deduplicationKey === void 0) {
|
|
271
|
-
return await transport(config);
|
|
272
|
-
}
|
|
273
|
-
if (!coalescedRequestsByDeduplicationKey) {
|
|
274
|
-
Promise.resolve().then(() => {
|
|
275
|
-
coalescedRequestsByDeduplicationKey = void 0;
|
|
276
|
-
});
|
|
277
|
-
coalescedRequestsByDeduplicationKey = {};
|
|
278
|
-
}
|
|
279
|
-
if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
|
|
280
|
-
const abortController = new AbortController();
|
|
281
|
-
coalescedRequestsByDeduplicationKey[deduplicationKey] = {
|
|
282
|
-
abortController,
|
|
283
|
-
numConsumers: 0,
|
|
284
|
-
responsePromise: transport({
|
|
285
|
-
...config,
|
|
286
|
-
signal: abortController.signal
|
|
287
|
-
})
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
|
|
291
|
-
coalescedRequest.numConsumers++;
|
|
292
|
-
if (signal) {
|
|
293
|
-
const responsePromise = coalescedRequest.responsePromise;
|
|
294
|
-
return await new Promise((resolve, reject) => {
|
|
295
|
-
const handleAbort = (e) => {
|
|
296
|
-
signal.removeEventListener("abort", handleAbort);
|
|
297
|
-
coalescedRequest.numConsumers -= 1;
|
|
298
|
-
if (coalescedRequest.numConsumers === 0) {
|
|
299
|
-
const abortController = coalescedRequest.abortController;
|
|
300
|
-
abortController.abort();
|
|
301
|
-
}
|
|
302
|
-
const abortError = new DOMException(e.target.reason, "AbortError");
|
|
303
|
-
reject(abortError);
|
|
304
|
-
};
|
|
305
|
-
signal.addEventListener("abort", handleAbort);
|
|
306
|
-
responsePromise.then(resolve).finally(() => {
|
|
307
|
-
signal.removeEventListener("abort", handleAbort);
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
} else {
|
|
311
|
-
return await coalescedRequest.responsePromise;
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
function isJsonRpcPayload(payload) {
|
|
316
|
-
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
320
|
-
}
|
|
321
|
-
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
322
|
-
return isJsonRpcPayload(payload) ? fastStableStringify([payload.method, payload.params]) : void 0;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// src/rpc-transport.ts
|
|
326
|
-
function normalizeHeaders(headers) {
|
|
327
|
-
const out = {};
|
|
328
|
-
for (const headerName in headers) {
|
|
329
|
-
out[headerName.toLowerCase()] = headers[headerName];
|
|
45
|
+
async function confirmSignatureOnlyTransaction(config) {
|
|
46
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
47
|
+
...config,
|
|
48
|
+
getRecentSignatureConfirmationPromise,
|
|
49
|
+
getTimeoutPromise
|
|
50
|
+
});
|
|
330
51
|
}
|
|
331
|
-
return
|
|
332
|
-
|
|
333
|
-
function createDefaultRpcTransport(config) {
|
|
334
|
-
return pipe(
|
|
335
|
-
createHttpTransport({
|
|
52
|
+
return async function airdrop(config) {
|
|
53
|
+
return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
336
54
|
...config,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// Keep these headers lowercase so they will override any user-supplied headers above.
|
|
341
|
-
"solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}),
|
|
345
|
-
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// src/rpc-websocket-autopinger.ts
|
|
350
|
-
var PING_PAYLOAD = {
|
|
351
|
-
jsonrpc: "2.0",
|
|
352
|
-
method: "ping"
|
|
353
|
-
};
|
|
354
|
-
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
355
|
-
const pingableConnections = /* @__PURE__ */ new Map();
|
|
356
|
-
return async (...args) => {
|
|
357
|
-
const connection = await transport(...args);
|
|
358
|
-
let intervalId;
|
|
359
|
-
function sendPing() {
|
|
360
|
-
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
361
|
-
}
|
|
362
|
-
function restartPingTimer() {
|
|
363
|
-
clearInterval(intervalId);
|
|
364
|
-
intervalId = setInterval(sendPing, intervalMs);
|
|
365
|
-
}
|
|
366
|
-
if (pingableConnections.has(connection) === false) {
|
|
367
|
-
pingableConnections.set(connection, {
|
|
368
|
-
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
369
|
-
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
370
|
-
restartPingTimer();
|
|
371
|
-
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
(async () => {
|
|
375
|
-
try {
|
|
376
|
-
for await (const _ of connection) {
|
|
377
|
-
restartPingTimer();
|
|
378
|
-
}
|
|
379
|
-
} catch {
|
|
380
|
-
} finally {
|
|
381
|
-
pingableConnections.delete(connection);
|
|
382
|
-
clearInterval(intervalId);
|
|
383
|
-
if (handleOffline) {
|
|
384
|
-
globalThis.window.removeEventListener("offline", handleOffline);
|
|
385
|
-
}
|
|
386
|
-
if (handleOnline) {
|
|
387
|
-
globalThis.window.removeEventListener("online", handleOnline);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
})();
|
|
391
|
-
if (globalThis.navigator.onLine) {
|
|
392
|
-
restartPingTimer();
|
|
393
|
-
}
|
|
394
|
-
let handleOffline;
|
|
395
|
-
let handleOnline;
|
|
396
|
-
{
|
|
397
|
-
handleOffline = () => {
|
|
398
|
-
clearInterval(intervalId);
|
|
399
|
-
};
|
|
400
|
-
handleOnline = () => {
|
|
401
|
-
sendPing();
|
|
402
|
-
restartPingTimer();
|
|
403
|
-
};
|
|
404
|
-
globalThis.window.addEventListener("offline", handleOffline);
|
|
405
|
-
globalThis.window.addEventListener("online", handleOnline);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return pingableConnections.get(connection);
|
|
55
|
+
confirmSignatureOnlyTransaction,
|
|
56
|
+
rpc
|
|
57
|
+
});
|
|
409
58
|
};
|
|
410
59
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
return getCachedAbortableIterableFactory({
|
|
418
|
-
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
419
|
-
getCacheEntryMissingError(shardKey) {
|
|
420
|
-
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
421
|
-
},
|
|
422
|
-
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
423
|
-
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
424
|
-
onCreateIterable: (abortSignal, config) => transport({
|
|
425
|
-
...config,
|
|
426
|
-
signal: abortSignal
|
|
427
|
-
})
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// src/rpc-websocket-transport.ts
|
|
432
|
-
function createDefaultRpcSubscriptionsTransport(config) {
|
|
433
|
-
const { getShard, intervalMs, ...rest } = config;
|
|
434
|
-
return pipe(
|
|
435
|
-
createWebSocketTransport({
|
|
436
|
-
...rest,
|
|
437
|
-
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
438
|
-
131072
|
|
439
|
-
}),
|
|
440
|
-
(transport) => getWebSocketTransportWithAutoping({
|
|
441
|
-
intervalMs: intervalMs ?? 5e3,
|
|
442
|
-
transport
|
|
443
|
-
}),
|
|
444
|
-
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
445
|
-
getShard,
|
|
446
|
-
transport
|
|
447
|
-
})
|
|
60
|
+
var compiledTransactionDecoder = void 0;
|
|
61
|
+
async function fetchLookupTables(lookupTableAddresses, rpc, config) {
|
|
62
|
+
const fetchedLookupTables = await fetchJsonParsedAccounts(
|
|
63
|
+
rpc,
|
|
64
|
+
lookupTableAddresses,
|
|
65
|
+
config
|
|
448
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
|
+
});
|
|
449
89
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
};
|
|
90
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
91
|
+
if (
|
|
92
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
93
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
94
|
+
commitmentComparator(
|
|
95
|
+
commitment,
|
|
96
|
+
"finalized"
|
|
97
|
+
/* default value of `preflightCommitment` */
|
|
98
|
+
) < 0
|
|
99
|
+
) {
|
|
100
|
+
return {
|
|
101
|
+
...config,
|
|
102
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
103
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
104
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
105
|
+
// confirmation commitment.
|
|
106
|
+
preflightCommitment: commitment
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return config;
|
|
472
110
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
111
|
+
async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
112
|
+
abortSignal,
|
|
113
|
+
commitment,
|
|
114
|
+
rpc,
|
|
115
|
+
transaction,
|
|
116
|
+
...sendTransactionConfig
|
|
117
|
+
}) {
|
|
118
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
119
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
120
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
121
|
+
encoding: "base64"
|
|
122
|
+
}).send({ abortSignal });
|
|
123
|
+
}
|
|
124
|
+
async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
125
|
+
abortSignal,
|
|
126
|
+
commitment,
|
|
127
|
+
confirmDurableNonceTransaction,
|
|
128
|
+
rpc,
|
|
129
|
+
transaction,
|
|
130
|
+
...sendTransactionConfig
|
|
131
|
+
}) {
|
|
132
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
133
|
+
...sendTransactionConfig,
|
|
134
|
+
abortSignal,
|
|
479
135
|
commitment,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
490
|
-
const data = base64.serialize(base64EncodedBytes);
|
|
491
|
-
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
492
|
-
return base58.deserialize(nonceValueBytes)[0];
|
|
493
|
-
}
|
|
494
|
-
const nonceAccountDidAdvancePromise = (async () => {
|
|
495
|
-
for await (const accountNotification of accountNotifications) {
|
|
496
|
-
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
497
|
-
if (nonceValue !== currentNonceValue) {
|
|
498
|
-
throw new Error(
|
|
499
|
-
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
})();
|
|
504
|
-
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
505
|
-
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
506
|
-
commitment,
|
|
507
|
-
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
508
|
-
encoding: "base58"
|
|
509
|
-
}).send({ abortSignal: abortController.signal });
|
|
510
|
-
if (!nonceAccount) {
|
|
511
|
-
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
512
|
-
}
|
|
513
|
-
const nonceValue = (
|
|
514
|
-
// This works because we asked for the exact slice of data representing the nonce
|
|
515
|
-
// value, and furthermore asked for it in `base58` encoding.
|
|
516
|
-
nonceAccount.data[0]
|
|
517
|
-
);
|
|
518
|
-
if (nonceValue !== currentNonceValue) {
|
|
519
|
-
throw new Error(
|
|
520
|
-
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
521
|
-
);
|
|
522
|
-
} else {
|
|
523
|
-
await new Promise(() => {
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
})();
|
|
527
|
-
try {
|
|
528
|
-
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
529
|
-
} finally {
|
|
530
|
-
abortController.abort();
|
|
531
|
-
}
|
|
532
|
-
};
|
|
136
|
+
rpc,
|
|
137
|
+
transaction
|
|
138
|
+
});
|
|
139
|
+
await confirmDurableNonceTransaction({
|
|
140
|
+
abortSignal,
|
|
141
|
+
commitment,
|
|
142
|
+
transaction
|
|
143
|
+
});
|
|
144
|
+
return transactionSignature;
|
|
533
145
|
}
|
|
534
|
-
function
|
|
535
|
-
|
|
536
|
-
|
|
146
|
+
async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
147
|
+
abortSignal,
|
|
148
|
+
commitment,
|
|
149
|
+
confirmRecentTransaction,
|
|
150
|
+
rpc,
|
|
151
|
+
transaction,
|
|
152
|
+
...sendTransactionConfig
|
|
153
|
+
}) {
|
|
154
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
155
|
+
...sendTransactionConfig,
|
|
156
|
+
abortSignal,
|
|
537
157
|
commitment,
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
548
|
-
if (signatureStatusNotification.value.err) {
|
|
549
|
-
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
550
|
-
cause: signatureStatusNotification.value.err
|
|
551
|
-
});
|
|
552
|
-
} else {
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
})();
|
|
557
|
-
const signatureStatusLookupPromise = (async () => {
|
|
558
|
-
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
559
|
-
const signatureStatus = signatureStatusResults[0];
|
|
560
|
-
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
561
|
-
return;
|
|
562
|
-
} else {
|
|
563
|
-
await new Promise(() => {
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
})();
|
|
567
|
-
try {
|
|
568
|
-
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
569
|
-
} finally {
|
|
570
|
-
abortController.abort();
|
|
571
|
-
}
|
|
572
|
-
};
|
|
158
|
+
rpc,
|
|
159
|
+
transaction
|
|
160
|
+
});
|
|
161
|
+
await confirmRecentTransaction({
|
|
162
|
+
abortSignal,
|
|
163
|
+
commitment,
|
|
164
|
+
transaction
|
|
165
|
+
});
|
|
166
|
+
return transactionSignature;
|
|
573
167
|
}
|
|
574
168
|
|
|
575
|
-
// src/transaction
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
function handleAbort() {
|
|
582
|
-
abortController.abort();
|
|
583
|
-
}
|
|
584
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
585
|
-
try {
|
|
586
|
-
const specificStrategies = getSpecificStrategiesForRace({
|
|
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({
|
|
587
175
|
...config,
|
|
588
|
-
|
|
176
|
+
rpc,
|
|
177
|
+
transaction
|
|
589
178
|
});
|
|
590
|
-
|
|
591
|
-
getRecentSignatureConfirmationPromise({
|
|
592
|
-
abortSignal: abortController.signal,
|
|
593
|
-
commitment,
|
|
594
|
-
signature
|
|
595
|
-
}),
|
|
596
|
-
...specificStrategies
|
|
597
|
-
]);
|
|
598
|
-
} finally {
|
|
599
|
-
abortController.abort();
|
|
600
|
-
}
|
|
179
|
+
};
|
|
601
180
|
}
|
|
602
|
-
function
|
|
181
|
+
function sendAndConfirmDurableNonceTransactionFactory({
|
|
603
182
|
rpc,
|
|
604
183
|
rpcSubscriptions
|
|
605
184
|
}) {
|
|
@@ -608,60 +187,51 @@ function createDefaultDurableNonceTransactionConfirmer({
|
|
|
608
187
|
rpc,
|
|
609
188
|
rpcSubscriptions
|
|
610
189
|
);
|
|
611
|
-
|
|
190
|
+
async function confirmDurableNonceTransaction(config) {
|
|
612
191
|
await waitForDurableNonceTransactionConfirmation({
|
|
613
192
|
...config,
|
|
614
193
|
getNonceInvalidationPromise,
|
|
615
194
|
getRecentSignatureConfirmationPromise
|
|
616
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
|
+
});
|
|
617
204
|
};
|
|
618
205
|
}
|
|
619
|
-
function
|
|
206
|
+
function sendAndConfirmTransactionFactory({
|
|
620
207
|
rpc,
|
|
621
208
|
rpcSubscriptions
|
|
622
209
|
}) {
|
|
623
|
-
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(
|
|
210
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
211
|
+
rpc,
|
|
212
|
+
rpcSubscriptions
|
|
213
|
+
});
|
|
624
214
|
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
625
215
|
rpc,
|
|
626
216
|
rpcSubscriptions
|
|
627
217
|
);
|
|
628
|
-
|
|
218
|
+
async function confirmRecentTransaction(config) {
|
|
629
219
|
await waitForRecentTransactionConfirmation({
|
|
630
220
|
...config,
|
|
631
221
|
getBlockHeightExceedencePromise,
|
|
632
222
|
getRecentSignatureConfirmationPromise
|
|
633
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
|
+
});
|
|
634
232
|
};
|
|
635
233
|
}
|
|
636
|
-
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
637
|
-
await raceStrategies(
|
|
638
|
-
config,
|
|
639
|
-
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
640
|
-
return [
|
|
641
|
-
getNonceInvalidationPromise({
|
|
642
|
-
abortSignal,
|
|
643
|
-
commitment,
|
|
644
|
-
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
645
|
-
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
646
|
-
})
|
|
647
|
-
];
|
|
648
|
-
}
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
async function waitForRecentTransactionConfirmation(config) {
|
|
652
|
-
await raceStrategies(
|
|
653
|
-
config,
|
|
654
|
-
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
655
|
-
return [
|
|
656
|
-
getBlockHeightExceedencePromise({
|
|
657
|
-
abortSignal,
|
|
658
|
-
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
659
|
-
})
|
|
660
|
-
];
|
|
661
|
-
}
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
234
|
|
|
665
|
-
export {
|
|
235
|
+
export { airdropFactory, decodeTransaction, sendAndConfirmDurableNonceTransactionFactory, sendAndConfirmTransactionFactory, sendTransactionWithoutConfirmingFactory };
|
|
666
236
|
//# sourceMappingURL=out.js.map
|
|
667
237
|
//# sourceMappingURL=index.browser.js.map
|