@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.cjs
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var accounts = require('@solana/accounts');
|
|
3
4
|
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecs = require('@solana/codecs');
|
|
6
|
+
var functional = require('@solana/functional');
|
|
4
7
|
var instructions = require('@solana/instructions');
|
|
5
8
|
var keys = require('@solana/keys');
|
|
9
|
+
var programs = require('@solana/programs');
|
|
10
|
+
var rpcParsedTypes = require('@solana/rpc-parsed-types');
|
|
11
|
+
var rpcTypes = require('@solana/rpc-types');
|
|
12
|
+
var signers = require('@solana/signers');
|
|
6
13
|
var transactions = require('@solana/transactions');
|
|
7
|
-
var functional = require('@solana/functional');
|
|
8
14
|
var rpcCore = require('@solana/rpc-core');
|
|
9
15
|
var rpcTransport = require('@solana/rpc-transport');
|
|
10
16
|
var fastStableStringify = require('fast-stable-stringify');
|
|
11
|
-
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
12
17
|
|
|
13
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
19
|
|
|
@@ -17,25 +22,217 @@ var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableString
|
|
|
17
22
|
// ../build-scripts/env-shim.ts
|
|
18
23
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
19
24
|
|
|
25
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
26
|
+
async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
|
|
27
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
28
|
+
callerAbortSignal?.throwIfAborted();
|
|
29
|
+
const abortController = new AbortController();
|
|
30
|
+
if (callerAbortSignal) {
|
|
31
|
+
const handleAbort = () => {
|
|
32
|
+
abortController.abort();
|
|
33
|
+
};
|
|
34
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
38
|
+
...config,
|
|
39
|
+
abortSignal: abortController.signal
|
|
40
|
+
});
|
|
41
|
+
return await Promise.race([
|
|
42
|
+
getRecentSignatureConfirmationPromise({
|
|
43
|
+
abortSignal: abortController.signal,
|
|
44
|
+
commitment,
|
|
45
|
+
signature
|
|
46
|
+
}),
|
|
47
|
+
...specificStrategies
|
|
48
|
+
]);
|
|
49
|
+
} finally {
|
|
50
|
+
abortController.abort();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
54
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
55
|
+
abortSignal: callerAbortSignal,
|
|
56
|
+
commitment,
|
|
57
|
+
signature
|
|
58
|
+
}) {
|
|
59
|
+
const abortController = new AbortController();
|
|
60
|
+
function handleAbort() {
|
|
61
|
+
abortController.abort();
|
|
62
|
+
}
|
|
63
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
64
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
65
|
+
const signatureDidCommitPromise = (async () => {
|
|
66
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
67
|
+
if (signatureStatusNotification.value.err) {
|
|
68
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
69
|
+
cause: signatureStatusNotification.value.err
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
const signatureStatusLookupPromise = (async () => {
|
|
77
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
78
|
+
const signatureStatus = signatureStatusResults[0];
|
|
79
|
+
if (signatureStatus && signatureStatus.confirmationStatus && rpcTypes.commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
80
|
+
return;
|
|
81
|
+
} else {
|
|
82
|
+
await new Promise(() => {
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
try {
|
|
87
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
88
|
+
} finally {
|
|
89
|
+
abortController.abort();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
95
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
96
|
+
return await new Promise((_, reject) => {
|
|
97
|
+
const handleAbort = (e) => {
|
|
98
|
+
clearTimeout(timeoutId);
|
|
99
|
+
const abortError = new DOMException(e.target.reason, "AbortError");
|
|
100
|
+
reject(abortError);
|
|
101
|
+
};
|
|
102
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
103
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
104
|
+
const startMs = performance.now();
|
|
105
|
+
const timeoutId = (
|
|
106
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
107
|
+
// elapsed time instead of active time.
|
|
108
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
const elapsedMs = performance.now() - startMs;
|
|
111
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
112
|
+
}, timeoutMs)
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/airdrop-confirmer.ts
|
|
118
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
119
|
+
rpc,
|
|
120
|
+
rpcSubscriptions
|
|
121
|
+
}) {
|
|
122
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
123
|
+
rpc,
|
|
124
|
+
rpcSubscriptions
|
|
125
|
+
);
|
|
126
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
127
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
128
|
+
...config,
|
|
129
|
+
getRecentSignatureConfirmationPromise,
|
|
130
|
+
getTimeoutPromise
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
135
|
+
await raceStrategies(
|
|
136
|
+
config.signature,
|
|
137
|
+
config,
|
|
138
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
139
|
+
return [
|
|
140
|
+
getTimeoutPromise2({
|
|
141
|
+
abortSignal,
|
|
142
|
+
commitment
|
|
143
|
+
})
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/airdrop.ts
|
|
150
|
+
function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
|
|
151
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
152
|
+
rpc,
|
|
153
|
+
rpcSubscriptions
|
|
154
|
+
});
|
|
155
|
+
return async function requestAirdrop(config) {
|
|
156
|
+
return await requestAndConfirmAirdrop({
|
|
157
|
+
...config,
|
|
158
|
+
confirmSignatureOnlyTransaction,
|
|
159
|
+
rpc
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async function requestAndConfirmAirdrop({
|
|
164
|
+
abortSignal,
|
|
165
|
+
commitment,
|
|
166
|
+
confirmSignatureOnlyTransaction,
|
|
167
|
+
lamports,
|
|
168
|
+
recipientAddress,
|
|
169
|
+
rpc
|
|
170
|
+
}) {
|
|
171
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
172
|
+
await confirmSignatureOnlyTransaction({
|
|
173
|
+
abortSignal,
|
|
174
|
+
commitment,
|
|
175
|
+
signature: airdropTransactionSignature
|
|
176
|
+
});
|
|
177
|
+
return airdropTransactionSignature;
|
|
178
|
+
}
|
|
179
|
+
var compiledTransactionDecoder = void 0;
|
|
180
|
+
async function fetchLookupTables(lookupTableAddresses, rpc, config) {
|
|
181
|
+
const fetchedLookupTables = await accounts.fetchJsonParsedAccounts(
|
|
182
|
+
rpc,
|
|
183
|
+
lookupTableAddresses,
|
|
184
|
+
config
|
|
185
|
+
);
|
|
186
|
+
accounts.assertAccountsDecoded(fetchedLookupTables);
|
|
187
|
+
accounts.assertAccountsExist(fetchedLookupTables);
|
|
188
|
+
return fetchedLookupTables.reduce((acc, lookup) => {
|
|
189
|
+
return {
|
|
190
|
+
...acc,
|
|
191
|
+
[lookup.address]: lookup.data.addresses
|
|
192
|
+
};
|
|
193
|
+
}, {});
|
|
194
|
+
}
|
|
195
|
+
async function decodeTransaction(encodedTransaction, rpc, config) {
|
|
196
|
+
const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};
|
|
197
|
+
if (!compiledTransactionDecoder)
|
|
198
|
+
compiledTransactionDecoder = transactions.getCompiledTransactionDecoder();
|
|
199
|
+
const compiledTransaction = compiledTransactionDecoder.decode(encodedTransaction);
|
|
200
|
+
const { compiledMessage } = compiledTransaction;
|
|
201
|
+
const lookupTables = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? compiledMessage.addressTableLookups : [];
|
|
202
|
+
const lookupTableAddresses = lookupTables.map((l) => l.lookupTableAddress);
|
|
203
|
+
const fetchedLookupTables = lookupTableAddresses.length > 0 ? await fetchLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig) : {};
|
|
204
|
+
return transactions.decompileTransaction(compiledTransaction, {
|
|
205
|
+
addressesByLookupTableAddress: fetchedLookupTables,
|
|
206
|
+
lastValidBlockHeight
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
20
210
|
// src/rpc-integer-overflow-error.ts
|
|
21
211
|
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
212
|
+
methodName;
|
|
213
|
+
keyPath;
|
|
214
|
+
value;
|
|
22
215
|
constructor(methodName, keyPath, value) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
216
|
+
let argumentLabel = "";
|
|
217
|
+
if (typeof keyPath[0] === "number") {
|
|
218
|
+
const argPosition = keyPath[0] + 1;
|
|
219
|
+
const lastDigit = argPosition % 10;
|
|
220
|
+
const lastTwoDigits = argPosition % 100;
|
|
221
|
+
if (lastDigit == 1 && lastTwoDigits != 11) {
|
|
222
|
+
argumentLabel = argPosition + "st";
|
|
223
|
+
} else if (lastDigit == 2 && lastTwoDigits != 12) {
|
|
224
|
+
argumentLabel = argPosition + "nd";
|
|
225
|
+
} else if (lastDigit == 3 && lastTwoDigits != 13) {
|
|
226
|
+
argumentLabel = argPosition + "rd";
|
|
227
|
+
} else {
|
|
228
|
+
argumentLabel = argPosition + "th";
|
|
229
|
+
}
|
|
33
230
|
} else {
|
|
34
|
-
|
|
231
|
+
argumentLabel = `\`${keyPath[0].toString()}\``;
|
|
35
232
|
}
|
|
36
233
|
const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
|
|
37
234
|
super(
|
|
38
|
-
`The ${
|
|
235
|
+
`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\`.`
|
|
39
236
|
);
|
|
40
237
|
this.keyPath = keyPath;
|
|
41
238
|
this.methodName = methodName;
|
|
@@ -48,6 +245,7 @@ var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
|
48
245
|
|
|
49
246
|
// src/rpc-default-config.ts
|
|
50
247
|
var DEFAULT_RPC_CONFIG = {
|
|
248
|
+
defaultCommitment: "confirmed",
|
|
51
249
|
onIntegerOverflow(methodName, keyPath, value) {
|
|
52
250
|
throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
|
|
53
251
|
}
|
|
@@ -207,11 +405,11 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
|
207
405
|
return {
|
|
208
406
|
...iterable,
|
|
209
407
|
async *[Symbol.asyncIterator]() {
|
|
210
|
-
abortPromise
|
|
408
|
+
abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
211
409
|
abortSignal.addEventListener("abort", () => {
|
|
212
410
|
reject(EXPLICIT_ABORT_TOKEN);
|
|
213
411
|
});
|
|
214
|
-
})
|
|
412
|
+
});
|
|
215
413
|
try {
|
|
216
414
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
217
415
|
while (true) {
|
|
@@ -242,9 +440,10 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
|
242
440
|
|
|
243
441
|
// src/rpc.ts
|
|
244
442
|
function createSolanaRpc(config) {
|
|
443
|
+
const api = rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG);
|
|
245
444
|
return rpcTransport.createJsonRpc({
|
|
246
445
|
...config,
|
|
247
|
-
api
|
|
446
|
+
api
|
|
248
447
|
});
|
|
249
448
|
}
|
|
250
449
|
function createSolanaRpcSubscriptions(config) {
|
|
@@ -283,13 +482,23 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
283
482
|
}
|
|
284
483
|
if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
|
|
285
484
|
const abortController = new AbortController();
|
|
485
|
+
const responsePromise = (async () => {
|
|
486
|
+
try {
|
|
487
|
+
return await transport({
|
|
488
|
+
...config,
|
|
489
|
+
signal: abortController.signal
|
|
490
|
+
});
|
|
491
|
+
} catch (e) {
|
|
492
|
+
if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
throw e;
|
|
496
|
+
}
|
|
497
|
+
})();
|
|
286
498
|
coalescedRequestsByDeduplicationKey[deduplicationKey] = {
|
|
287
499
|
abortController,
|
|
288
500
|
numConsumers: 0,
|
|
289
|
-
responsePromise
|
|
290
|
-
...config,
|
|
291
|
-
signal: abortController.signal
|
|
292
|
-
})
|
|
501
|
+
responsePromise
|
|
293
502
|
};
|
|
294
503
|
}
|
|
295
504
|
const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
|
|
@@ -356,7 +565,10 @@ var PING_PAYLOAD = {
|
|
|
356
565
|
jsonrpc: "2.0",
|
|
357
566
|
method: "ping"
|
|
358
567
|
};
|
|
359
|
-
function getWebSocketTransportWithAutoping({
|
|
568
|
+
function getWebSocketTransportWithAutoping({
|
|
569
|
+
intervalMs,
|
|
570
|
+
transport
|
|
571
|
+
}) {
|
|
360
572
|
const pingableConnections = /* @__PURE__ */ new Map();
|
|
361
573
|
return async (...args) => {
|
|
362
574
|
const connection = await transport(...args);
|
|
@@ -407,7 +619,10 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
|
407
619
|
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
408
620
|
__DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
|
|
409
621
|
);
|
|
410
|
-
function getWebSocketTransportWithConnectionSharding({
|
|
622
|
+
function getWebSocketTransportWithConnectionSharding({
|
|
623
|
+
getShard,
|
|
624
|
+
transport
|
|
625
|
+
}) {
|
|
411
626
|
return getCachedAbortableIterableFactory({
|
|
412
627
|
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
413
628
|
getCacheEntryMissingError(shardKey) {
|
|
@@ -443,22 +658,52 @@ function createDefaultRpcSubscriptionsTransport(config) {
|
|
|
443
658
|
}
|
|
444
659
|
|
|
445
660
|
// src/transaction-confirmation-strategy-blockheight.ts
|
|
446
|
-
function createBlockHeightExceedencePromiseFactory(
|
|
447
|
-
|
|
661
|
+
function createBlockHeightExceedencePromiseFactory({
|
|
662
|
+
rpc,
|
|
663
|
+
rpcSubscriptions
|
|
664
|
+
}) {
|
|
665
|
+
return async function getBlockHeightExceedencePromise({
|
|
666
|
+
abortSignal: callerAbortSignal,
|
|
667
|
+
commitment,
|
|
668
|
+
lastValidBlockHeight
|
|
669
|
+
}) {
|
|
448
670
|
const abortController = new AbortController();
|
|
449
|
-
|
|
671
|
+
const handleAbort = () => {
|
|
450
672
|
abortController.abort();
|
|
451
|
-
}
|
|
673
|
+
};
|
|
452
674
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
453
|
-
|
|
675
|
+
async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
|
|
676
|
+
const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
|
|
677
|
+
return {
|
|
678
|
+
blockHeight,
|
|
679
|
+
differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
|
|
680
|
+
};
|
|
681
|
+
}
|
|
454
682
|
try {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
683
|
+
const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
|
|
684
|
+
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
|
|
685
|
+
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
|
|
686
|
+
]);
|
|
687
|
+
if (blockHeight <= lastValidBlockHeight) {
|
|
688
|
+
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
|
|
689
|
+
for await (const slotNotification of slotNotifications) {
|
|
690
|
+
const { slot } = slotNotification;
|
|
691
|
+
if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
|
|
692
|
+
const {
|
|
693
|
+
blockHeight: currentBlockHeight,
|
|
694
|
+
differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
|
|
695
|
+
} = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
|
|
696
|
+
if (currentBlockHeight > lastValidBlockHeight) {
|
|
697
|
+
break;
|
|
698
|
+
} else {
|
|
699
|
+
lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
460
702
|
}
|
|
461
703
|
}
|
|
704
|
+
throw new Error(
|
|
705
|
+
"The network has progressed past the last block for which this transaction could have been committed."
|
|
706
|
+
);
|
|
462
707
|
} finally {
|
|
463
708
|
abortController.abort();
|
|
464
709
|
}
|
|
@@ -480,10 +725,12 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
480
725
|
}
|
|
481
726
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
482
727
|
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
728
|
+
const base58Decoder = codecs.getBase58Decoder();
|
|
729
|
+
const base64Encoder = codecs.getBase64Encoder();
|
|
483
730
|
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
484
|
-
const data =
|
|
731
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
485
732
|
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
486
|
-
return
|
|
733
|
+
return base58Decoder.decode(nonceValueBytes);
|
|
487
734
|
}
|
|
488
735
|
const nonceAccountDidAdvancePromise = (async () => {
|
|
489
736
|
for await (const accountNotification of accountNotifications) {
|
|
@@ -525,97 +772,48 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
525
772
|
}
|
|
526
773
|
};
|
|
527
774
|
}
|
|
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
775
|
|
|
565
776
|
// 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
777
|
function createDefaultDurableNonceTransactionConfirmer({
|
|
593
778
|
rpc,
|
|
594
779
|
rpcSubscriptions
|
|
595
780
|
}) {
|
|
596
781
|
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
597
|
-
const
|
|
598
|
-
|
|
782
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
783
|
+
rpc,
|
|
784
|
+
rpcSubscriptions
|
|
785
|
+
);
|
|
786
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
599
787
|
await waitForDurableNonceTransactionConfirmation({
|
|
600
788
|
...config,
|
|
601
789
|
getNonceInvalidationPromise,
|
|
602
|
-
|
|
790
|
+
getRecentSignatureConfirmationPromise
|
|
603
791
|
});
|
|
604
792
|
};
|
|
605
793
|
}
|
|
606
|
-
function
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
794
|
+
function createDefaultRecentTransactionConfirmer({
|
|
795
|
+
rpc,
|
|
796
|
+
rpcSubscriptions
|
|
797
|
+
}) {
|
|
798
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
799
|
+
rpc,
|
|
800
|
+
rpcSubscriptions
|
|
801
|
+
});
|
|
802
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
803
|
+
rpc,
|
|
804
|
+
rpcSubscriptions
|
|
805
|
+
);
|
|
806
|
+
return async function confirmRecentTransaction(config) {
|
|
807
|
+
await waitForRecentTransactionConfirmation({
|
|
611
808
|
...config,
|
|
612
809
|
getBlockHeightExceedencePromise,
|
|
613
|
-
|
|
810
|
+
getRecentSignatureConfirmationPromise
|
|
614
811
|
});
|
|
615
812
|
};
|
|
616
813
|
}
|
|
617
814
|
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
618
815
|
await raceStrategies(
|
|
816
|
+
transactions.getSignatureFromTransaction(config.transaction),
|
|
619
817
|
config,
|
|
620
818
|
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
621
819
|
return [
|
|
@@ -629,13 +827,20 @@ async function waitForDurableNonceTransactionConfirmation(config) {
|
|
|
629
827
|
}
|
|
630
828
|
);
|
|
631
829
|
}
|
|
632
|
-
async function
|
|
830
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
633
831
|
await raceStrategies(
|
|
832
|
+
transactions.getSignatureFromTransaction(config.transaction),
|
|
634
833
|
config,
|
|
635
|
-
function getSpecificStrategiesForRace({
|
|
834
|
+
function getSpecificStrategiesForRace({
|
|
835
|
+
abortSignal,
|
|
836
|
+
commitment,
|
|
837
|
+
getBlockHeightExceedencePromise,
|
|
838
|
+
transaction
|
|
839
|
+
}) {
|
|
636
840
|
return [
|
|
637
841
|
getBlockHeightExceedencePromise({
|
|
638
842
|
abortSignal,
|
|
843
|
+
commitment,
|
|
639
844
|
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
640
845
|
})
|
|
641
846
|
];
|
|
@@ -643,24 +848,163 @@ async function waitForTransactionConfirmation(config) {
|
|
|
643
848
|
);
|
|
644
849
|
}
|
|
645
850
|
|
|
851
|
+
// src/send-transaction.ts
|
|
852
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
853
|
+
if (
|
|
854
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
855
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
856
|
+
rpcTypes.commitmentComparator(
|
|
857
|
+
commitment,
|
|
858
|
+
"finalized"
|
|
859
|
+
/* default value of `preflightCommitment` */
|
|
860
|
+
) < 0
|
|
861
|
+
) {
|
|
862
|
+
return {
|
|
863
|
+
...config,
|
|
864
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
865
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
866
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
867
|
+
// confirmation commitment.
|
|
868
|
+
preflightCommitment: commitment
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
return config;
|
|
872
|
+
}
|
|
873
|
+
async function sendTransaction_INTERNAL({
|
|
874
|
+
abortSignal,
|
|
875
|
+
commitment,
|
|
876
|
+
rpc,
|
|
877
|
+
transaction,
|
|
878
|
+
...sendTransactionConfig
|
|
879
|
+
}) {
|
|
880
|
+
const base64EncodedWireTransaction = transactions.getBase64EncodedWireTransaction(transaction);
|
|
881
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
882
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
883
|
+
encoding: "base64"
|
|
884
|
+
}).send({ abortSignal });
|
|
885
|
+
}
|
|
886
|
+
function createDefaultDurableNonceTransactionSender({
|
|
887
|
+
rpc,
|
|
888
|
+
rpcSubscriptions
|
|
889
|
+
}) {
|
|
890
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
891
|
+
rpc,
|
|
892
|
+
rpcSubscriptions
|
|
893
|
+
});
|
|
894
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
895
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
896
|
+
...config,
|
|
897
|
+
confirmDurableNonceTransaction,
|
|
898
|
+
rpc,
|
|
899
|
+
transaction
|
|
900
|
+
});
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
function createDefaultTransactionSender({
|
|
904
|
+
rpc,
|
|
905
|
+
rpcSubscriptions
|
|
906
|
+
}) {
|
|
907
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
908
|
+
rpc,
|
|
909
|
+
rpcSubscriptions
|
|
910
|
+
});
|
|
911
|
+
return async function sendTransaction(transaction, config) {
|
|
912
|
+
await sendAndConfirmTransaction({
|
|
913
|
+
...config,
|
|
914
|
+
confirmRecentTransaction,
|
|
915
|
+
rpc,
|
|
916
|
+
transaction
|
|
917
|
+
});
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
921
|
+
abortSignal,
|
|
922
|
+
commitment,
|
|
923
|
+
confirmDurableNonceTransaction,
|
|
924
|
+
rpc,
|
|
925
|
+
transaction,
|
|
926
|
+
...sendTransactionConfig
|
|
927
|
+
}) {
|
|
928
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
929
|
+
...sendTransactionConfig,
|
|
930
|
+
abortSignal,
|
|
931
|
+
commitment,
|
|
932
|
+
rpc,
|
|
933
|
+
transaction
|
|
934
|
+
});
|
|
935
|
+
await confirmDurableNonceTransaction({
|
|
936
|
+
abortSignal,
|
|
937
|
+
commitment,
|
|
938
|
+
transaction
|
|
939
|
+
});
|
|
940
|
+
return transactionSignature;
|
|
941
|
+
}
|
|
942
|
+
async function sendAndConfirmTransaction({
|
|
943
|
+
abortSignal,
|
|
944
|
+
commitment,
|
|
945
|
+
confirmRecentTransaction,
|
|
946
|
+
rpc,
|
|
947
|
+
transaction,
|
|
948
|
+
...sendTransactionConfig
|
|
949
|
+
}) {
|
|
950
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
951
|
+
...sendTransactionConfig,
|
|
952
|
+
abortSignal,
|
|
953
|
+
commitment,
|
|
954
|
+
rpc,
|
|
955
|
+
transaction
|
|
956
|
+
});
|
|
957
|
+
await confirmRecentTransaction({
|
|
958
|
+
abortSignal,
|
|
959
|
+
commitment,
|
|
960
|
+
transaction
|
|
961
|
+
});
|
|
962
|
+
return transactionSignature;
|
|
963
|
+
}
|
|
964
|
+
|
|
646
965
|
exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
|
|
966
|
+
exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
|
|
647
967
|
exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
|
|
968
|
+
exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
|
|
969
|
+
exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
|
|
648
970
|
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
649
971
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
650
|
-
exports.
|
|
972
|
+
exports.createDefaultTransactionSender = createDefaultTransactionSender;
|
|
651
973
|
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
652
|
-
exports.
|
|
974
|
+
exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
|
|
653
975
|
exports.createSolanaRpc = createSolanaRpc;
|
|
654
976
|
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
655
977
|
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
978
|
+
exports.decodeTransaction = decodeTransaction;
|
|
979
|
+
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
980
|
+
exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
|
|
981
|
+
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
656
982
|
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
657
|
-
exports.
|
|
983
|
+
exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
|
|
984
|
+
Object.keys(accounts).forEach(function (k) {
|
|
985
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
986
|
+
enumerable: true,
|
|
987
|
+
get: function () { return accounts[k]; }
|
|
988
|
+
});
|
|
989
|
+
});
|
|
658
990
|
Object.keys(addresses).forEach(function (k) {
|
|
659
991
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
660
992
|
enumerable: true,
|
|
661
993
|
get: function () { return addresses[k]; }
|
|
662
994
|
});
|
|
663
995
|
});
|
|
996
|
+
Object.keys(codecs).forEach(function (k) {
|
|
997
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
998
|
+
enumerable: true,
|
|
999
|
+
get: function () { return codecs[k]; }
|
|
1000
|
+
});
|
|
1001
|
+
});
|
|
1002
|
+
Object.keys(functional).forEach(function (k) {
|
|
1003
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1004
|
+
enumerable: true,
|
|
1005
|
+
get: function () { return functional[k]; }
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
664
1008
|
Object.keys(instructions).forEach(function (k) {
|
|
665
1009
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
666
1010
|
enumerable: true,
|
|
@@ -673,9 +1017,35 @@ Object.keys(keys).forEach(function (k) {
|
|
|
673
1017
|
get: function () { return keys[k]; }
|
|
674
1018
|
});
|
|
675
1019
|
});
|
|
1020
|
+
Object.keys(programs).forEach(function (k) {
|
|
1021
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1022
|
+
enumerable: true,
|
|
1023
|
+
get: function () { return programs[k]; }
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
Object.keys(rpcParsedTypes).forEach(function (k) {
|
|
1027
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1028
|
+
enumerable: true,
|
|
1029
|
+
get: function () { return rpcParsedTypes[k]; }
|
|
1030
|
+
});
|
|
1031
|
+
});
|
|
1032
|
+
Object.keys(rpcTypes).forEach(function (k) {
|
|
1033
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1034
|
+
enumerable: true,
|
|
1035
|
+
get: function () { return rpcTypes[k]; }
|
|
1036
|
+
});
|
|
1037
|
+
});
|
|
1038
|
+
Object.keys(signers).forEach(function (k) {
|
|
1039
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1040
|
+
enumerable: true,
|
|
1041
|
+
get: function () { return signers[k]; }
|
|
1042
|
+
});
|
|
1043
|
+
});
|
|
676
1044
|
Object.keys(transactions).forEach(function (k) {
|
|
677
1045
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
678
1046
|
enumerable: true,
|
|
679
1047
|
get: function () { return transactions[k]; }
|
|
680
1048
|
});
|
|
681
1049
|
});
|
|
1050
|
+
//# sourceMappingURL=out.js.map
|
|
1051
|
+
//# sourceMappingURL=index.node.cjs.map
|