@solana/web3.js 2.0.0-experimental.b927e84 → 2.0.0-experimental.ba21818
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 +4 -4
- package/dist/index.browser.cjs +540 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +525 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2336 -429
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +514 -11
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +529 -13
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +514 -11
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +52 -29
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -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 +5 -3
- 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-signature.d.ts +13 -0
- package/dist/types/transaction-confirmation.d.ts +39 -0
- package/package.json +21 -21
package/dist/index.node.cjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var addresses = require('@solana/addresses');
|
|
3
4
|
var instructions = require('@solana/instructions');
|
|
4
5
|
var keys = require('@solana/keys');
|
|
5
6
|
var transactions = require('@solana/transactions');
|
|
7
|
+
var functional = require('@solana/functional');
|
|
6
8
|
var rpcCore = require('@solana/rpc-core');
|
|
7
9
|
var rpcTransport = require('@solana/rpc-transport');
|
|
8
10
|
var fastStableStringify = require('fast-stable-stringify');
|
|
11
|
+
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
9
12
|
|
|
10
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
14
|
|
|
12
15
|
var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableStringify);
|
|
13
16
|
|
|
14
|
-
//
|
|
17
|
+
// ../build-scripts/env-shim.ts
|
|
18
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
15
19
|
|
|
16
20
|
// src/rpc-integer-overflow-error.ts
|
|
17
21
|
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
@@ -49,6 +53,193 @@ var DEFAULT_RPC_CONFIG = {
|
|
|
49
53
|
}
|
|
50
54
|
};
|
|
51
55
|
|
|
56
|
+
// src/cached-abortable-iterable.ts
|
|
57
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
58
|
+
(async () => {
|
|
59
|
+
try {
|
|
60
|
+
for await (const _ of iterable)
|
|
61
|
+
;
|
|
62
|
+
} catch {
|
|
63
|
+
} finally {
|
|
64
|
+
cleanupFn();
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
}
|
|
68
|
+
function getCachedAbortableIterableFactory({
|
|
69
|
+
getAbortSignalFromInputArgs,
|
|
70
|
+
getCacheEntryMissingError,
|
|
71
|
+
getCacheKeyFromInputArgs,
|
|
72
|
+
onCacheHit,
|
|
73
|
+
onCreateIterable
|
|
74
|
+
}) {
|
|
75
|
+
const cache = /* @__PURE__ */ new Map();
|
|
76
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
77
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
78
|
+
if (!currentCacheEntry) {
|
|
79
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
80
|
+
}
|
|
81
|
+
return currentCacheEntry;
|
|
82
|
+
}
|
|
83
|
+
return async (...args) => {
|
|
84
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
85
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
86
|
+
if (cacheKey === void 0) {
|
|
87
|
+
return await onCreateIterable(signal, ...args);
|
|
88
|
+
}
|
|
89
|
+
const cleanup = () => {
|
|
90
|
+
cache.delete(cacheKey);
|
|
91
|
+
signal.removeEventListener("abort", handleAbort);
|
|
92
|
+
};
|
|
93
|
+
const handleAbort = () => {
|
|
94
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
95
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
96
|
+
cacheEntry.purgeScheduled = true;
|
|
97
|
+
globalThis.queueMicrotask(() => {
|
|
98
|
+
cacheEntry.purgeScheduled = false;
|
|
99
|
+
if (cacheEntry.referenceCount === 0) {
|
|
100
|
+
cacheEntry.abortController.abort();
|
|
101
|
+
cleanup();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
cacheEntry.referenceCount--;
|
|
106
|
+
};
|
|
107
|
+
signal.addEventListener("abort", handleAbort);
|
|
108
|
+
try {
|
|
109
|
+
const cacheEntry = cache.get(cacheKey);
|
|
110
|
+
if (!cacheEntry) {
|
|
111
|
+
const singletonAbortController = new AbortController();
|
|
112
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
113
|
+
const newCacheEntry = {
|
|
114
|
+
abortController: singletonAbortController,
|
|
115
|
+
iterable: newIterablePromise,
|
|
116
|
+
purgeScheduled: false,
|
|
117
|
+
referenceCount: 1
|
|
118
|
+
};
|
|
119
|
+
cache.set(cacheKey, newCacheEntry);
|
|
120
|
+
const newIterable = await newIterablePromise;
|
|
121
|
+
registerIterableCleanup(newIterable, cleanup);
|
|
122
|
+
newCacheEntry.iterable = newIterable;
|
|
123
|
+
return newIterable;
|
|
124
|
+
} else {
|
|
125
|
+
cacheEntry.referenceCount++;
|
|
126
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
127
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
128
|
+
await onCacheHit(cachedIterable, ...args);
|
|
129
|
+
return cachedIterable;
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {
|
|
132
|
+
cleanup();
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/rpc-subscription-coalescer.ts
|
|
139
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
140
|
+
__DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
|
|
141
|
+
);
|
|
142
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
143
|
+
(async () => {
|
|
144
|
+
try {
|
|
145
|
+
for await (const _ of iterable)
|
|
146
|
+
;
|
|
147
|
+
} catch {
|
|
148
|
+
} finally {
|
|
149
|
+
cleanupFn();
|
|
150
|
+
}
|
|
151
|
+
})();
|
|
152
|
+
}
|
|
153
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
154
|
+
getDeduplicationKey,
|
|
155
|
+
rpcSubscriptions
|
|
156
|
+
}) {
|
|
157
|
+
const cache = /* @__PURE__ */ new Map();
|
|
158
|
+
return new Proxy(rpcSubscriptions, {
|
|
159
|
+
defineProperty() {
|
|
160
|
+
return false;
|
|
161
|
+
},
|
|
162
|
+
deleteProperty() {
|
|
163
|
+
return false;
|
|
164
|
+
},
|
|
165
|
+
get(target, p, receiver) {
|
|
166
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
167
|
+
if (typeof subscriptionMethod !== "function") {
|
|
168
|
+
return subscriptionMethod;
|
|
169
|
+
}
|
|
170
|
+
return function(...rawParams) {
|
|
171
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
172
|
+
if (deduplicationKey === void 0) {
|
|
173
|
+
return subscriptionMethod(...rawParams);
|
|
174
|
+
}
|
|
175
|
+
if (cache.has(deduplicationKey)) {
|
|
176
|
+
return cache.get(deduplicationKey);
|
|
177
|
+
}
|
|
178
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
179
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
180
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
181
|
+
return new Error(
|
|
182
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
186
|
+
async onCacheHit(_iterable, _config) {
|
|
187
|
+
},
|
|
188
|
+
async onCreateIterable(abortSignal, config) {
|
|
189
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
190
|
+
...rawParams
|
|
191
|
+
);
|
|
192
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
193
|
+
...config,
|
|
194
|
+
abortSignal
|
|
195
|
+
});
|
|
196
|
+
registerIterableCleanup2(iterable, () => {
|
|
197
|
+
cache.delete(deduplicationKey);
|
|
198
|
+
});
|
|
199
|
+
return iterable;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const pendingSubscription = {
|
|
203
|
+
async subscribe(...args) {
|
|
204
|
+
const iterable = await iterableFactory(...args);
|
|
205
|
+
const { abortSignal } = args[0];
|
|
206
|
+
let abortPromise;
|
|
207
|
+
return {
|
|
208
|
+
...iterable,
|
|
209
|
+
async *[Symbol.asyncIterator]() {
|
|
210
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
211
|
+
abortSignal.addEventListener("abort", () => {
|
|
212
|
+
reject(EXPLICIT_ABORT_TOKEN);
|
|
213
|
+
});
|
|
214
|
+
}));
|
|
215
|
+
try {
|
|
216
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
217
|
+
while (true) {
|
|
218
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
219
|
+
if (iteratorResult.done) {
|
|
220
|
+
return;
|
|
221
|
+
} else {
|
|
222
|
+
yield iteratorResult.value;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} catch (e) {
|
|
226
|
+
if (e === EXPLICIT_ABORT_TOKEN) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
cache.delete(deduplicationKey);
|
|
230
|
+
throw e;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
237
|
+
return pendingSubscription;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
52
243
|
// src/rpc.ts
|
|
53
244
|
function createSolanaRpc(config) {
|
|
54
245
|
return rpcTransport.createJsonRpc({
|
|
@@ -56,6 +247,24 @@ function createSolanaRpc(config) {
|
|
|
56
247
|
api: rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
57
248
|
});
|
|
58
249
|
}
|
|
250
|
+
function createSolanaRpcSubscriptions(config) {
|
|
251
|
+
return functional.pipe(
|
|
252
|
+
rpcTransport.createJsonSubscriptionRpc({
|
|
253
|
+
...config,
|
|
254
|
+
api: rpcCore.createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
255
|
+
}),
|
|
256
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
257
|
+
getDeduplicationKey: (...args) => fastStableStringify__default.default(args),
|
|
258
|
+
rpcSubscriptions
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
263
|
+
return rpcTransport.createJsonSubscriptionRpc({
|
|
264
|
+
...config,
|
|
265
|
+
api: rpcCore.createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
266
|
+
});
|
|
267
|
+
}
|
|
59
268
|
|
|
60
269
|
// src/rpc-request-coalescer.ts
|
|
61
270
|
function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
@@ -108,13 +317,14 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
108
317
|
}
|
|
109
318
|
};
|
|
110
319
|
}
|
|
111
|
-
function
|
|
320
|
+
function isJsonRpcPayload(payload) {
|
|
112
321
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
116
|
-
return fastStableStringify__default.default([payload.method, payload.params]);
|
|
322
|
+
return false;
|
|
117
323
|
}
|
|
324
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
325
|
+
}
|
|
326
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
327
|
+
return isJsonRpcPayload(payload) ? fastStableStringify__default.default([payload.method, payload.params]) : void 0;
|
|
118
328
|
}
|
|
119
329
|
|
|
120
330
|
// src/rpc-transport.ts
|
|
@@ -126,7 +336,7 @@ function normalizeHeaders(headers) {
|
|
|
126
336
|
return out;
|
|
127
337
|
}
|
|
128
338
|
function createDefaultRpcTransport(config) {
|
|
129
|
-
return
|
|
339
|
+
return functional.pipe(
|
|
130
340
|
rpcTransport.createHttpTransport({
|
|
131
341
|
...config,
|
|
132
342
|
headers: {
|
|
@@ -137,29 +347,335 @@ function createDefaultRpcTransport(config) {
|
|
|
137
347
|
}
|
|
138
348
|
}
|
|
139
349
|
}),
|
|
140
|
-
getSolanaRpcPayloadDeduplicationKey
|
|
350
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
141
351
|
);
|
|
142
352
|
}
|
|
143
353
|
|
|
354
|
+
// src/rpc-websocket-autopinger.ts
|
|
355
|
+
var PING_PAYLOAD = {
|
|
356
|
+
jsonrpc: "2.0",
|
|
357
|
+
method: "ping"
|
|
358
|
+
};
|
|
359
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
360
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
361
|
+
return async (...args) => {
|
|
362
|
+
const connection = await transport(...args);
|
|
363
|
+
let intervalId;
|
|
364
|
+
function sendPing() {
|
|
365
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
366
|
+
}
|
|
367
|
+
function restartPingTimer() {
|
|
368
|
+
clearInterval(intervalId);
|
|
369
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
370
|
+
}
|
|
371
|
+
if (pingableConnections.has(connection) === false) {
|
|
372
|
+
pingableConnections.set(connection, {
|
|
373
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
374
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
375
|
+
restartPingTimer();
|
|
376
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
(async () => {
|
|
380
|
+
try {
|
|
381
|
+
for await (const _ of connection) {
|
|
382
|
+
restartPingTimer();
|
|
383
|
+
}
|
|
384
|
+
} catch {
|
|
385
|
+
} finally {
|
|
386
|
+
pingableConnections.delete(connection);
|
|
387
|
+
clearInterval(intervalId);
|
|
388
|
+
if (handleOffline) {
|
|
389
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
390
|
+
}
|
|
391
|
+
if (handleOnline) {
|
|
392
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
})();
|
|
396
|
+
{
|
|
397
|
+
restartPingTimer();
|
|
398
|
+
}
|
|
399
|
+
let handleOffline;
|
|
400
|
+
let handleOnline;
|
|
401
|
+
}
|
|
402
|
+
return pingableConnections.get(connection);
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
407
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
408
|
+
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
409
|
+
);
|
|
410
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
411
|
+
return getCachedAbortableIterableFactory({
|
|
412
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
413
|
+
getCacheEntryMissingError(shardKey) {
|
|
414
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
415
|
+
},
|
|
416
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
417
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
418
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
419
|
+
...config,
|
|
420
|
+
signal: abortSignal
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/rpc-websocket-transport.ts
|
|
426
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
427
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
428
|
+
return functional.pipe(
|
|
429
|
+
rpcTransport.createWebSocketTransport({
|
|
430
|
+
...rest,
|
|
431
|
+
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
432
|
+
131072
|
|
433
|
+
}),
|
|
434
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
435
|
+
intervalMs: intervalMs ?? 5e3,
|
|
436
|
+
transport
|
|
437
|
+
}),
|
|
438
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
439
|
+
getShard,
|
|
440
|
+
transport
|
|
441
|
+
})
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
446
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
447
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
448
|
+
const abortController = new AbortController();
|
|
449
|
+
function handleAbort() {
|
|
450
|
+
abortController.abort();
|
|
451
|
+
}
|
|
452
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
453
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
454
|
+
try {
|
|
455
|
+
for await (const slotNotification of slotNotifications) {
|
|
456
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
457
|
+
throw new Error(
|
|
458
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
} finally {
|
|
463
|
+
abortController.abort();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
468
|
+
4 + // state(u32)
|
|
469
|
+
32;
|
|
470
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
471
|
+
return async function getNonceInvalidationPromise({
|
|
472
|
+
abortSignal: callerAbortSignal,
|
|
473
|
+
commitment,
|
|
474
|
+
currentNonceValue,
|
|
475
|
+
nonceAccountAddress
|
|
476
|
+
}) {
|
|
477
|
+
const abortController = new AbortController();
|
|
478
|
+
function handleAbort() {
|
|
479
|
+
abortController.abort();
|
|
480
|
+
}
|
|
481
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
482
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
483
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
484
|
+
const data = umiSerializers.base64.serialize(base64EncodedBytes);
|
|
485
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
486
|
+
return umiSerializers.base58.deserialize(nonceValueBytes)[0];
|
|
487
|
+
}
|
|
488
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
489
|
+
for await (const accountNotification of accountNotifications) {
|
|
490
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
491
|
+
if (nonceValue !== currentNonceValue) {
|
|
492
|
+
throw new Error(
|
|
493
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
})();
|
|
498
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
499
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
500
|
+
commitment,
|
|
501
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
502
|
+
encoding: "base58"
|
|
503
|
+
}).send({ abortSignal: abortController.signal });
|
|
504
|
+
if (!nonceAccount) {
|
|
505
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
506
|
+
}
|
|
507
|
+
const nonceValue = (
|
|
508
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
509
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
510
|
+
nonceAccount.data[0]
|
|
511
|
+
);
|
|
512
|
+
if (nonceValue !== currentNonceValue) {
|
|
513
|
+
throw new Error(
|
|
514
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
515
|
+
);
|
|
516
|
+
} else {
|
|
517
|
+
await new Promise(() => {
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
})();
|
|
521
|
+
try {
|
|
522
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
523
|
+
} finally {
|
|
524
|
+
abortController.abort();
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
529
|
+
return async function getSignatureConfirmationPromise({ abortSignal: callerAbortSignal, commitment, signature }) {
|
|
530
|
+
const abortController = new AbortController();
|
|
531
|
+
function handleAbort() {
|
|
532
|
+
abortController.abort();
|
|
533
|
+
}
|
|
534
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
535
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
536
|
+
const signatureDidCommitPromise = (async () => {
|
|
537
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
538
|
+
if (signatureStatusNotification.value.err) {
|
|
539
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
540
|
+
cause: signatureStatusNotification.value.err
|
|
541
|
+
});
|
|
542
|
+
} else {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
})();
|
|
547
|
+
const signatureStatusLookupPromise = (async () => {
|
|
548
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
549
|
+
const signatureStatus = signatureStatusResults[0];
|
|
550
|
+
if (signatureStatus && signatureStatus.confirmationStatus && rpcCore.commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
551
|
+
return;
|
|
552
|
+
} else {
|
|
553
|
+
await new Promise(() => {
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
})();
|
|
557
|
+
try {
|
|
558
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
559
|
+
} finally {
|
|
560
|
+
abortController.abort();
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// src/transaction-confirmation.ts
|
|
566
|
+
async function raceStrategies(config, getSpecificStrategiesForRace) {
|
|
567
|
+
const { abortSignal: callerAbortSignal, commitment, getSignatureConfirmationPromise, transaction } = config;
|
|
568
|
+
callerAbortSignal.throwIfAborted();
|
|
569
|
+
const signature = transactions.getSignatureFromTransaction(transaction);
|
|
570
|
+
const abortController = new AbortController();
|
|
571
|
+
function handleAbort() {
|
|
572
|
+
abortController.abort();
|
|
573
|
+
}
|
|
574
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
575
|
+
try {
|
|
576
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
577
|
+
...config,
|
|
578
|
+
abortSignal: abortController.signal
|
|
579
|
+
});
|
|
580
|
+
return await Promise.race([
|
|
581
|
+
getSignatureConfirmationPromise({
|
|
582
|
+
abortSignal: abortController.signal,
|
|
583
|
+
commitment,
|
|
584
|
+
signature
|
|
585
|
+
}),
|
|
586
|
+
...specificStrategies
|
|
587
|
+
]);
|
|
588
|
+
} finally {
|
|
589
|
+
abortController.abort();
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
593
|
+
rpc,
|
|
594
|
+
rpcSubscriptions
|
|
595
|
+
}) {
|
|
596
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
597
|
+
const getSignatureConfirmationPromise = createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions);
|
|
598
|
+
return async function confirmTransaction(config) {
|
|
599
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
600
|
+
...config,
|
|
601
|
+
getNonceInvalidationPromise,
|
|
602
|
+
getSignatureConfirmationPromise
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function createDefaultTransactionConfirmer({ rpc, rpcSubscriptions }) {
|
|
607
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
608
|
+
const getSignatureConfirmationPromise = createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions);
|
|
609
|
+
return async function confirmTransaction(config) {
|
|
610
|
+
await waitForTransactionConfirmation({
|
|
611
|
+
...config,
|
|
612
|
+
getBlockHeightExceedencePromise,
|
|
613
|
+
getSignatureConfirmationPromise
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
618
|
+
await raceStrategies(
|
|
619
|
+
config,
|
|
620
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
621
|
+
return [
|
|
622
|
+
getNonceInvalidationPromise({
|
|
623
|
+
abortSignal,
|
|
624
|
+
commitment,
|
|
625
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
626
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
627
|
+
})
|
|
628
|
+
];
|
|
629
|
+
}
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
async function waitForTransactionConfirmation(config) {
|
|
633
|
+
await raceStrategies(
|
|
634
|
+
config,
|
|
635
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
636
|
+
return [
|
|
637
|
+
getBlockHeightExceedencePromise({
|
|
638
|
+
abortSignal,
|
|
639
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
640
|
+
})
|
|
641
|
+
];
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
|
|
647
|
+
exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
|
|
648
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
144
649
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
650
|
+
exports.createDefaultTransactionConfirmer = createDefaultTransactionConfirmer;
|
|
651
|
+
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
652
|
+
exports.createSignatureConfirmationPromiseFactory = createSignatureConfirmationPromiseFactory;
|
|
145
653
|
exports.createSolanaRpc = createSolanaRpc;
|
|
654
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
655
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
656
|
+
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
657
|
+
exports.waitForTransactionConfirmation = waitForTransactionConfirmation;
|
|
658
|
+
Object.keys(addresses).forEach(function (k) {
|
|
659
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
660
|
+
enumerable: true,
|
|
661
|
+
get: function () { return addresses[k]; }
|
|
662
|
+
});
|
|
663
|
+
});
|
|
146
664
|
Object.keys(instructions).forEach(function (k) {
|
|
147
|
-
if (k !== 'default' && !
|
|
665
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
148
666
|
enumerable: true,
|
|
149
667
|
get: function () { return instructions[k]; }
|
|
150
668
|
});
|
|
151
669
|
});
|
|
152
670
|
Object.keys(keys).forEach(function (k) {
|
|
153
|
-
if (k !== 'default' && !
|
|
671
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
154
672
|
enumerable: true,
|
|
155
673
|
get: function () { return keys[k]; }
|
|
156
674
|
});
|
|
157
675
|
});
|
|
158
676
|
Object.keys(transactions).forEach(function (k) {
|
|
159
|
-
if (k !== 'default' && !
|
|
677
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
160
678
|
enumerable: true,
|
|
161
679
|
get: function () { return transactions[k]; }
|
|
162
680
|
});
|
|
163
681
|
});
|
|
164
|
-
//# sourceMappingURL=out.js.map
|
|
165
|
-
//# sourceMappingURL=index.node.cjs.map
|