@solana/web3.js 2.0.0-experimental.32e3112 → 2.0.0-experimental.34c3228
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 +652 -35
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +595 -36
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +5370 -566
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +584 -36
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +641 -35
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +584 -36
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +270 -19
- 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/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
- package/dist/types/decode-transaction.d.ts +10 -0
- package/dist/types/decode-transaction.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -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 -7
- package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -1
- package/dist/types/rpc-request-coalescer.d.ts +2 -2
- 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 +7 -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 +16 -0
- package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
- package/dist/types/rpc.d.ts +12 -4
- package/dist/types/rpc.d.ts.map +1 -1
- package/dist/types/send-transaction-internal.d.ts +27 -0
- package/dist/types/send-transaction-internal.d.ts.map +1 -0
- package/dist/types/send-transaction.d.ts +23 -0
- package/dist/types/send-transaction.d.ts.map +1 -0
- package/package.json +27 -40
package/dist/index.browser.cjs
CHANGED
|
@@ -1,58 +1,350 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var accounts = require('@solana/accounts');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecs = require('@solana/codecs');
|
|
6
|
+
var functional = require('@solana/functional');
|
|
3
7
|
var instructions = require('@solana/instructions');
|
|
4
8
|
var keys = require('@solana/keys');
|
|
9
|
+
var programs = require('@solana/programs');
|
|
10
|
+
var rpcParsedTypes = require('@solana/rpc-parsed-types');
|
|
11
|
+
var rpcTypes = require('@solana/rpc-types');
|
|
12
|
+
var signers = require('@solana/signers');
|
|
13
|
+
var transactions = require('@solana/transactions');
|
|
14
|
+
var transactionConfirmation = require('@solana/transaction-confirmation');
|
|
5
15
|
var rpcCore = require('@solana/rpc-core');
|
|
6
16
|
var rpcTransport = require('@solana/rpc-transport');
|
|
7
17
|
var fastStableStringify = require('fast-stable-stringify');
|
|
18
|
+
var errors = require('@solana/errors');
|
|
8
19
|
|
|
9
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
21
|
|
|
11
22
|
var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableStringify);
|
|
12
23
|
|
|
13
|
-
//
|
|
24
|
+
// ../build-scripts/env-shim.ts
|
|
25
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
14
26
|
|
|
15
|
-
// src/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
// src/airdrop-internal.ts
|
|
28
|
+
async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
29
|
+
abortSignal,
|
|
30
|
+
commitment,
|
|
31
|
+
confirmSignatureOnlyTransaction,
|
|
32
|
+
lamports,
|
|
33
|
+
recipientAddress,
|
|
34
|
+
rpc
|
|
35
|
+
}) {
|
|
36
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
37
|
+
await confirmSignatureOnlyTransaction({
|
|
38
|
+
abortSignal,
|
|
39
|
+
commitment,
|
|
40
|
+
signature: airdropTransactionSignature
|
|
41
|
+
});
|
|
42
|
+
return airdropTransactionSignature;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/airdrop.ts
|
|
46
|
+
function airdropFactory({ rpc, rpcSubscriptions }) {
|
|
47
|
+
const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
|
|
48
|
+
rpc,
|
|
49
|
+
rpcSubscriptions
|
|
50
|
+
);
|
|
51
|
+
async function confirmSignatureOnlyTransaction(config) {
|
|
52
|
+
await transactionConfirmation.waitForRecentTransactionConfirmationUntilTimeout({
|
|
53
|
+
...config,
|
|
54
|
+
getRecentSignatureConfirmationPromise,
|
|
55
|
+
getTimeoutPromise: transactionConfirmation.getTimeoutPromise
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return async function airdrop(config) {
|
|
59
|
+
return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
60
|
+
...config,
|
|
61
|
+
confirmSignatureOnlyTransaction,
|
|
62
|
+
rpc
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var compiledTransactionDecoder = void 0;
|
|
67
|
+
async function fetchLookupTables(lookupTableAddresses, rpc, config) {
|
|
68
|
+
const fetchedLookupTables = await accounts.fetchJsonParsedAccounts(
|
|
69
|
+
rpc,
|
|
70
|
+
lookupTableAddresses,
|
|
71
|
+
config
|
|
72
|
+
);
|
|
73
|
+
accounts.assertAccountsDecoded(fetchedLookupTables);
|
|
74
|
+
accounts.assertAccountsExist(fetchedLookupTables);
|
|
75
|
+
return fetchedLookupTables.reduce((acc, lookup) => {
|
|
76
|
+
return {
|
|
77
|
+
...acc,
|
|
78
|
+
[lookup.address]: lookup.data.addresses
|
|
79
|
+
};
|
|
80
|
+
}, {});
|
|
81
|
+
}
|
|
82
|
+
async function decodeTransaction(encodedTransaction, rpc, config) {
|
|
83
|
+
const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};
|
|
84
|
+
if (!compiledTransactionDecoder)
|
|
85
|
+
compiledTransactionDecoder = transactions.getCompiledTransactionDecoder();
|
|
86
|
+
const compiledTransaction = compiledTransactionDecoder.decode(encodedTransaction);
|
|
87
|
+
const { compiledMessage } = compiledTransaction;
|
|
88
|
+
const lookupTables = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? compiledMessage.addressTableLookups : [];
|
|
89
|
+
const lookupTableAddresses = lookupTables.map((l) => l.lookupTableAddress);
|
|
90
|
+
const fetchedLookupTables = lookupTableAddresses.length > 0 ? await fetchLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig) : {};
|
|
91
|
+
return transactions.decompileTransaction(compiledTransaction, {
|
|
92
|
+
addressesByLookupTableAddress: fetchedLookupTables,
|
|
93
|
+
lastValidBlockHeight
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value) {
|
|
97
|
+
let argumentLabel = "";
|
|
98
|
+
if (typeof keyPath[0] === "number") {
|
|
99
|
+
const argPosition = keyPath[0] + 1;
|
|
20
100
|
const lastDigit = argPosition % 10;
|
|
21
101
|
const lastTwoDigits = argPosition % 100;
|
|
22
102
|
if (lastDigit == 1 && lastTwoDigits != 11) {
|
|
23
|
-
|
|
103
|
+
argumentLabel = argPosition + "st";
|
|
24
104
|
} else if (lastDigit == 2 && lastTwoDigits != 12) {
|
|
25
|
-
|
|
105
|
+
argumentLabel = argPosition + "nd";
|
|
26
106
|
} else if (lastDigit == 3 && lastTwoDigits != 13) {
|
|
27
|
-
|
|
107
|
+
argumentLabel = argPosition + "rd";
|
|
28
108
|
} else {
|
|
29
|
-
|
|
109
|
+
argumentLabel = argPosition + "th";
|
|
30
110
|
}
|
|
31
|
-
|
|
32
|
-
|
|
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;
|
|
111
|
+
} else {
|
|
112
|
+
argumentLabel = `\`${keyPath[0].toString()}\``;
|
|
38
113
|
}
|
|
39
|
-
|
|
40
|
-
|
|
114
|
+
const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : void 0;
|
|
115
|
+
const error = new errors.SolanaError(errors.SOLANA_ERROR__RPC_INTEGER_OVERFLOW, {
|
|
116
|
+
argumentLabel,
|
|
117
|
+
keyPath,
|
|
118
|
+
methodName,
|
|
119
|
+
optionalPathLabel: path ? ` at path \`${path}\`` : "",
|
|
120
|
+
value,
|
|
121
|
+
...path !== void 0 ? { path } : void 0
|
|
122
|
+
});
|
|
123
|
+
if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
|
|
124
|
+
Error.captureStackTrace(error, createSolanaJsonRpcIntegerOverflowError);
|
|
41
125
|
}
|
|
42
|
-
|
|
126
|
+
return error;
|
|
127
|
+
}
|
|
43
128
|
|
|
44
129
|
// src/rpc-default-config.ts
|
|
45
130
|
var DEFAULT_RPC_CONFIG = {
|
|
131
|
+
defaultCommitment: "confirmed",
|
|
46
132
|
onIntegerOverflow(methodName, keyPath, value) {
|
|
47
|
-
throw
|
|
133
|
+
throw createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
|
|
48
134
|
}
|
|
49
135
|
};
|
|
50
136
|
|
|
137
|
+
// src/cached-abortable-iterable.ts
|
|
138
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
139
|
+
(async () => {
|
|
140
|
+
try {
|
|
141
|
+
for await (const _ of iterable)
|
|
142
|
+
;
|
|
143
|
+
} catch {
|
|
144
|
+
} finally {
|
|
145
|
+
cleanupFn();
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
}
|
|
149
|
+
function getCachedAbortableIterableFactory({
|
|
150
|
+
getAbortSignalFromInputArgs,
|
|
151
|
+
getCacheEntryMissingError,
|
|
152
|
+
getCacheKeyFromInputArgs,
|
|
153
|
+
onCacheHit,
|
|
154
|
+
onCreateIterable
|
|
155
|
+
}) {
|
|
156
|
+
const cache = /* @__PURE__ */ new Map();
|
|
157
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
158
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
159
|
+
if (!currentCacheEntry) {
|
|
160
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
161
|
+
}
|
|
162
|
+
return currentCacheEntry;
|
|
163
|
+
}
|
|
164
|
+
return async (...args) => {
|
|
165
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
166
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
167
|
+
if (cacheKey === void 0) {
|
|
168
|
+
return await onCreateIterable(signal, ...args);
|
|
169
|
+
}
|
|
170
|
+
const cleanup = () => {
|
|
171
|
+
cache.delete(cacheKey);
|
|
172
|
+
signal.removeEventListener("abort", handleAbort);
|
|
173
|
+
};
|
|
174
|
+
const handleAbort = () => {
|
|
175
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
176
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
177
|
+
cacheEntry.purgeScheduled = true;
|
|
178
|
+
globalThis.queueMicrotask(() => {
|
|
179
|
+
cacheEntry.purgeScheduled = false;
|
|
180
|
+
if (cacheEntry.referenceCount === 0) {
|
|
181
|
+
cacheEntry.abortController.abort();
|
|
182
|
+
cleanup();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
cacheEntry.referenceCount--;
|
|
187
|
+
};
|
|
188
|
+
signal.addEventListener("abort", handleAbort);
|
|
189
|
+
try {
|
|
190
|
+
const cacheEntry = cache.get(cacheKey);
|
|
191
|
+
if (!cacheEntry) {
|
|
192
|
+
const singletonAbortController = new AbortController();
|
|
193
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
194
|
+
const newCacheEntry = {
|
|
195
|
+
abortController: singletonAbortController,
|
|
196
|
+
iterable: newIterablePromise,
|
|
197
|
+
purgeScheduled: false,
|
|
198
|
+
referenceCount: 1
|
|
199
|
+
};
|
|
200
|
+
cache.set(cacheKey, newCacheEntry);
|
|
201
|
+
const newIterable = await newIterablePromise;
|
|
202
|
+
registerIterableCleanup(newIterable, cleanup);
|
|
203
|
+
newCacheEntry.iterable = newIterable;
|
|
204
|
+
return newIterable;
|
|
205
|
+
} else {
|
|
206
|
+
cacheEntry.referenceCount++;
|
|
207
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
208
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
209
|
+
await onCacheHit(cachedIterable, ...args);
|
|
210
|
+
return cachedIterable;
|
|
211
|
+
}
|
|
212
|
+
} catch (e) {
|
|
213
|
+
cleanup();
|
|
214
|
+
throw e;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/rpc-subscription-coalescer.ts
|
|
220
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
221
|
+
__DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
|
|
222
|
+
);
|
|
223
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
224
|
+
(async () => {
|
|
225
|
+
try {
|
|
226
|
+
for await (const _ of iterable)
|
|
227
|
+
;
|
|
228
|
+
} catch {
|
|
229
|
+
} finally {
|
|
230
|
+
cleanupFn();
|
|
231
|
+
}
|
|
232
|
+
})();
|
|
233
|
+
}
|
|
234
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
235
|
+
getDeduplicationKey,
|
|
236
|
+
rpcSubscriptions
|
|
237
|
+
}) {
|
|
238
|
+
const cache = /* @__PURE__ */ new Map();
|
|
239
|
+
return new Proxy(rpcSubscriptions, {
|
|
240
|
+
defineProperty() {
|
|
241
|
+
return false;
|
|
242
|
+
},
|
|
243
|
+
deleteProperty() {
|
|
244
|
+
return false;
|
|
245
|
+
},
|
|
246
|
+
get(target, p, receiver) {
|
|
247
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
248
|
+
if (typeof subscriptionMethod !== "function") {
|
|
249
|
+
return subscriptionMethod;
|
|
250
|
+
}
|
|
251
|
+
return function(...rawParams) {
|
|
252
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
253
|
+
if (deduplicationKey === void 0) {
|
|
254
|
+
return subscriptionMethod(...rawParams);
|
|
255
|
+
}
|
|
256
|
+
if (cache.has(deduplicationKey)) {
|
|
257
|
+
return cache.get(deduplicationKey);
|
|
258
|
+
}
|
|
259
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
260
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
261
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
262
|
+
return new Error(
|
|
263
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
264
|
+
);
|
|
265
|
+
},
|
|
266
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
267
|
+
async onCacheHit(_iterable, _config) {
|
|
268
|
+
},
|
|
269
|
+
async onCreateIterable(abortSignal, config) {
|
|
270
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
271
|
+
...rawParams
|
|
272
|
+
);
|
|
273
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
274
|
+
...config,
|
|
275
|
+
abortSignal
|
|
276
|
+
});
|
|
277
|
+
registerIterableCleanup2(iterable, () => {
|
|
278
|
+
cache.delete(deduplicationKey);
|
|
279
|
+
});
|
|
280
|
+
return iterable;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
const pendingSubscription = {
|
|
284
|
+
async subscribe(...args) {
|
|
285
|
+
const iterable = await iterableFactory(...args);
|
|
286
|
+
const { abortSignal } = args[0];
|
|
287
|
+
let abortPromise;
|
|
288
|
+
return {
|
|
289
|
+
...iterable,
|
|
290
|
+
async *[Symbol.asyncIterator]() {
|
|
291
|
+
abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
292
|
+
abortSignal.addEventListener("abort", () => {
|
|
293
|
+
reject(EXPLICIT_ABORT_TOKEN);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
try {
|
|
297
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
298
|
+
while (true) {
|
|
299
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
300
|
+
if (iteratorResult.done) {
|
|
301
|
+
return;
|
|
302
|
+
} else {
|
|
303
|
+
yield iteratorResult.value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
} catch (e) {
|
|
307
|
+
if (e === EXPLICIT_ABORT_TOKEN) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
cache.delete(deduplicationKey);
|
|
311
|
+
throw e;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
318
|
+
return pendingSubscription;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
51
324
|
// src/rpc.ts
|
|
52
325
|
function createSolanaRpc(config) {
|
|
326
|
+
const api = rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG);
|
|
53
327
|
return rpcTransport.createJsonRpc({
|
|
54
328
|
...config,
|
|
55
|
-
api
|
|
329
|
+
api
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function createSolanaRpcSubscriptions(config) {
|
|
333
|
+
return functional.pipe(
|
|
334
|
+
rpcTransport.createJsonSubscriptionRpc({
|
|
335
|
+
...config,
|
|
336
|
+
api: rpcCore.createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
337
|
+
}),
|
|
338
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
339
|
+
getDeduplicationKey: (...args) => fastStableStringify__default.default(args),
|
|
340
|
+
rpcSubscriptions
|
|
341
|
+
})
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
345
|
+
return rpcTransport.createJsonSubscriptionRpc({
|
|
346
|
+
...config,
|
|
347
|
+
api: rpcCore.createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
56
348
|
});
|
|
57
349
|
}
|
|
58
350
|
|
|
@@ -73,13 +365,23 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
73
365
|
}
|
|
74
366
|
if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
|
|
75
367
|
const abortController = new AbortController();
|
|
368
|
+
const responsePromise = (async () => {
|
|
369
|
+
try {
|
|
370
|
+
return await transport({
|
|
371
|
+
...config,
|
|
372
|
+
signal: abortController.signal
|
|
373
|
+
});
|
|
374
|
+
} catch (e) {
|
|
375
|
+
if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
throw e;
|
|
379
|
+
}
|
|
380
|
+
})();
|
|
76
381
|
coalescedRequestsByDeduplicationKey[deduplicationKey] = {
|
|
77
382
|
abortController,
|
|
78
383
|
numConsumers: 0,
|
|
79
|
-
responsePromise
|
|
80
|
-
...config,
|
|
81
|
-
signal: abortController.signal
|
|
82
|
-
})
|
|
384
|
+
responsePromise
|
|
83
385
|
};
|
|
84
386
|
}
|
|
85
387
|
const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
|
|
@@ -107,13 +409,14 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
107
409
|
}
|
|
108
410
|
};
|
|
109
411
|
}
|
|
110
|
-
function
|
|
412
|
+
function isJsonRpcPayload(payload) {
|
|
111
413
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
115
|
-
return fastStableStringify__default.default([payload.method, payload.params]);
|
|
414
|
+
return false;
|
|
116
415
|
}
|
|
416
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
417
|
+
}
|
|
418
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
419
|
+
return isJsonRpcPayload(payload) ? fastStableStringify__default.default([payload.method, payload.params]) : void 0;
|
|
117
420
|
}
|
|
118
421
|
|
|
119
422
|
// src/rpc-transport.ts
|
|
@@ -125,7 +428,7 @@ function normalizeHeaders(headers) {
|
|
|
125
428
|
return out;
|
|
126
429
|
}
|
|
127
430
|
function createDefaultRpcTransport(config) {
|
|
128
|
-
return
|
|
431
|
+
return functional.pipe(
|
|
129
432
|
rpcTransport.createHttpTransport({
|
|
130
433
|
...config,
|
|
131
434
|
headers: {
|
|
@@ -136,23 +439,337 @@ function createDefaultRpcTransport(config) {
|
|
|
136
439
|
}
|
|
137
440
|
}
|
|
138
441
|
}),
|
|
139
|
-
getSolanaRpcPayloadDeduplicationKey
|
|
442
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
140
443
|
);
|
|
141
444
|
}
|
|
142
445
|
|
|
446
|
+
// src/rpc-websocket-autopinger.ts
|
|
447
|
+
var PING_PAYLOAD = {
|
|
448
|
+
jsonrpc: "2.0",
|
|
449
|
+
method: "ping"
|
|
450
|
+
};
|
|
451
|
+
function getWebSocketTransportWithAutoping({
|
|
452
|
+
intervalMs,
|
|
453
|
+
transport
|
|
454
|
+
}) {
|
|
455
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
456
|
+
return async (...args) => {
|
|
457
|
+
const connection = await transport(...args);
|
|
458
|
+
let intervalId;
|
|
459
|
+
function sendPing() {
|
|
460
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
461
|
+
}
|
|
462
|
+
function restartPingTimer() {
|
|
463
|
+
clearInterval(intervalId);
|
|
464
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
465
|
+
}
|
|
466
|
+
if (pingableConnections.has(connection) === false) {
|
|
467
|
+
pingableConnections.set(connection, {
|
|
468
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
469
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
470
|
+
restartPingTimer();
|
|
471
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
(async () => {
|
|
475
|
+
try {
|
|
476
|
+
for await (const _ of connection) {
|
|
477
|
+
restartPingTimer();
|
|
478
|
+
}
|
|
479
|
+
} catch {
|
|
480
|
+
} finally {
|
|
481
|
+
pingableConnections.delete(connection);
|
|
482
|
+
clearInterval(intervalId);
|
|
483
|
+
if (handleOffline) {
|
|
484
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
485
|
+
}
|
|
486
|
+
if (handleOnline) {
|
|
487
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
})();
|
|
491
|
+
if (globalThis.navigator.onLine) {
|
|
492
|
+
restartPingTimer();
|
|
493
|
+
}
|
|
494
|
+
let handleOffline;
|
|
495
|
+
let handleOnline;
|
|
496
|
+
{
|
|
497
|
+
handleOffline = () => {
|
|
498
|
+
clearInterval(intervalId);
|
|
499
|
+
};
|
|
500
|
+
handleOnline = () => {
|
|
501
|
+
sendPing();
|
|
502
|
+
restartPingTimer();
|
|
503
|
+
};
|
|
504
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
505
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return pingableConnections.get(connection);
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
513
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
514
|
+
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
515
|
+
);
|
|
516
|
+
function getWebSocketTransportWithConnectionSharding({
|
|
517
|
+
getShard,
|
|
518
|
+
transport
|
|
519
|
+
}) {
|
|
520
|
+
return getCachedAbortableIterableFactory({
|
|
521
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
522
|
+
getCacheEntryMissingError(shardKey) {
|
|
523
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
524
|
+
},
|
|
525
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
526
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
527
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
528
|
+
...config,
|
|
529
|
+
signal: abortSignal
|
|
530
|
+
})
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/rpc-websocket-transport.ts
|
|
535
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
536
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
537
|
+
return functional.pipe(
|
|
538
|
+
rpcTransport.createWebSocketTransport({
|
|
539
|
+
...rest,
|
|
540
|
+
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
541
|
+
131072
|
|
542
|
+
}),
|
|
543
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
544
|
+
intervalMs: intervalMs ?? 5e3,
|
|
545
|
+
transport
|
|
546
|
+
}),
|
|
547
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
548
|
+
getShard,
|
|
549
|
+
transport
|
|
550
|
+
})
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
554
|
+
if (
|
|
555
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
556
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
557
|
+
rpcTypes.commitmentComparator(
|
|
558
|
+
commitment,
|
|
559
|
+
"finalized"
|
|
560
|
+
/* default value of `preflightCommitment` */
|
|
561
|
+
) < 0
|
|
562
|
+
) {
|
|
563
|
+
return {
|
|
564
|
+
...config,
|
|
565
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
566
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
567
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
568
|
+
// confirmation commitment.
|
|
569
|
+
preflightCommitment: commitment
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
return config;
|
|
573
|
+
}
|
|
574
|
+
async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
575
|
+
abortSignal,
|
|
576
|
+
commitment,
|
|
577
|
+
rpc,
|
|
578
|
+
transaction,
|
|
579
|
+
...sendTransactionConfig
|
|
580
|
+
}) {
|
|
581
|
+
const base64EncodedWireTransaction = transactions.getBase64EncodedWireTransaction(transaction);
|
|
582
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
583
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
584
|
+
encoding: "base64"
|
|
585
|
+
}).send({ abortSignal });
|
|
586
|
+
}
|
|
587
|
+
async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
588
|
+
abortSignal,
|
|
589
|
+
commitment,
|
|
590
|
+
confirmDurableNonceTransaction,
|
|
591
|
+
rpc,
|
|
592
|
+
transaction,
|
|
593
|
+
...sendTransactionConfig
|
|
594
|
+
}) {
|
|
595
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
596
|
+
...sendTransactionConfig,
|
|
597
|
+
abortSignal,
|
|
598
|
+
commitment,
|
|
599
|
+
rpc,
|
|
600
|
+
transaction
|
|
601
|
+
});
|
|
602
|
+
await confirmDurableNonceTransaction({
|
|
603
|
+
abortSignal,
|
|
604
|
+
commitment,
|
|
605
|
+
transaction
|
|
606
|
+
});
|
|
607
|
+
return transactionSignature;
|
|
608
|
+
}
|
|
609
|
+
async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
610
|
+
abortSignal,
|
|
611
|
+
commitment,
|
|
612
|
+
confirmRecentTransaction,
|
|
613
|
+
rpc,
|
|
614
|
+
transaction,
|
|
615
|
+
...sendTransactionConfig
|
|
616
|
+
}) {
|
|
617
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
618
|
+
...sendTransactionConfig,
|
|
619
|
+
abortSignal,
|
|
620
|
+
commitment,
|
|
621
|
+
rpc,
|
|
622
|
+
transaction
|
|
623
|
+
});
|
|
624
|
+
await confirmRecentTransaction({
|
|
625
|
+
abortSignal,
|
|
626
|
+
commitment,
|
|
627
|
+
transaction
|
|
628
|
+
});
|
|
629
|
+
return transactionSignature;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/send-transaction.ts
|
|
633
|
+
function sendTransactionWithoutConfirmingFactory({
|
|
634
|
+
rpc
|
|
635
|
+
}) {
|
|
636
|
+
return async function sendTransactionWithoutConfirming(transaction, config) {
|
|
637
|
+
await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
638
|
+
...config,
|
|
639
|
+
rpc,
|
|
640
|
+
transaction
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function sendAndConfirmDurableNonceTransactionFactory({
|
|
645
|
+
rpc,
|
|
646
|
+
rpcSubscriptions
|
|
647
|
+
}) {
|
|
648
|
+
const getNonceInvalidationPromise = transactionConfirmation.createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
649
|
+
const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
|
|
650
|
+
rpc,
|
|
651
|
+
rpcSubscriptions
|
|
652
|
+
);
|
|
653
|
+
async function confirmDurableNonceTransaction(config) {
|
|
654
|
+
await transactionConfirmation.waitForDurableNonceTransactionConfirmation({
|
|
655
|
+
...config,
|
|
656
|
+
getNonceInvalidationPromise,
|
|
657
|
+
getRecentSignatureConfirmationPromise
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
|
|
661
|
+
await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
662
|
+
...config,
|
|
663
|
+
confirmDurableNonceTransaction,
|
|
664
|
+
rpc,
|
|
665
|
+
transaction
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function sendAndConfirmTransactionFactory({
|
|
670
|
+
rpc,
|
|
671
|
+
rpcSubscriptions
|
|
672
|
+
}) {
|
|
673
|
+
const getBlockHeightExceedencePromise = transactionConfirmation.createBlockHeightExceedencePromiseFactory({
|
|
674
|
+
rpc,
|
|
675
|
+
rpcSubscriptions
|
|
676
|
+
});
|
|
677
|
+
const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
|
|
678
|
+
rpc,
|
|
679
|
+
rpcSubscriptions
|
|
680
|
+
);
|
|
681
|
+
async function confirmRecentTransaction(config) {
|
|
682
|
+
await transactionConfirmation.waitForRecentTransactionConfirmation({
|
|
683
|
+
...config,
|
|
684
|
+
getBlockHeightExceedencePromise,
|
|
685
|
+
getRecentSignatureConfirmationPromise
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
return async function sendAndConfirmTransaction(transaction, config) {
|
|
689
|
+
await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
690
|
+
...config,
|
|
691
|
+
confirmRecentTransaction,
|
|
692
|
+
rpc,
|
|
693
|
+
transaction
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
exports.airdropFactory = airdropFactory;
|
|
699
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
143
700
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
144
701
|
exports.createSolanaRpc = createSolanaRpc;
|
|
702
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
703
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
704
|
+
exports.decodeTransaction = decodeTransaction;
|
|
705
|
+
exports.sendAndConfirmDurableNonceTransactionFactory = sendAndConfirmDurableNonceTransactionFactory;
|
|
706
|
+
exports.sendAndConfirmTransactionFactory = sendAndConfirmTransactionFactory;
|
|
707
|
+
exports.sendTransactionWithoutConfirmingFactory = sendTransactionWithoutConfirmingFactory;
|
|
708
|
+
Object.keys(accounts).forEach(function (k) {
|
|
709
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
710
|
+
enumerable: true,
|
|
711
|
+
get: function () { return accounts[k]; }
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
Object.keys(addresses).forEach(function (k) {
|
|
715
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
716
|
+
enumerable: true,
|
|
717
|
+
get: function () { return addresses[k]; }
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
Object.keys(codecs).forEach(function (k) {
|
|
721
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
722
|
+
enumerable: true,
|
|
723
|
+
get: function () { return codecs[k]; }
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
Object.keys(functional).forEach(function (k) {
|
|
727
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
728
|
+
enumerable: true,
|
|
729
|
+
get: function () { return functional[k]; }
|
|
730
|
+
});
|
|
731
|
+
});
|
|
145
732
|
Object.keys(instructions).forEach(function (k) {
|
|
146
|
-
if (k !== 'default' && !
|
|
733
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
147
734
|
enumerable: true,
|
|
148
735
|
get: function () { return instructions[k]; }
|
|
149
736
|
});
|
|
150
737
|
});
|
|
151
738
|
Object.keys(keys).forEach(function (k) {
|
|
152
|
-
if (k !== 'default' && !
|
|
739
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
153
740
|
enumerable: true,
|
|
154
741
|
get: function () { return keys[k]; }
|
|
155
742
|
});
|
|
156
743
|
});
|
|
744
|
+
Object.keys(programs).forEach(function (k) {
|
|
745
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
746
|
+
enumerable: true,
|
|
747
|
+
get: function () { return programs[k]; }
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
Object.keys(rpcParsedTypes).forEach(function (k) {
|
|
751
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
752
|
+
enumerable: true,
|
|
753
|
+
get: function () { return rpcParsedTypes[k]; }
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
Object.keys(rpcTypes).forEach(function (k) {
|
|
757
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
758
|
+
enumerable: true,
|
|
759
|
+
get: function () { return rpcTypes[k]; }
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
Object.keys(signers).forEach(function (k) {
|
|
763
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
764
|
+
enumerable: true,
|
|
765
|
+
get: function () { return signers[k]; }
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
Object.keys(transactions).forEach(function (k) {
|
|
769
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
770
|
+
enumerable: true,
|
|
771
|
+
get: function () { return transactions[k]; }
|
|
772
|
+
});
|
|
773
|
+
});
|
|
157
774
|
//# sourceMappingURL=out.js.map
|
|
158
775
|
//# sourceMappingURL=index.browser.cjs.map
|