@solana/web3.js 2.0.0-experimental.0cfc222 → 2.0.0-experimental.0e03ca9
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 +479 -111
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +434 -111
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +4351 -2065
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +434 -111
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +481 -111
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +436 -111
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +273 -50
- package/dist/types/airdrop-confirmer.d.ts +19 -0
- package/dist/types/airdrop-confirmer.d.ts.map +1 -0
- package/dist/types/airdrop.d.ts +21 -0
- package/dist/types/airdrop.d.ts.map +1 -0
- package/dist/types/cached-abortable-iterable.d.ts.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 +17 -7
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/rpc-default-config.d.ts.map +1 -0
- package/dist/types/rpc-integer-overflow-error.d.ts +3 -2
- package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -0
- package/dist/types/rpc-request-coalescer.d.ts +2 -2
- package/dist/types/rpc-request-coalescer.d.ts.map +1 -0
- package/dist/types/rpc-request-deduplication.d.ts.map +1 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +1 -1
- 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 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +4 -4
- package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +4 -4
- package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
- package/dist/types/rpc-websocket-transport.d.ts +7 -4
- package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
- package/dist/types/rpc.d.ts +12 -6
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/send-transaction.d.ts +37 -0
- package/dist/types/send-transaction.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +9 -5
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +4 -6
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +11 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +1 -0
- package/dist/types/transaction-confirmation.d.ts +20 -27
- package/dist/types/transaction-confirmation.d.ts.map +1 -0
- package/package.json +24 -18
- package/dist/types/transaction-confirmation-strategy-signature.d.ts +0 -13
package/dist/index.node.js
CHANGED
|
@@ -1,36 +1,237 @@
|
|
|
1
|
+
import { fetchJsonParsedAccounts, assertAccountsDecoded, assertAccountsExist } from '@solana/accounts';
|
|
2
|
+
export * from '@solana/accounts';
|
|
1
3
|
export * from '@solana/addresses';
|
|
4
|
+
import { getBase58Decoder, getBase64Encoder } from '@solana/codecs';
|
|
5
|
+
export * from '@solana/codecs';
|
|
6
|
+
import { pipe } from '@solana/functional';
|
|
7
|
+
export * from '@solana/functional';
|
|
2
8
|
export * from '@solana/instructions';
|
|
3
9
|
export * from '@solana/keys';
|
|
4
|
-
|
|
10
|
+
export * from '@solana/programs';
|
|
11
|
+
export * from '@solana/rpc-parsed-types';
|
|
12
|
+
import { commitmentComparator } from '@solana/rpc-types';
|
|
13
|
+
export * from '@solana/rpc-types';
|
|
14
|
+
export * from '@solana/signers';
|
|
15
|
+
import { getCompiledTransactionDecoder, decompileTransaction, getSignatureFromTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';
|
|
5
16
|
export * from '@solana/transactions';
|
|
6
|
-
import {
|
|
7
|
-
import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE, commitmentComparator } from '@solana/rpc-core';
|
|
17
|
+
import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE } from '@solana/rpc-core';
|
|
8
18
|
import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
|
|
9
19
|
import fastStableStringify from 'fast-stable-stringify';
|
|
10
|
-
import { base64, base58 } from '@metaplex-foundation/umi-serializers';
|
|
11
20
|
|
|
12
21
|
// ../build-scripts/env-shim.ts
|
|
13
22
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
14
23
|
|
|
24
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
25
|
+
async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
|
|
26
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
27
|
+
callerAbortSignal?.throwIfAborted();
|
|
28
|
+
const abortController = new AbortController();
|
|
29
|
+
if (callerAbortSignal) {
|
|
30
|
+
const handleAbort = () => {
|
|
31
|
+
abortController.abort();
|
|
32
|
+
};
|
|
33
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
37
|
+
...config,
|
|
38
|
+
abortSignal: abortController.signal
|
|
39
|
+
});
|
|
40
|
+
return await Promise.race([
|
|
41
|
+
getRecentSignatureConfirmationPromise({
|
|
42
|
+
abortSignal: abortController.signal,
|
|
43
|
+
commitment,
|
|
44
|
+
signature
|
|
45
|
+
}),
|
|
46
|
+
...specificStrategies
|
|
47
|
+
]);
|
|
48
|
+
} finally {
|
|
49
|
+
abortController.abort();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
53
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
54
|
+
abortSignal: callerAbortSignal,
|
|
55
|
+
commitment,
|
|
56
|
+
signature
|
|
57
|
+
}) {
|
|
58
|
+
const abortController = new AbortController();
|
|
59
|
+
function handleAbort() {
|
|
60
|
+
abortController.abort();
|
|
61
|
+
}
|
|
62
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
63
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
64
|
+
const signatureDidCommitPromise = (async () => {
|
|
65
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
66
|
+
if (signatureStatusNotification.value.err) {
|
|
67
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
68
|
+
cause: signatureStatusNotification.value.err
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
const signatureStatusLookupPromise = (async () => {
|
|
76
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
77
|
+
const signatureStatus = signatureStatusResults[0];
|
|
78
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
79
|
+
return;
|
|
80
|
+
} else {
|
|
81
|
+
await new Promise(() => {
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
try {
|
|
86
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
87
|
+
} finally {
|
|
88
|
+
abortController.abort();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
94
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
95
|
+
return await new Promise((_, reject) => {
|
|
96
|
+
const handleAbort = (e) => {
|
|
97
|
+
clearTimeout(timeoutId);
|
|
98
|
+
const abortError = new DOMException(e.target.reason, "AbortError");
|
|
99
|
+
reject(abortError);
|
|
100
|
+
};
|
|
101
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
102
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
103
|
+
const startMs = performance.now();
|
|
104
|
+
const timeoutId = (
|
|
105
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
106
|
+
// elapsed time instead of active time.
|
|
107
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
const elapsedMs = performance.now() - startMs;
|
|
110
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
111
|
+
}, timeoutMs)
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/airdrop-confirmer.ts
|
|
117
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
118
|
+
rpc,
|
|
119
|
+
rpcSubscriptions
|
|
120
|
+
}) {
|
|
121
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
122
|
+
rpc,
|
|
123
|
+
rpcSubscriptions
|
|
124
|
+
);
|
|
125
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
126
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
127
|
+
...config,
|
|
128
|
+
getRecentSignatureConfirmationPromise,
|
|
129
|
+
getTimeoutPromise
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
134
|
+
await raceStrategies(
|
|
135
|
+
config.signature,
|
|
136
|
+
config,
|
|
137
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
138
|
+
return [
|
|
139
|
+
getTimeoutPromise2({
|
|
140
|
+
abortSignal,
|
|
141
|
+
commitment
|
|
142
|
+
})
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/airdrop.ts
|
|
149
|
+
function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
|
|
150
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
151
|
+
rpc,
|
|
152
|
+
rpcSubscriptions
|
|
153
|
+
});
|
|
154
|
+
return async function requestAirdrop(config) {
|
|
155
|
+
return await requestAndConfirmAirdrop({
|
|
156
|
+
...config,
|
|
157
|
+
confirmSignatureOnlyTransaction,
|
|
158
|
+
rpc
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function requestAndConfirmAirdrop({
|
|
163
|
+
abortSignal,
|
|
164
|
+
commitment,
|
|
165
|
+
confirmSignatureOnlyTransaction,
|
|
166
|
+
lamports,
|
|
167
|
+
recipientAddress,
|
|
168
|
+
rpc
|
|
169
|
+
}) {
|
|
170
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
171
|
+
await confirmSignatureOnlyTransaction({
|
|
172
|
+
abortSignal,
|
|
173
|
+
commitment,
|
|
174
|
+
signature: airdropTransactionSignature
|
|
175
|
+
});
|
|
176
|
+
return airdropTransactionSignature;
|
|
177
|
+
}
|
|
178
|
+
var compiledTransactionDecoder = void 0;
|
|
179
|
+
async function fetchLookupTables(lookupTableAddresses, rpc, config) {
|
|
180
|
+
const fetchedLookupTables = await fetchJsonParsedAccounts(
|
|
181
|
+
rpc,
|
|
182
|
+
lookupTableAddresses,
|
|
183
|
+
config
|
|
184
|
+
);
|
|
185
|
+
assertAccountsDecoded(fetchedLookupTables);
|
|
186
|
+
assertAccountsExist(fetchedLookupTables);
|
|
187
|
+
return fetchedLookupTables.reduce((acc, lookup) => {
|
|
188
|
+
return {
|
|
189
|
+
...acc,
|
|
190
|
+
[lookup.address]: lookup.data.addresses
|
|
191
|
+
};
|
|
192
|
+
}, {});
|
|
193
|
+
}
|
|
194
|
+
async function decodeTransaction(encodedTransaction, rpc, config) {
|
|
195
|
+
const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};
|
|
196
|
+
if (!compiledTransactionDecoder)
|
|
197
|
+
compiledTransactionDecoder = getCompiledTransactionDecoder();
|
|
198
|
+
const compiledTransaction = compiledTransactionDecoder.decode(encodedTransaction);
|
|
199
|
+
const { compiledMessage } = compiledTransaction;
|
|
200
|
+
const lookupTables = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? compiledMessage.addressTableLookups : [];
|
|
201
|
+
const lookupTableAddresses = lookupTables.map((l) => l.lookupTableAddress);
|
|
202
|
+
const fetchedLookupTables = lookupTableAddresses.length > 0 ? await fetchLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig) : {};
|
|
203
|
+
return decompileTransaction(compiledTransaction, {
|
|
204
|
+
addressesByLookupTableAddress: fetchedLookupTables,
|
|
205
|
+
lastValidBlockHeight
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
15
209
|
// src/rpc-integer-overflow-error.ts
|
|
16
210
|
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
211
|
+
methodName;
|
|
212
|
+
keyPath;
|
|
213
|
+
value;
|
|
17
214
|
constructor(methodName, keyPath, value) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
215
|
+
let argumentLabel = "";
|
|
216
|
+
if (typeof keyPath[0] === "number") {
|
|
217
|
+
const argPosition = keyPath[0] + 1;
|
|
218
|
+
const lastDigit = argPosition % 10;
|
|
219
|
+
const lastTwoDigits = argPosition % 100;
|
|
220
|
+
if (lastDigit == 1 && lastTwoDigits != 11) {
|
|
221
|
+
argumentLabel = argPosition + "st";
|
|
222
|
+
} else if (lastDigit == 2 && lastTwoDigits != 12) {
|
|
223
|
+
argumentLabel = argPosition + "nd";
|
|
224
|
+
} else if (lastDigit == 3 && lastTwoDigits != 13) {
|
|
225
|
+
argumentLabel = argPosition + "rd";
|
|
226
|
+
} else {
|
|
227
|
+
argumentLabel = argPosition + "th";
|
|
228
|
+
}
|
|
28
229
|
} else {
|
|
29
|
-
|
|
230
|
+
argumentLabel = `\`${keyPath[0].toString()}\``;
|
|
30
231
|
}
|
|
31
232
|
const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
|
|
32
233
|
super(
|
|
33
|
-
`The ${
|
|
234
|
+
`The ${argumentLabel} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
|
|
34
235
|
);
|
|
35
236
|
this.keyPath = keyPath;
|
|
36
237
|
this.methodName = methodName;
|
|
@@ -43,6 +244,7 @@ var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
|
43
244
|
|
|
44
245
|
// src/rpc-default-config.ts
|
|
45
246
|
var DEFAULT_RPC_CONFIG = {
|
|
247
|
+
defaultCommitment: "confirmed",
|
|
46
248
|
onIntegerOverflow(methodName, keyPath, value) {
|
|
47
249
|
throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
|
|
48
250
|
}
|
|
@@ -202,11 +404,11 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
|
202
404
|
return {
|
|
203
405
|
...iterable,
|
|
204
406
|
async *[Symbol.asyncIterator]() {
|
|
205
|
-
abortPromise
|
|
407
|
+
abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
206
408
|
abortSignal.addEventListener("abort", () => {
|
|
207
409
|
reject(EXPLICIT_ABORT_TOKEN);
|
|
208
410
|
});
|
|
209
|
-
})
|
|
411
|
+
});
|
|
210
412
|
try {
|
|
211
413
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
212
414
|
while (true) {
|
|
@@ -237,9 +439,10 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
|
237
439
|
|
|
238
440
|
// src/rpc.ts
|
|
239
441
|
function createSolanaRpc(config) {
|
|
442
|
+
const api = createSolanaRpcApi(DEFAULT_RPC_CONFIG);
|
|
240
443
|
return createJsonRpc({
|
|
241
444
|
...config,
|
|
242
|
-
api
|
|
445
|
+
api
|
|
243
446
|
});
|
|
244
447
|
}
|
|
245
448
|
function createSolanaRpcSubscriptions(config) {
|
|
@@ -278,13 +481,23 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
278
481
|
}
|
|
279
482
|
if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
|
|
280
483
|
const abortController = new AbortController();
|
|
484
|
+
const responsePromise = (async () => {
|
|
485
|
+
try {
|
|
486
|
+
return await transport({
|
|
487
|
+
...config,
|
|
488
|
+
signal: abortController.signal
|
|
489
|
+
});
|
|
490
|
+
} catch (e) {
|
|
491
|
+
if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
throw e;
|
|
495
|
+
}
|
|
496
|
+
})();
|
|
281
497
|
coalescedRequestsByDeduplicationKey[deduplicationKey] = {
|
|
282
498
|
abortController,
|
|
283
499
|
numConsumers: 0,
|
|
284
|
-
responsePromise
|
|
285
|
-
...config,
|
|
286
|
-
signal: abortController.signal
|
|
287
|
-
})
|
|
500
|
+
responsePromise
|
|
288
501
|
};
|
|
289
502
|
}
|
|
290
503
|
const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
|
|
@@ -351,7 +564,10 @@ var PING_PAYLOAD = {
|
|
|
351
564
|
jsonrpc: "2.0",
|
|
352
565
|
method: "ping"
|
|
353
566
|
};
|
|
354
|
-
function getWebSocketTransportWithAutoping({
|
|
567
|
+
function getWebSocketTransportWithAutoping({
|
|
568
|
+
intervalMs,
|
|
569
|
+
transport
|
|
570
|
+
}) {
|
|
355
571
|
const pingableConnections = /* @__PURE__ */ new Map();
|
|
356
572
|
return async (...args) => {
|
|
357
573
|
const connection = await transport(...args);
|
|
@@ -402,7 +618,10 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
|
402
618
|
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
403
619
|
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
404
620
|
);
|
|
405
|
-
function getWebSocketTransportWithConnectionSharding({
|
|
621
|
+
function getWebSocketTransportWithConnectionSharding({
|
|
622
|
+
getShard,
|
|
623
|
+
transport
|
|
624
|
+
}) {
|
|
406
625
|
return getCachedAbortableIterableFactory({
|
|
407
626
|
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
408
627
|
getCacheEntryMissingError(shardKey) {
|
|
@@ -438,22 +657,52 @@ function createDefaultRpcSubscriptionsTransport(config) {
|
|
|
438
657
|
}
|
|
439
658
|
|
|
440
659
|
// src/transaction-confirmation-strategy-blockheight.ts
|
|
441
|
-
function createBlockHeightExceedencePromiseFactory(
|
|
442
|
-
|
|
660
|
+
function createBlockHeightExceedencePromiseFactory({
|
|
661
|
+
rpc,
|
|
662
|
+
rpcSubscriptions
|
|
663
|
+
}) {
|
|
664
|
+
return async function getBlockHeightExceedencePromise({
|
|
665
|
+
abortSignal: callerAbortSignal,
|
|
666
|
+
commitment,
|
|
667
|
+
lastValidBlockHeight
|
|
668
|
+
}) {
|
|
443
669
|
const abortController = new AbortController();
|
|
444
|
-
|
|
670
|
+
const handleAbort = () => {
|
|
445
671
|
abortController.abort();
|
|
446
|
-
}
|
|
672
|
+
};
|
|
447
673
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
448
|
-
|
|
674
|
+
async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
|
|
675
|
+
const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
|
|
676
|
+
return {
|
|
677
|
+
blockHeight,
|
|
678
|
+
differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
|
|
679
|
+
};
|
|
680
|
+
}
|
|
449
681
|
try {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
682
|
+
const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
|
|
683
|
+
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
|
|
684
|
+
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
|
|
685
|
+
]);
|
|
686
|
+
if (blockHeight <= lastValidBlockHeight) {
|
|
687
|
+
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
|
|
688
|
+
for await (const slotNotification of slotNotifications) {
|
|
689
|
+
const { slot } = slotNotification;
|
|
690
|
+
if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
|
|
691
|
+
const {
|
|
692
|
+
blockHeight: currentBlockHeight,
|
|
693
|
+
differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
|
|
694
|
+
} = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
|
|
695
|
+
if (currentBlockHeight > lastValidBlockHeight) {
|
|
696
|
+
break;
|
|
697
|
+
} else {
|
|
698
|
+
lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
455
701
|
}
|
|
456
702
|
}
|
|
703
|
+
throw new Error(
|
|
704
|
+
"The network has progressed past the last block for which this transaction could have been committed."
|
|
705
|
+
);
|
|
457
706
|
} finally {
|
|
458
707
|
abortController.abort();
|
|
459
708
|
}
|
|
@@ -475,10 +724,12 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
475
724
|
}
|
|
476
725
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
477
726
|
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
727
|
+
const base58Decoder = getBase58Decoder();
|
|
728
|
+
const base64Encoder = getBase64Encoder();
|
|
478
729
|
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
479
|
-
const data =
|
|
730
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
480
731
|
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
481
|
-
return
|
|
732
|
+
return base58Decoder.decode(nonceValueBytes);
|
|
482
733
|
}
|
|
483
734
|
const nonceAccountDidAdvancePromise = (async () => {
|
|
484
735
|
for await (const accountNotification of accountNotifications) {
|
|
@@ -520,97 +771,48 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
520
771
|
}
|
|
521
772
|
};
|
|
522
773
|
}
|
|
523
|
-
function createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
524
|
-
return async function getSignatureConfirmationPromise({ abortSignal: callerAbortSignal, commitment, signature }) {
|
|
525
|
-
const abortController = new AbortController();
|
|
526
|
-
function handleAbort() {
|
|
527
|
-
abortController.abort();
|
|
528
|
-
}
|
|
529
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
530
|
-
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
531
|
-
const signatureDidCommitPromise = (async () => {
|
|
532
|
-
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
533
|
-
if (signatureStatusNotification.value.err) {
|
|
534
|
-
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
535
|
-
cause: signatureStatusNotification.value.err
|
|
536
|
-
});
|
|
537
|
-
} else {
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
})();
|
|
542
|
-
const signatureStatusLookupPromise = (async () => {
|
|
543
|
-
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
544
|
-
const signatureStatus = signatureStatusResults[0];
|
|
545
|
-
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
546
|
-
return;
|
|
547
|
-
} else {
|
|
548
|
-
await new Promise(() => {
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
})();
|
|
552
|
-
try {
|
|
553
|
-
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
554
|
-
} finally {
|
|
555
|
-
abortController.abort();
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
774
|
|
|
560
775
|
// src/transaction-confirmation.ts
|
|
561
|
-
async function raceStrategies(config, getSpecificStrategiesForRace) {
|
|
562
|
-
const { abortSignal: callerAbortSignal, commitment, getSignatureConfirmationPromise, transaction } = config;
|
|
563
|
-
callerAbortSignal.throwIfAborted();
|
|
564
|
-
const signature = getSignatureFromTransaction(transaction);
|
|
565
|
-
const abortController = new AbortController();
|
|
566
|
-
function handleAbort() {
|
|
567
|
-
abortController.abort();
|
|
568
|
-
}
|
|
569
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
570
|
-
try {
|
|
571
|
-
const specificStrategies = getSpecificStrategiesForRace({
|
|
572
|
-
...config,
|
|
573
|
-
abortSignal: abortController.signal
|
|
574
|
-
});
|
|
575
|
-
return await Promise.race([
|
|
576
|
-
getSignatureConfirmationPromise({
|
|
577
|
-
abortSignal: abortController.signal,
|
|
578
|
-
commitment,
|
|
579
|
-
signature
|
|
580
|
-
}),
|
|
581
|
-
...specificStrategies
|
|
582
|
-
]);
|
|
583
|
-
} finally {
|
|
584
|
-
abortController.abort();
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
776
|
function createDefaultDurableNonceTransactionConfirmer({
|
|
588
777
|
rpc,
|
|
589
778
|
rpcSubscriptions
|
|
590
779
|
}) {
|
|
591
780
|
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
592
|
-
const
|
|
593
|
-
|
|
781
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
782
|
+
rpc,
|
|
783
|
+
rpcSubscriptions
|
|
784
|
+
);
|
|
785
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
594
786
|
await waitForDurableNonceTransactionConfirmation({
|
|
595
787
|
...config,
|
|
596
788
|
getNonceInvalidationPromise,
|
|
597
|
-
|
|
789
|
+
getRecentSignatureConfirmationPromise
|
|
598
790
|
});
|
|
599
791
|
};
|
|
600
792
|
}
|
|
601
|
-
function
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
793
|
+
function createDefaultRecentTransactionConfirmer({
|
|
794
|
+
rpc,
|
|
795
|
+
rpcSubscriptions
|
|
796
|
+
}) {
|
|
797
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
798
|
+
rpc,
|
|
799
|
+
rpcSubscriptions
|
|
800
|
+
});
|
|
801
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
802
|
+
rpc,
|
|
803
|
+
rpcSubscriptions
|
|
804
|
+
);
|
|
805
|
+
return async function confirmRecentTransaction(config) {
|
|
806
|
+
await waitForRecentTransactionConfirmation({
|
|
606
807
|
...config,
|
|
607
808
|
getBlockHeightExceedencePromise,
|
|
608
|
-
|
|
809
|
+
getRecentSignatureConfirmationPromise
|
|
609
810
|
});
|
|
610
811
|
};
|
|
611
812
|
}
|
|
612
813
|
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
613
814
|
await raceStrategies(
|
|
815
|
+
getSignatureFromTransaction(config.transaction),
|
|
614
816
|
config,
|
|
615
817
|
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
616
818
|
return [
|
|
@@ -624,13 +826,20 @@ async function waitForDurableNonceTransactionConfirmation(config) {
|
|
|
624
826
|
}
|
|
625
827
|
);
|
|
626
828
|
}
|
|
627
|
-
async function
|
|
829
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
628
830
|
await raceStrategies(
|
|
831
|
+
getSignatureFromTransaction(config.transaction),
|
|
629
832
|
config,
|
|
630
|
-
function getSpecificStrategiesForRace({
|
|
833
|
+
function getSpecificStrategiesForRace({
|
|
834
|
+
abortSignal,
|
|
835
|
+
commitment,
|
|
836
|
+
getBlockHeightExceedencePromise,
|
|
837
|
+
transaction
|
|
838
|
+
}) {
|
|
631
839
|
return [
|
|
632
840
|
getBlockHeightExceedencePromise({
|
|
633
841
|
abortSignal,
|
|
842
|
+
commitment,
|
|
634
843
|
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
635
844
|
})
|
|
636
845
|
];
|
|
@@ -638,4 +847,120 @@ async function waitForTransactionConfirmation(config) {
|
|
|
638
847
|
);
|
|
639
848
|
}
|
|
640
849
|
|
|
641
|
-
|
|
850
|
+
// src/send-transaction.ts
|
|
851
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
852
|
+
if (
|
|
853
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
854
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
855
|
+
commitmentComparator(
|
|
856
|
+
commitment,
|
|
857
|
+
"finalized"
|
|
858
|
+
/* default value of `preflightCommitment` */
|
|
859
|
+
) < 0
|
|
860
|
+
) {
|
|
861
|
+
return {
|
|
862
|
+
...config,
|
|
863
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
864
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
865
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
866
|
+
// confirmation commitment.
|
|
867
|
+
preflightCommitment: commitment
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
return config;
|
|
871
|
+
}
|
|
872
|
+
async function sendTransaction_INTERNAL({
|
|
873
|
+
abortSignal,
|
|
874
|
+
commitment,
|
|
875
|
+
rpc,
|
|
876
|
+
transaction,
|
|
877
|
+
...sendTransactionConfig
|
|
878
|
+
}) {
|
|
879
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
880
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
881
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
882
|
+
encoding: "base64"
|
|
883
|
+
}).send({ abortSignal });
|
|
884
|
+
}
|
|
885
|
+
function createDefaultDurableNonceTransactionSender({
|
|
886
|
+
rpc,
|
|
887
|
+
rpcSubscriptions
|
|
888
|
+
}) {
|
|
889
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
890
|
+
rpc,
|
|
891
|
+
rpcSubscriptions
|
|
892
|
+
});
|
|
893
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
894
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
895
|
+
...config,
|
|
896
|
+
confirmDurableNonceTransaction,
|
|
897
|
+
rpc,
|
|
898
|
+
transaction
|
|
899
|
+
});
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
function createDefaultTransactionSender({
|
|
903
|
+
rpc,
|
|
904
|
+
rpcSubscriptions
|
|
905
|
+
}) {
|
|
906
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
907
|
+
rpc,
|
|
908
|
+
rpcSubscriptions
|
|
909
|
+
});
|
|
910
|
+
return async function sendTransaction(transaction, config) {
|
|
911
|
+
await sendAndConfirmTransaction({
|
|
912
|
+
...config,
|
|
913
|
+
confirmRecentTransaction,
|
|
914
|
+
rpc,
|
|
915
|
+
transaction
|
|
916
|
+
});
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
920
|
+
abortSignal,
|
|
921
|
+
commitment,
|
|
922
|
+
confirmDurableNonceTransaction,
|
|
923
|
+
rpc,
|
|
924
|
+
transaction,
|
|
925
|
+
...sendTransactionConfig
|
|
926
|
+
}) {
|
|
927
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
928
|
+
...sendTransactionConfig,
|
|
929
|
+
abortSignal,
|
|
930
|
+
commitment,
|
|
931
|
+
rpc,
|
|
932
|
+
transaction
|
|
933
|
+
});
|
|
934
|
+
await confirmDurableNonceTransaction({
|
|
935
|
+
abortSignal,
|
|
936
|
+
commitment,
|
|
937
|
+
transaction
|
|
938
|
+
});
|
|
939
|
+
return transactionSignature;
|
|
940
|
+
}
|
|
941
|
+
async function sendAndConfirmTransaction({
|
|
942
|
+
abortSignal,
|
|
943
|
+
commitment,
|
|
944
|
+
confirmRecentTransaction,
|
|
945
|
+
rpc,
|
|
946
|
+
transaction,
|
|
947
|
+
...sendTransactionConfig
|
|
948
|
+
}) {
|
|
949
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
950
|
+
...sendTransactionConfig,
|
|
951
|
+
abortSignal,
|
|
952
|
+
commitment,
|
|
953
|
+
rpc,
|
|
954
|
+
transaction
|
|
955
|
+
});
|
|
956
|
+
await confirmRecentTransaction({
|
|
957
|
+
abortSignal,
|
|
958
|
+
commitment,
|
|
959
|
+
transaction
|
|
960
|
+
});
|
|
961
|
+
return transactionSignature;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
export { createBlockHeightExceedencePromiseFactory, createDefaultAirdropRequester, createDefaultDurableNonceTransactionConfirmer, createDefaultDurableNonceTransactionSender, createDefaultRecentTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createDefaultTransactionSender, createNonceInvalidationPromiseFactory, createRecentSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, decodeTransaction, requestAndConfirmAirdrop, sendAndConfirmDurableNonceTransaction, sendAndConfirmTransaction, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation };
|
|
965
|
+
//# sourceMappingURL=out.js.map
|
|
966
|
+
//# sourceMappingURL=index.node.js.map
|