@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.browser.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);
|
|
@@ -413,7 +629,10 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
|
413
629
|
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
414
630
|
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
415
631
|
);
|
|
416
|
-
function getWebSocketTransportWithConnectionSharding({
|
|
632
|
+
function getWebSocketTransportWithConnectionSharding({
|
|
633
|
+
getShard,
|
|
634
|
+
transport
|
|
635
|
+
}) {
|
|
417
636
|
return getCachedAbortableIterableFactory({
|
|
418
637
|
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
419
638
|
getCacheEntryMissingError(shardKey) {
|
|
@@ -449,22 +668,52 @@ function createDefaultRpcSubscriptionsTransport(config) {
|
|
|
449
668
|
}
|
|
450
669
|
|
|
451
670
|
// src/transaction-confirmation-strategy-blockheight.ts
|
|
452
|
-
function createBlockHeightExceedencePromiseFactory(
|
|
453
|
-
|
|
671
|
+
function createBlockHeightExceedencePromiseFactory({
|
|
672
|
+
rpc,
|
|
673
|
+
rpcSubscriptions
|
|
674
|
+
}) {
|
|
675
|
+
return async function getBlockHeightExceedencePromise({
|
|
676
|
+
abortSignal: callerAbortSignal,
|
|
677
|
+
commitment,
|
|
678
|
+
lastValidBlockHeight
|
|
679
|
+
}) {
|
|
454
680
|
const abortController = new AbortController();
|
|
455
|
-
|
|
681
|
+
const handleAbort = () => {
|
|
456
682
|
abortController.abort();
|
|
457
|
-
}
|
|
683
|
+
};
|
|
458
684
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
459
|
-
|
|
685
|
+
async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
|
|
686
|
+
const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
|
|
687
|
+
return {
|
|
688
|
+
blockHeight,
|
|
689
|
+
differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
|
|
690
|
+
};
|
|
691
|
+
}
|
|
460
692
|
try {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
693
|
+
const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
|
|
694
|
+
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
|
|
695
|
+
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
|
|
696
|
+
]);
|
|
697
|
+
if (blockHeight <= lastValidBlockHeight) {
|
|
698
|
+
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
|
|
699
|
+
for await (const slotNotification of slotNotifications) {
|
|
700
|
+
const { slot } = slotNotification;
|
|
701
|
+
if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
|
|
702
|
+
const {
|
|
703
|
+
blockHeight: currentBlockHeight,
|
|
704
|
+
differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
|
|
705
|
+
} = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
|
|
706
|
+
if (currentBlockHeight > lastValidBlockHeight) {
|
|
707
|
+
break;
|
|
708
|
+
} else {
|
|
709
|
+
lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
466
712
|
}
|
|
467
713
|
}
|
|
714
|
+
throw new Error(
|
|
715
|
+
"The network has progressed past the last block for which this transaction could have been committed."
|
|
716
|
+
);
|
|
468
717
|
} finally {
|
|
469
718
|
abortController.abort();
|
|
470
719
|
}
|
|
@@ -486,10 +735,12 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
486
735
|
}
|
|
487
736
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
488
737
|
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
738
|
+
const base58Decoder = getBase58Decoder();
|
|
739
|
+
const base64Encoder = getBase64Encoder();
|
|
489
740
|
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
490
|
-
const data =
|
|
741
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
491
742
|
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
492
|
-
return
|
|
743
|
+
return base58Decoder.decode(nonceValueBytes);
|
|
493
744
|
}
|
|
494
745
|
const nonceAccountDidAdvancePromise = (async () => {
|
|
495
746
|
for await (const accountNotification of accountNotifications) {
|
|
@@ -531,97 +782,48 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
531
782
|
}
|
|
532
783
|
};
|
|
533
784
|
}
|
|
534
|
-
function createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
535
|
-
return async function getSignatureConfirmationPromise({ abortSignal: callerAbortSignal, commitment, signature }) {
|
|
536
|
-
const abortController = new AbortController();
|
|
537
|
-
function handleAbort() {
|
|
538
|
-
abortController.abort();
|
|
539
|
-
}
|
|
540
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
541
|
-
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
542
|
-
const signatureDidCommitPromise = (async () => {
|
|
543
|
-
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
544
|
-
if (signatureStatusNotification.value.err) {
|
|
545
|
-
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
546
|
-
cause: signatureStatusNotification.value.err
|
|
547
|
-
});
|
|
548
|
-
} else {
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
})();
|
|
553
|
-
const signatureStatusLookupPromise = (async () => {
|
|
554
|
-
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
555
|
-
const signatureStatus = signatureStatusResults[0];
|
|
556
|
-
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
557
|
-
return;
|
|
558
|
-
} else {
|
|
559
|
-
await new Promise(() => {
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
})();
|
|
563
|
-
try {
|
|
564
|
-
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
565
|
-
} finally {
|
|
566
|
-
abortController.abort();
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
785
|
|
|
571
786
|
// src/transaction-confirmation.ts
|
|
572
|
-
async function raceStrategies(config, getSpecificStrategiesForRace) {
|
|
573
|
-
const { abortSignal: callerAbortSignal, commitment, getSignatureConfirmationPromise, transaction } = config;
|
|
574
|
-
callerAbortSignal.throwIfAborted();
|
|
575
|
-
const signature = getSignatureFromTransaction(transaction);
|
|
576
|
-
const abortController = new AbortController();
|
|
577
|
-
function handleAbort() {
|
|
578
|
-
abortController.abort();
|
|
579
|
-
}
|
|
580
|
-
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
581
|
-
try {
|
|
582
|
-
const specificStrategies = getSpecificStrategiesForRace({
|
|
583
|
-
...config,
|
|
584
|
-
abortSignal: abortController.signal
|
|
585
|
-
});
|
|
586
|
-
return await Promise.race([
|
|
587
|
-
getSignatureConfirmationPromise({
|
|
588
|
-
abortSignal: abortController.signal,
|
|
589
|
-
commitment,
|
|
590
|
-
signature
|
|
591
|
-
}),
|
|
592
|
-
...specificStrategies
|
|
593
|
-
]);
|
|
594
|
-
} finally {
|
|
595
|
-
abortController.abort();
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
787
|
function createDefaultDurableNonceTransactionConfirmer({
|
|
599
788
|
rpc,
|
|
600
789
|
rpcSubscriptions
|
|
601
790
|
}) {
|
|
602
791
|
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
603
|
-
const
|
|
604
|
-
|
|
792
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
793
|
+
rpc,
|
|
794
|
+
rpcSubscriptions
|
|
795
|
+
);
|
|
796
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
605
797
|
await waitForDurableNonceTransactionConfirmation({
|
|
606
798
|
...config,
|
|
607
799
|
getNonceInvalidationPromise,
|
|
608
|
-
|
|
800
|
+
getRecentSignatureConfirmationPromise
|
|
609
801
|
});
|
|
610
802
|
};
|
|
611
803
|
}
|
|
612
|
-
function
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
804
|
+
function createDefaultRecentTransactionConfirmer({
|
|
805
|
+
rpc,
|
|
806
|
+
rpcSubscriptions
|
|
807
|
+
}) {
|
|
808
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
809
|
+
rpc,
|
|
810
|
+
rpcSubscriptions
|
|
811
|
+
});
|
|
812
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
813
|
+
rpc,
|
|
814
|
+
rpcSubscriptions
|
|
815
|
+
);
|
|
816
|
+
return async function confirmRecentTransaction(config) {
|
|
817
|
+
await waitForRecentTransactionConfirmation({
|
|
617
818
|
...config,
|
|
618
819
|
getBlockHeightExceedencePromise,
|
|
619
|
-
|
|
820
|
+
getRecentSignatureConfirmationPromise
|
|
620
821
|
});
|
|
621
822
|
};
|
|
622
823
|
}
|
|
623
824
|
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
624
825
|
await raceStrategies(
|
|
826
|
+
getSignatureFromTransaction(config.transaction),
|
|
625
827
|
config,
|
|
626
828
|
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
627
829
|
return [
|
|
@@ -635,13 +837,20 @@ async function waitForDurableNonceTransactionConfirmation(config) {
|
|
|
635
837
|
}
|
|
636
838
|
);
|
|
637
839
|
}
|
|
638
|
-
async function
|
|
840
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
639
841
|
await raceStrategies(
|
|
842
|
+
getSignatureFromTransaction(config.transaction),
|
|
640
843
|
config,
|
|
641
|
-
function getSpecificStrategiesForRace({
|
|
844
|
+
function getSpecificStrategiesForRace({
|
|
845
|
+
abortSignal,
|
|
846
|
+
commitment,
|
|
847
|
+
getBlockHeightExceedencePromise,
|
|
848
|
+
transaction
|
|
849
|
+
}) {
|
|
642
850
|
return [
|
|
643
851
|
getBlockHeightExceedencePromise({
|
|
644
852
|
abortSignal,
|
|
853
|
+
commitment,
|
|
645
854
|
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
646
855
|
})
|
|
647
856
|
];
|
|
@@ -649,6 +858,120 @@ async function waitForTransactionConfirmation(config) {
|
|
|
649
858
|
);
|
|
650
859
|
}
|
|
651
860
|
|
|
652
|
-
|
|
861
|
+
// src/send-transaction.ts
|
|
862
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
863
|
+
if (
|
|
864
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
865
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
866
|
+
commitmentComparator(
|
|
867
|
+
commitment,
|
|
868
|
+
"finalized"
|
|
869
|
+
/* default value of `preflightCommitment` */
|
|
870
|
+
) < 0
|
|
871
|
+
) {
|
|
872
|
+
return {
|
|
873
|
+
...config,
|
|
874
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
875
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
876
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
877
|
+
// confirmation commitment.
|
|
878
|
+
preflightCommitment: commitment
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
return config;
|
|
882
|
+
}
|
|
883
|
+
async function sendTransaction_INTERNAL({
|
|
884
|
+
abortSignal,
|
|
885
|
+
commitment,
|
|
886
|
+
rpc,
|
|
887
|
+
transaction,
|
|
888
|
+
...sendTransactionConfig
|
|
889
|
+
}) {
|
|
890
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
891
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
892
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
893
|
+
encoding: "base64"
|
|
894
|
+
}).send({ abortSignal });
|
|
895
|
+
}
|
|
896
|
+
function createDefaultDurableNonceTransactionSender({
|
|
897
|
+
rpc,
|
|
898
|
+
rpcSubscriptions
|
|
899
|
+
}) {
|
|
900
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
901
|
+
rpc,
|
|
902
|
+
rpcSubscriptions
|
|
903
|
+
});
|
|
904
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
905
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
906
|
+
...config,
|
|
907
|
+
confirmDurableNonceTransaction,
|
|
908
|
+
rpc,
|
|
909
|
+
transaction
|
|
910
|
+
});
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
function createDefaultTransactionSender({
|
|
914
|
+
rpc,
|
|
915
|
+
rpcSubscriptions
|
|
916
|
+
}) {
|
|
917
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
918
|
+
rpc,
|
|
919
|
+
rpcSubscriptions
|
|
920
|
+
});
|
|
921
|
+
return async function sendTransaction(transaction, config) {
|
|
922
|
+
await sendAndConfirmTransaction({
|
|
923
|
+
...config,
|
|
924
|
+
confirmRecentTransaction,
|
|
925
|
+
rpc,
|
|
926
|
+
transaction
|
|
927
|
+
});
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
931
|
+
abortSignal,
|
|
932
|
+
commitment,
|
|
933
|
+
confirmDurableNonceTransaction,
|
|
934
|
+
rpc,
|
|
935
|
+
transaction,
|
|
936
|
+
...sendTransactionConfig
|
|
937
|
+
}) {
|
|
938
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
939
|
+
...sendTransactionConfig,
|
|
940
|
+
abortSignal,
|
|
941
|
+
commitment,
|
|
942
|
+
rpc,
|
|
943
|
+
transaction
|
|
944
|
+
});
|
|
945
|
+
await confirmDurableNonceTransaction({
|
|
946
|
+
abortSignal,
|
|
947
|
+
commitment,
|
|
948
|
+
transaction
|
|
949
|
+
});
|
|
950
|
+
return transactionSignature;
|
|
951
|
+
}
|
|
952
|
+
async function sendAndConfirmTransaction({
|
|
953
|
+
abortSignal,
|
|
954
|
+
commitment,
|
|
955
|
+
confirmRecentTransaction,
|
|
956
|
+
rpc,
|
|
957
|
+
transaction,
|
|
958
|
+
...sendTransactionConfig
|
|
959
|
+
}) {
|
|
960
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
961
|
+
...sendTransactionConfig,
|
|
962
|
+
abortSignal,
|
|
963
|
+
commitment,
|
|
964
|
+
rpc,
|
|
965
|
+
transaction
|
|
966
|
+
});
|
|
967
|
+
await confirmRecentTransaction({
|
|
968
|
+
abortSignal,
|
|
969
|
+
commitment,
|
|
970
|
+
transaction
|
|
971
|
+
});
|
|
972
|
+
return transactionSignature;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
export { createBlockHeightExceedencePromiseFactory, createDefaultAirdropRequester, createDefaultDurableNonceTransactionConfirmer, createDefaultDurableNonceTransactionSender, createDefaultRecentTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createDefaultTransactionSender, createNonceInvalidationPromiseFactory, createRecentSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, decodeTransaction, requestAndConfirmAirdrop, sendAndConfirmDurableNonceTransaction, sendAndConfirmTransaction, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation };
|
|
653
976
|
//# sourceMappingURL=out.js.map
|
|
654
977
|
//# sourceMappingURL=index.browser.js.map
|