@solana/web3.js 2.0.0-experimental.e0b865d → 2.0.0-experimental.e1b2277
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1151 -43
- package/dist/index.browser.cjs +464 -14
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +448 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2274 -1006
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +448 -15
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +464 -14
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +448 -15
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +82 -36
- 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/index.d.ts +10 -3
- 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 +1 -1
- 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 +1 -2
- package/dist/types/rpc-transport.d.ts.map +1 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +1 -1
- package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +1 -1
- package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
- package/dist/types/rpc-websocket-transport.d.ts +1 -2
- package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
- package/dist/types/rpc.d.ts +1 -2
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/send-transaction.d.ts +38 -0
- package/dist/types/send-transaction.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +9 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +14 -0
- 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 +12 -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 +32 -0
- package/dist/types/transaction-confirmation.d.ts.map +1 -0
- package/package.json +22 -20
package/dist/index.browser.js
CHANGED
|
@@ -1,34 +1,200 @@
|
|
|
1
1
|
export * from '@solana/addresses';
|
|
2
2
|
export * from '@solana/instructions';
|
|
3
3
|
export * from '@solana/keys';
|
|
4
|
+
import { commitmentComparator } from '@solana/rpc-types';
|
|
5
|
+
export * from '@solana/rpc-types';
|
|
6
|
+
import { getSignatureFromTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';
|
|
4
7
|
export * from '@solana/transactions';
|
|
5
8
|
import { pipe } from '@solana/functional';
|
|
6
9
|
import { createSolanaRpcApi, createSolanaRpcSubscriptionsApi, createSolanaRpcSubscriptionsApi_UNSTABLE } from '@solana/rpc-core';
|
|
7
10
|
import { createJsonRpc, createJsonSubscriptionRpc, createHttpTransport, createWebSocketTransport } from '@solana/rpc-transport';
|
|
8
11
|
import fastStableStringify from 'fast-stable-stringify';
|
|
12
|
+
import { getBase58Decoder, getBase64Encoder } from '@solana/codecs-strings';
|
|
9
13
|
|
|
10
14
|
// ../build-scripts/env-shim.ts
|
|
11
15
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
12
16
|
|
|
17
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
18
|
+
async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
|
|
19
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
20
|
+
callerAbortSignal?.throwIfAborted();
|
|
21
|
+
const abortController = new AbortController();
|
|
22
|
+
if (callerAbortSignal) {
|
|
23
|
+
const handleAbort = () => {
|
|
24
|
+
abortController.abort();
|
|
25
|
+
};
|
|
26
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
30
|
+
...config,
|
|
31
|
+
abortSignal: abortController.signal
|
|
32
|
+
});
|
|
33
|
+
return await Promise.race([
|
|
34
|
+
getRecentSignatureConfirmationPromise({
|
|
35
|
+
abortSignal: abortController.signal,
|
|
36
|
+
commitment,
|
|
37
|
+
signature
|
|
38
|
+
}),
|
|
39
|
+
...specificStrategies
|
|
40
|
+
]);
|
|
41
|
+
} finally {
|
|
42
|
+
abortController.abort();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
46
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
47
|
+
abortSignal: callerAbortSignal,
|
|
48
|
+
commitment,
|
|
49
|
+
signature
|
|
50
|
+
}) {
|
|
51
|
+
const abortController = new AbortController();
|
|
52
|
+
function handleAbort() {
|
|
53
|
+
abortController.abort();
|
|
54
|
+
}
|
|
55
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
56
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
57
|
+
const signatureDidCommitPromise = (async () => {
|
|
58
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
59
|
+
if (signatureStatusNotification.value.err) {
|
|
60
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
61
|
+
cause: signatureStatusNotification.value.err
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
const signatureStatusLookupPromise = (async () => {
|
|
69
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
70
|
+
const signatureStatus = signatureStatusResults[0];
|
|
71
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
72
|
+
return;
|
|
73
|
+
} else {
|
|
74
|
+
await new Promise(() => {
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
try {
|
|
79
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
80
|
+
} finally {
|
|
81
|
+
abortController.abort();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
87
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
88
|
+
return await new Promise((_, reject) => {
|
|
89
|
+
const handleAbort = (e) => {
|
|
90
|
+
clearTimeout(timeoutId);
|
|
91
|
+
const abortError = new DOMException(e.target.reason, "AbortError");
|
|
92
|
+
reject(abortError);
|
|
93
|
+
};
|
|
94
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
95
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
96
|
+
const startMs = performance.now();
|
|
97
|
+
const timeoutId = (
|
|
98
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
99
|
+
// elapsed time instead of active time.
|
|
100
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
const elapsedMs = performance.now() - startMs;
|
|
103
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
104
|
+
}, timeoutMs)
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/airdrop-confirmer.ts
|
|
110
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
111
|
+
rpc,
|
|
112
|
+
rpcSubscriptions
|
|
113
|
+
}) {
|
|
114
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
115
|
+
rpc,
|
|
116
|
+
rpcSubscriptions
|
|
117
|
+
);
|
|
118
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
119
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
120
|
+
...config,
|
|
121
|
+
getRecentSignatureConfirmationPromise,
|
|
122
|
+
getTimeoutPromise
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
127
|
+
await raceStrategies(
|
|
128
|
+
config.signature,
|
|
129
|
+
config,
|
|
130
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
131
|
+
return [
|
|
132
|
+
getTimeoutPromise2({
|
|
133
|
+
abortSignal,
|
|
134
|
+
commitment
|
|
135
|
+
})
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/airdrop.ts
|
|
142
|
+
function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
|
|
143
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
144
|
+
rpc,
|
|
145
|
+
rpcSubscriptions
|
|
146
|
+
});
|
|
147
|
+
return async function requestAirdrop(config) {
|
|
148
|
+
return await requestAndConfirmAirdrop({
|
|
149
|
+
...config,
|
|
150
|
+
confirmSignatureOnlyTransaction,
|
|
151
|
+
rpc
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async function requestAndConfirmAirdrop({
|
|
156
|
+
abortSignal,
|
|
157
|
+
commitment,
|
|
158
|
+
confirmSignatureOnlyTransaction,
|
|
159
|
+
lamports,
|
|
160
|
+
recipientAddress,
|
|
161
|
+
rpc
|
|
162
|
+
}) {
|
|
163
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
164
|
+
await confirmSignatureOnlyTransaction({
|
|
165
|
+
abortSignal,
|
|
166
|
+
commitment,
|
|
167
|
+
signature: airdropTransactionSignature
|
|
168
|
+
});
|
|
169
|
+
return airdropTransactionSignature;
|
|
170
|
+
}
|
|
171
|
+
|
|
13
172
|
// src/rpc-integer-overflow-error.ts
|
|
14
173
|
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
174
|
+
methodName;
|
|
175
|
+
keyPath;
|
|
176
|
+
value;
|
|
15
177
|
constructor(methodName, keyPath, value) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
178
|
+
let argumentLabel = "";
|
|
179
|
+
if (typeof keyPath[0] === "number") {
|
|
180
|
+
const argPosition = keyPath[0] + 1;
|
|
181
|
+
const lastDigit = argPosition % 10;
|
|
182
|
+
const lastTwoDigits = argPosition % 100;
|
|
183
|
+
if (lastDigit == 1 && lastTwoDigits != 11) {
|
|
184
|
+
argumentLabel = argPosition + "st";
|
|
185
|
+
} else if (lastDigit == 2 && lastTwoDigits != 12) {
|
|
186
|
+
argumentLabel = argPosition + "nd";
|
|
187
|
+
} else if (lastDigit == 3 && lastTwoDigits != 13) {
|
|
188
|
+
argumentLabel = argPosition + "rd";
|
|
189
|
+
} else {
|
|
190
|
+
argumentLabel = argPosition + "th";
|
|
191
|
+
}
|
|
26
192
|
} else {
|
|
27
|
-
|
|
193
|
+
argumentLabel = `\`${keyPath[0].toString()}\``;
|
|
28
194
|
}
|
|
29
195
|
const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
|
|
30
196
|
super(
|
|
31
|
-
`The ${
|
|
197
|
+
`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\`.`
|
|
32
198
|
);
|
|
33
199
|
this.keyPath = keyPath;
|
|
34
200
|
this.methodName = methodName;
|
|
@@ -41,6 +207,7 @@ var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
|
41
207
|
|
|
42
208
|
// src/rpc-default-config.ts
|
|
43
209
|
var DEFAULT_RPC_CONFIG = {
|
|
210
|
+
defaultCommitment: "confirmed",
|
|
44
211
|
onIntegerOverflow(methodName, keyPath, value) {
|
|
45
212
|
throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
|
|
46
213
|
}
|
|
@@ -200,11 +367,11 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
|
200
367
|
return {
|
|
201
368
|
...iterable,
|
|
202
369
|
async *[Symbol.asyncIterator]() {
|
|
203
|
-
abortPromise
|
|
370
|
+
abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
|
|
204
371
|
abortSignal.addEventListener("abort", () => {
|
|
205
372
|
reject(EXPLICIT_ABORT_TOKEN);
|
|
206
373
|
});
|
|
207
|
-
})
|
|
374
|
+
});
|
|
208
375
|
try {
|
|
209
376
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
210
377
|
while (true) {
|
|
@@ -446,6 +613,272 @@ function createDefaultRpcSubscriptionsTransport(config) {
|
|
|
446
613
|
);
|
|
447
614
|
}
|
|
448
615
|
|
|
449
|
-
|
|
616
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
617
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
618
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
619
|
+
const abortController = new AbortController();
|
|
620
|
+
function handleAbort() {
|
|
621
|
+
abortController.abort();
|
|
622
|
+
}
|
|
623
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
624
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
625
|
+
try {
|
|
626
|
+
for await (const slotNotification of slotNotifications) {
|
|
627
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
628
|
+
throw new Error(
|
|
629
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
} finally {
|
|
634
|
+
abortController.abort();
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
639
|
+
4 + // state(u32)
|
|
640
|
+
32;
|
|
641
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
642
|
+
return async function getNonceInvalidationPromise({
|
|
643
|
+
abortSignal: callerAbortSignal,
|
|
644
|
+
commitment,
|
|
645
|
+
currentNonceValue,
|
|
646
|
+
nonceAccountAddress
|
|
647
|
+
}) {
|
|
648
|
+
const abortController = new AbortController();
|
|
649
|
+
function handleAbort() {
|
|
650
|
+
abortController.abort();
|
|
651
|
+
}
|
|
652
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
653
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
654
|
+
const base58Decoder = getBase58Decoder();
|
|
655
|
+
const base64Encoder = getBase64Encoder();
|
|
656
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
657
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
658
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
659
|
+
return base58Decoder.decode(nonceValueBytes);
|
|
660
|
+
}
|
|
661
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
662
|
+
for await (const accountNotification of accountNotifications) {
|
|
663
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
664
|
+
if (nonceValue !== currentNonceValue) {
|
|
665
|
+
throw new Error(
|
|
666
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
})();
|
|
671
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
672
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
673
|
+
commitment,
|
|
674
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
675
|
+
encoding: "base58"
|
|
676
|
+
}).send({ abortSignal: abortController.signal });
|
|
677
|
+
if (!nonceAccount) {
|
|
678
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
679
|
+
}
|
|
680
|
+
const nonceValue = (
|
|
681
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
682
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
683
|
+
nonceAccount.data[0]
|
|
684
|
+
);
|
|
685
|
+
if (nonceValue !== currentNonceValue) {
|
|
686
|
+
throw new Error(
|
|
687
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
688
|
+
);
|
|
689
|
+
} else {
|
|
690
|
+
await new Promise(() => {
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
})();
|
|
694
|
+
try {
|
|
695
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
696
|
+
} finally {
|
|
697
|
+
abortController.abort();
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// src/transaction-confirmation.ts
|
|
703
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
704
|
+
rpc,
|
|
705
|
+
rpcSubscriptions
|
|
706
|
+
}) {
|
|
707
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
708
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
709
|
+
rpc,
|
|
710
|
+
rpcSubscriptions
|
|
711
|
+
);
|
|
712
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
713
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
714
|
+
...config,
|
|
715
|
+
getNonceInvalidationPromise,
|
|
716
|
+
getRecentSignatureConfirmationPromise
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
function createDefaultRecentTransactionConfirmer({
|
|
721
|
+
rpc,
|
|
722
|
+
rpcSubscriptions
|
|
723
|
+
}) {
|
|
724
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
725
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
726
|
+
rpc,
|
|
727
|
+
rpcSubscriptions
|
|
728
|
+
);
|
|
729
|
+
return async function confirmRecentTransaction(config) {
|
|
730
|
+
await waitForRecentTransactionConfirmation({
|
|
731
|
+
...config,
|
|
732
|
+
getBlockHeightExceedencePromise,
|
|
733
|
+
getRecentSignatureConfirmationPromise
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
738
|
+
await raceStrategies(
|
|
739
|
+
getSignatureFromTransaction(config.transaction),
|
|
740
|
+
config,
|
|
741
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
742
|
+
return [
|
|
743
|
+
getNonceInvalidationPromise({
|
|
744
|
+
abortSignal,
|
|
745
|
+
commitment,
|
|
746
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
747
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
748
|
+
})
|
|
749
|
+
];
|
|
750
|
+
}
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
754
|
+
await raceStrategies(
|
|
755
|
+
getSignatureFromTransaction(config.transaction),
|
|
756
|
+
config,
|
|
757
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
758
|
+
return [
|
|
759
|
+
getBlockHeightExceedencePromise({
|
|
760
|
+
abortSignal,
|
|
761
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
762
|
+
})
|
|
763
|
+
];
|
|
764
|
+
}
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/send-transaction.ts
|
|
769
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
770
|
+
if (
|
|
771
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
772
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
773
|
+
commitmentComparator(
|
|
774
|
+
commitment,
|
|
775
|
+
"finalized"
|
|
776
|
+
/* default value of `preflightCommitment` */
|
|
777
|
+
) < 0
|
|
778
|
+
) {
|
|
779
|
+
return {
|
|
780
|
+
...config,
|
|
781
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
782
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
783
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
784
|
+
// confirmation commitment.
|
|
785
|
+
preflightCommitment: commitment
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
return config;
|
|
789
|
+
}
|
|
790
|
+
async function sendTransaction_INTERNAL({
|
|
791
|
+
abortSignal,
|
|
792
|
+
commitment,
|
|
793
|
+
rpc,
|
|
794
|
+
transaction,
|
|
795
|
+
...sendTransactionConfig
|
|
796
|
+
}) {
|
|
797
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
798
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
799
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
800
|
+
encoding: "base64"
|
|
801
|
+
}).send({ abortSignal });
|
|
802
|
+
}
|
|
803
|
+
function createDefaultDurableNonceTransactionSender({
|
|
804
|
+
rpc,
|
|
805
|
+
rpcSubscriptions
|
|
806
|
+
}) {
|
|
807
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
808
|
+
rpc,
|
|
809
|
+
rpcSubscriptions
|
|
810
|
+
});
|
|
811
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
812
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
813
|
+
...config,
|
|
814
|
+
confirmDurableNonceTransaction,
|
|
815
|
+
rpc,
|
|
816
|
+
transaction
|
|
817
|
+
});
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function createDefaultTransactionSender({
|
|
821
|
+
rpc,
|
|
822
|
+
rpcSubscriptions
|
|
823
|
+
}) {
|
|
824
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
825
|
+
rpc,
|
|
826
|
+
rpcSubscriptions
|
|
827
|
+
});
|
|
828
|
+
return async function sendTransaction(transaction, config) {
|
|
829
|
+
await sendAndConfirmTransaction({
|
|
830
|
+
...config,
|
|
831
|
+
confirmRecentTransaction,
|
|
832
|
+
rpc,
|
|
833
|
+
transaction
|
|
834
|
+
});
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
838
|
+
abortSignal,
|
|
839
|
+
commitment,
|
|
840
|
+
confirmDurableNonceTransaction,
|
|
841
|
+
rpc,
|
|
842
|
+
transaction,
|
|
843
|
+
...sendTransactionConfig
|
|
844
|
+
}) {
|
|
845
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
846
|
+
...sendTransactionConfig,
|
|
847
|
+
abortSignal,
|
|
848
|
+
commitment,
|
|
849
|
+
rpc,
|
|
850
|
+
transaction
|
|
851
|
+
});
|
|
852
|
+
await confirmDurableNonceTransaction({
|
|
853
|
+
abortSignal,
|
|
854
|
+
commitment,
|
|
855
|
+
transaction
|
|
856
|
+
});
|
|
857
|
+
return transactionSignature;
|
|
858
|
+
}
|
|
859
|
+
async function sendAndConfirmTransaction({
|
|
860
|
+
abortSignal,
|
|
861
|
+
commitment,
|
|
862
|
+
confirmRecentTransaction,
|
|
863
|
+
rpc,
|
|
864
|
+
transaction,
|
|
865
|
+
...sendTransactionConfig
|
|
866
|
+
}) {
|
|
867
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
868
|
+
...sendTransactionConfig,
|
|
869
|
+
abortSignal,
|
|
870
|
+
commitment,
|
|
871
|
+
rpc,
|
|
872
|
+
transaction
|
|
873
|
+
});
|
|
874
|
+
await confirmRecentTransaction({
|
|
875
|
+
abortSignal,
|
|
876
|
+
commitment,
|
|
877
|
+
transaction
|
|
878
|
+
});
|
|
879
|
+
return transactionSignature;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
export { createBlockHeightExceedencePromiseFactory, createDefaultAirdropRequester, createDefaultDurableNonceTransactionConfirmer, createDefaultDurableNonceTransactionSender, createDefaultRecentTransactionConfirmer, createDefaultRpcSubscriptionsTransport, createDefaultRpcTransport, createDefaultTransactionSender, createNonceInvalidationPromiseFactory, createRecentSignatureConfirmationPromiseFactory, createSolanaRpc, createSolanaRpcSubscriptions, createSolanaRpcSubscriptions_UNSTABLE, requestAndConfirmAirdrop, sendAndConfirmDurableNonceTransaction, sendAndConfirmTransaction, waitForDurableNonceTransactionConfirmation, waitForRecentTransactionConfirmation };
|
|
450
883
|
//# sourceMappingURL=out.js.map
|
|
451
884
|
//# sourceMappingURL=index.browser.js.map
|