@solana/web3.js 2.0.0-experimental.59e5893 → 2.0.0-experimental.5a6335d
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 +2 -0
- package/dist/index.browser.cjs +142 -21
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +108 -21
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +3764 -2244
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +108 -21
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +142 -21
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +108 -21
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +273 -82
- package/dist/types/airdrop-confirmer.d.ts +1 -1
- package/dist/types/airdrop-confirmer.d.ts.map +1 -1
- package/dist/types/airdrop.d.ts +1 -1
- package/dist/types/airdrop.d.ts.map +1 -1
- 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 +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rpc-request-coalescer.d.ts +1 -1
- package/dist/types/rpc-request-coalescer.d.ts.map +1 -1
- package/dist/types/rpc-subscription-coalescer.d.ts +1 -1
- package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -1
- package/dist/types/rpc-transport.d.ts +8 -2
- package/dist/types/rpc-transport.d.ts.map +1 -1
- package/dist/types/rpc.d.ts +9 -3
- package/dist/types/rpc.d.ts.map +1 -1
- package/dist/types/send-transaction.d.ts +1 -2
- package/dist/types/send-transaction.d.ts.map +1 -1
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +9 -4
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -1
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +1 -2
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -1
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +1 -2
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -1
- package/dist/types/transaction-confirmation.d.ts +3 -3
- package/dist/types/transaction-confirmation.d.ts.map +1 -1
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -784,6 +784,8 @@ Solana’s codecs libraries are broken up into modular components so you only ne
|
|
|
784
784
|
- `@solana/codecs-data-structures`: Codecs and serializers for structs
|
|
785
785
|
- `@solana/options`: Designed to build codecs and serializers for types that mimic Rust’s enums, which can include embedded data within their variants such as values, tuples, and structs
|
|
786
786
|
|
|
787
|
+
These packages are included in the main `@solana/web3.js` library but you may also import them from `@solana/codecs` if you only need the codecs.
|
|
788
|
+
|
|
787
789
|
Here’s an example of encoding and decoding a custom struct with some strings and numbers:
|
|
788
790
|
|
|
789
791
|
```tsx
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,15 +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');
|
|
6
11
|
var rpcTypes = require('@solana/rpc-types');
|
|
12
|
+
var signers = require('@solana/signers');
|
|
7
13
|
var transactions = require('@solana/transactions');
|
|
8
|
-
var functional = require('@solana/functional');
|
|
9
14
|
var rpcCore = require('@solana/rpc-core');
|
|
10
15
|
var rpcTransport = require('@solana/rpc-transport');
|
|
11
16
|
var fastStableStringify = require('fast-stable-stringify');
|
|
12
|
-
var codecsStrings = require('@solana/codecs-strings');
|
|
13
17
|
|
|
14
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
19
|
|
|
@@ -172,6 +176,36 @@ async function requestAndConfirmAirdrop({
|
|
|
172
176
|
});
|
|
173
177
|
return airdropTransactionSignature;
|
|
174
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
|
+
}
|
|
175
209
|
|
|
176
210
|
// src/rpc-integer-overflow-error.ts
|
|
177
211
|
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
@@ -406,9 +440,10 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
|
406
440
|
|
|
407
441
|
// src/rpc.ts
|
|
408
442
|
function createSolanaRpc(config) {
|
|
443
|
+
const api = rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG);
|
|
409
444
|
return rpcTransport.createJsonRpc({
|
|
410
445
|
...config,
|
|
411
|
-
api
|
|
446
|
+
api
|
|
412
447
|
});
|
|
413
448
|
}
|
|
414
449
|
function createSolanaRpcSubscriptions(config) {
|
|
@@ -447,13 +482,23 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
|
447
482
|
}
|
|
448
483
|
if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
|
|
449
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
|
+
})();
|
|
450
498
|
coalescedRequestsByDeduplicationKey[deduplicationKey] = {
|
|
451
499
|
abortController,
|
|
452
500
|
numConsumers: 0,
|
|
453
|
-
responsePromise
|
|
454
|
-
...config,
|
|
455
|
-
signal: abortController.signal
|
|
456
|
-
})
|
|
501
|
+
responsePromise
|
|
457
502
|
};
|
|
458
503
|
}
|
|
459
504
|
const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
|
|
@@ -618,22 +663,52 @@ function createDefaultRpcSubscriptionsTransport(config) {
|
|
|
618
663
|
}
|
|
619
664
|
|
|
620
665
|
// src/transaction-confirmation-strategy-blockheight.ts
|
|
621
|
-
function createBlockHeightExceedencePromiseFactory(
|
|
622
|
-
|
|
666
|
+
function createBlockHeightExceedencePromiseFactory({
|
|
667
|
+
rpc,
|
|
668
|
+
rpcSubscriptions
|
|
669
|
+
}) {
|
|
670
|
+
return async function getBlockHeightExceedencePromise({
|
|
671
|
+
abortSignal: callerAbortSignal,
|
|
672
|
+
commitment,
|
|
673
|
+
lastValidBlockHeight
|
|
674
|
+
}) {
|
|
623
675
|
const abortController = new AbortController();
|
|
624
|
-
|
|
676
|
+
const handleAbort = () => {
|
|
625
677
|
abortController.abort();
|
|
626
|
-
}
|
|
678
|
+
};
|
|
627
679
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
628
|
-
|
|
680
|
+
async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
|
|
681
|
+
const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
|
|
682
|
+
return {
|
|
683
|
+
blockHeight,
|
|
684
|
+
differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
|
|
685
|
+
};
|
|
686
|
+
}
|
|
629
687
|
try {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
688
|
+
const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
|
|
689
|
+
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
|
|
690
|
+
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
|
|
691
|
+
]);
|
|
692
|
+
if (blockHeight <= lastValidBlockHeight) {
|
|
693
|
+
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
|
|
694
|
+
for await (const slotNotification of slotNotifications) {
|
|
695
|
+
const { slot } = slotNotification;
|
|
696
|
+
if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
|
|
697
|
+
const {
|
|
698
|
+
blockHeight: currentBlockHeight,
|
|
699
|
+
differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
|
|
700
|
+
} = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
|
|
701
|
+
if (currentBlockHeight > lastValidBlockHeight) {
|
|
702
|
+
break;
|
|
703
|
+
} else {
|
|
704
|
+
lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
635
707
|
}
|
|
636
708
|
}
|
|
709
|
+
throw new Error(
|
|
710
|
+
"The network has progressed past the last block for which this transaction could have been committed."
|
|
711
|
+
);
|
|
637
712
|
} finally {
|
|
638
713
|
abortController.abort();
|
|
639
714
|
}
|
|
@@ -655,8 +730,8 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
|
655
730
|
}
|
|
656
731
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
657
732
|
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
658
|
-
const base58Decoder =
|
|
659
|
-
const base64Encoder =
|
|
733
|
+
const base58Decoder = codecs.getBase58Decoder();
|
|
734
|
+
const base64Encoder = codecs.getBase64Encoder();
|
|
660
735
|
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
661
736
|
const data = base64Encoder.encode(base64EncodedBytes);
|
|
662
737
|
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
@@ -725,7 +800,10 @@ function createDefaultRecentTransactionConfirmer({
|
|
|
725
800
|
rpc,
|
|
726
801
|
rpcSubscriptions
|
|
727
802
|
}) {
|
|
728
|
-
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(
|
|
803
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
804
|
+
rpc,
|
|
805
|
+
rpcSubscriptions
|
|
806
|
+
});
|
|
729
807
|
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
730
808
|
rpc,
|
|
731
809
|
rpcSubscriptions
|
|
@@ -758,10 +836,16 @@ async function waitForRecentTransactionConfirmation(config) {
|
|
|
758
836
|
await raceStrategies(
|
|
759
837
|
transactions.getSignatureFromTransaction(config.transaction),
|
|
760
838
|
config,
|
|
761
|
-
function getSpecificStrategiesForRace({
|
|
839
|
+
function getSpecificStrategiesForRace({
|
|
840
|
+
abortSignal,
|
|
841
|
+
commitment,
|
|
842
|
+
getBlockHeightExceedencePromise,
|
|
843
|
+
transaction
|
|
844
|
+
}) {
|
|
762
845
|
return [
|
|
763
846
|
getBlockHeightExceedencePromise({
|
|
764
847
|
abortSignal,
|
|
848
|
+
commitment,
|
|
765
849
|
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
766
850
|
})
|
|
767
851
|
];
|
|
@@ -896,17 +980,36 @@ exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureC
|
|
|
896
980
|
exports.createSolanaRpc = createSolanaRpc;
|
|
897
981
|
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
898
982
|
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
983
|
+
exports.decodeTransaction = decodeTransaction;
|
|
899
984
|
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
900
985
|
exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
|
|
901
986
|
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
902
987
|
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
903
988
|
exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
|
|
989
|
+
Object.keys(accounts).forEach(function (k) {
|
|
990
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
991
|
+
enumerable: true,
|
|
992
|
+
get: function () { return accounts[k]; }
|
|
993
|
+
});
|
|
994
|
+
});
|
|
904
995
|
Object.keys(addresses).forEach(function (k) {
|
|
905
996
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
906
997
|
enumerable: true,
|
|
907
998
|
get: function () { return addresses[k]; }
|
|
908
999
|
});
|
|
909
1000
|
});
|
|
1001
|
+
Object.keys(codecs).forEach(function (k) {
|
|
1002
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1003
|
+
enumerable: true,
|
|
1004
|
+
get: function () { return codecs[k]; }
|
|
1005
|
+
});
|
|
1006
|
+
});
|
|
1007
|
+
Object.keys(functional).forEach(function (k) {
|
|
1008
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1009
|
+
enumerable: true,
|
|
1010
|
+
get: function () { return functional[k]; }
|
|
1011
|
+
});
|
|
1012
|
+
});
|
|
910
1013
|
Object.keys(instructions).forEach(function (k) {
|
|
911
1014
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
912
1015
|
enumerable: true,
|
|
@@ -919,12 +1022,30 @@ Object.keys(keys).forEach(function (k) {
|
|
|
919
1022
|
get: function () { return keys[k]; }
|
|
920
1023
|
});
|
|
921
1024
|
});
|
|
1025
|
+
Object.keys(programs).forEach(function (k) {
|
|
1026
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1027
|
+
enumerable: true,
|
|
1028
|
+
get: function () { return programs[k]; }
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
1031
|
+
Object.keys(rpcParsedTypes).forEach(function (k) {
|
|
1032
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1033
|
+
enumerable: true,
|
|
1034
|
+
get: function () { return rpcParsedTypes[k]; }
|
|
1035
|
+
});
|
|
1036
|
+
});
|
|
922
1037
|
Object.keys(rpcTypes).forEach(function (k) {
|
|
923
1038
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
924
1039
|
enumerable: true,
|
|
925
1040
|
get: function () { return rpcTypes[k]; }
|
|
926
1041
|
});
|
|
927
1042
|
});
|
|
1043
|
+
Object.keys(signers).forEach(function (k) {
|
|
1044
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1045
|
+
enumerable: true,
|
|
1046
|
+
get: function () { return signers[k]; }
|
|
1047
|
+
});
|
|
1048
|
+
});
|
|
928
1049
|
Object.keys(transactions).forEach(function (k) {
|
|
929
1050
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
930
1051
|
enumerable: true,
|