@solana/web3.js 2.0.0-experimental.5e737f9 → 2.0.0-experimental.62b6bd6
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/dist/index.browser.cjs +65 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +54 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +332 -171
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +54 -13
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +65 -13
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +54 -13
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +94 -78
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.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.d.ts +2 -2
- package/dist/types/transaction-confirmation.d.ts.map +1 -1
- package/package.json +11 -10
|
@@ -122,7 +122,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
122
122
|
// src/index.ts
|
|
123
123
|
init_env_shim();
|
|
124
124
|
|
|
125
|
-
// ../
|
|
125
|
+
// ../accounts/dist/index.browser.js
|
|
126
|
+
init_env_shim();
|
|
127
|
+
|
|
128
|
+
// ../codecs-strings/dist/index.browser.js
|
|
126
129
|
init_env_shim();
|
|
127
130
|
|
|
128
131
|
// ../codecs-core/dist/index.browser.js
|
|
@@ -168,11 +171,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
168
171
|
function isFixedSize(codec) {
|
|
169
172
|
return "fixedSize" in codec && typeof codec.fixedSize === "number";
|
|
170
173
|
}
|
|
171
|
-
function assertIsFixedSize(codec, message) {
|
|
172
|
-
if (!isFixedSize(codec)) {
|
|
173
|
-
throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
174
|
function isVariableSize(codec) {
|
|
177
175
|
return !isFixedSize(codec);
|
|
178
176
|
}
|
|
@@ -242,9 +240,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
242
240
|
});
|
|
243
241
|
}
|
|
244
242
|
|
|
245
|
-
// ../codecs-strings/dist/index.browser.js
|
|
246
|
-
init_env_shim();
|
|
247
|
-
|
|
248
243
|
// ../codecs-numbers/dist/index.browser.js
|
|
249
244
|
init_env_shim();
|
|
250
245
|
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
@@ -535,6 +530,98 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
535
530
|
});
|
|
536
531
|
}
|
|
537
532
|
|
|
533
|
+
// ../accounts/dist/index.browser.js
|
|
534
|
+
var BASE_ACCOUNT_SIZE = 128;
|
|
535
|
+
function decodeAccount(encodedAccount, decoder) {
|
|
536
|
+
try {
|
|
537
|
+
if ("exists" in encodedAccount && !encodedAccount.exists) {
|
|
538
|
+
return encodedAccount;
|
|
539
|
+
}
|
|
540
|
+
return Object.freeze({ ...encodedAccount, data: decoder.decode(encodedAccount.data) });
|
|
541
|
+
} catch (error) {
|
|
542
|
+
const newError = new Error(`Failed to decode account [${encodedAccount.address}].`);
|
|
543
|
+
newError.cause = error;
|
|
544
|
+
throw newError;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function accountExists(account) {
|
|
548
|
+
return !("exists" in account) || "exists" in account && account.exists;
|
|
549
|
+
}
|
|
550
|
+
function assertAccountDecoded(account) {
|
|
551
|
+
if (accountExists(account) && account.data instanceof Uint8Array) {
|
|
552
|
+
throw new Error(`Expected account [${account.address}] to be decoded.`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function assertAccountsDecoded(accounts) {
|
|
556
|
+
const encoded = accounts.filter((a) => accountExists(a) && a.data instanceof Uint8Array);
|
|
557
|
+
if (encoded.length > 0) {
|
|
558
|
+
const encodedAddresses = encoded.map((a) => a.address).join(", ");
|
|
559
|
+
throw new Error(`Expected accounts [${encodedAddresses}] to be decoded.`);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function parseBase64RpcAccount(address2, rpcAccount) {
|
|
563
|
+
if (!rpcAccount)
|
|
564
|
+
return Object.freeze({ address: address2, exists: false });
|
|
565
|
+
const data = getBase64Encoder().encode(rpcAccount.data[0]);
|
|
566
|
+
return Object.freeze({ ...parseBaseAccount(rpcAccount), address: address2, data, exists: true });
|
|
567
|
+
}
|
|
568
|
+
function parseBase58RpcAccount(address2, rpcAccount) {
|
|
569
|
+
if (!rpcAccount)
|
|
570
|
+
return Object.freeze({ address: address2, exists: false });
|
|
571
|
+
const data = getBase58Encoder().encode(typeof rpcAccount.data === "string" ? rpcAccount.data : rpcAccount.data[0]);
|
|
572
|
+
return Object.freeze({ ...parseBaseAccount(rpcAccount), address: address2, data, exists: true });
|
|
573
|
+
}
|
|
574
|
+
function parseJsonRpcAccount(address2, rpcAccount) {
|
|
575
|
+
if (!rpcAccount)
|
|
576
|
+
return Object.freeze({ address: address2, exists: false });
|
|
577
|
+
const data = rpcAccount.data.parsed.info;
|
|
578
|
+
return Object.freeze({ ...parseBaseAccount(rpcAccount), address: address2, data, exists: true });
|
|
579
|
+
}
|
|
580
|
+
function parseBaseAccount(rpcAccount) {
|
|
581
|
+
return Object.freeze({
|
|
582
|
+
executable: rpcAccount.executable,
|
|
583
|
+
lamports: rpcAccount.lamports,
|
|
584
|
+
programAddress: rpcAccount.owner
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
async function fetchEncodedAccount(rpc, address2, config = {}) {
|
|
588
|
+
const { abortSignal, ...rpcConfig } = config;
|
|
589
|
+
const response = await rpc.getAccountInfo(address2, { ...rpcConfig, encoding: "base64" }).send({ abortSignal });
|
|
590
|
+
return parseBase64RpcAccount(address2, response.value);
|
|
591
|
+
}
|
|
592
|
+
async function fetchJsonParsedAccount(rpc, address2, config = {}) {
|
|
593
|
+
const { abortSignal, ...rpcConfig } = config;
|
|
594
|
+
const { value: account } = await rpc.getAccountInfo(address2, { ...rpcConfig, encoding: "jsonParsed" }).send({ abortSignal });
|
|
595
|
+
return !!account && typeof account === "object" && "parsed" in account.data ? parseJsonRpcAccount(address2, account) : parseBase64RpcAccount(address2, account);
|
|
596
|
+
}
|
|
597
|
+
async function fetchEncodedAccounts(rpc, addresses, config = {}) {
|
|
598
|
+
const { abortSignal, ...rpcConfig } = config;
|
|
599
|
+
const response = await rpc.getMultipleAccounts(addresses, { ...rpcConfig, encoding: "base64" }).send({ abortSignal });
|
|
600
|
+
return response.value.map((account, index) => parseBase64RpcAccount(addresses[index], account));
|
|
601
|
+
}
|
|
602
|
+
async function fetchJsonParsedAccounts(rpc, addresses, config = {}) {
|
|
603
|
+
const { abortSignal, ...rpcConfig } = config;
|
|
604
|
+
const response = await rpc.getMultipleAccounts(addresses, { ...rpcConfig, encoding: "jsonParsed" }).send({ abortSignal });
|
|
605
|
+
return response.value.map((account, index) => {
|
|
606
|
+
return !!account && typeof account === "object" && "parsed" in account.data ? parseJsonRpcAccount(addresses[index], account) : parseBase64RpcAccount(addresses[index], account);
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
function assertAccountExists(account) {
|
|
610
|
+
if (!account.exists) {
|
|
611
|
+
throw new Error(`Expected account [${account.address}] to exist.`);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function assertAccountsExist(accounts) {
|
|
615
|
+
const missingAccounts = accounts.filter((a) => !a.exists);
|
|
616
|
+
if (missingAccounts.length > 0) {
|
|
617
|
+
const missingAddresses = missingAccounts.map((a) => a.address);
|
|
618
|
+
throw new Error(`Expected accounts [${missingAddresses.join(", ")}] to exist.`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// ../addresses/dist/index.browser.js
|
|
623
|
+
init_env_shim();
|
|
624
|
+
|
|
538
625
|
// ../assertions/dist/index.browser.js
|
|
539
626
|
init_env_shim();
|
|
540
627
|
function assertIsSecureContext() {
|
|
@@ -886,6 +973,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
886
973
|
return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
887
974
|
}
|
|
888
975
|
|
|
976
|
+
// ../functional/dist/index.browser.js
|
|
977
|
+
init_env_shim();
|
|
978
|
+
function pipe(init, ...fns) {
|
|
979
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
980
|
+
}
|
|
981
|
+
|
|
889
982
|
// ../instructions/dist/index.browser.js
|
|
890
983
|
init_env_shim();
|
|
891
984
|
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
@@ -1162,9 +1255,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1162
1255
|
function getArrayEncoder(item, config = {}) {
|
|
1163
1256
|
var _a, _b;
|
|
1164
1257
|
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
1165
|
-
if (size === "remainder") {
|
|
1166
|
-
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1167
|
-
}
|
|
1168
1258
|
const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
|
|
1169
1259
|
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
1170
1260
|
return createEncoder({
|
|
@@ -1192,9 +1282,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1192
1282
|
function getArrayDecoder(item, config = {}) {
|
|
1193
1283
|
var _a, _b;
|
|
1194
1284
|
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1195
|
-
if (size === "remainder") {
|
|
1196
|
-
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1197
|
-
}
|
|
1198
1285
|
const itemSize = getFixedSize(item);
|
|
1199
1286
|
const fixedSize = computeArrayLikeCodecSize(size, itemSize);
|
|
1200
1287
|
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
@@ -1205,7 +1292,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1205
1292
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1206
1293
|
return [array, offset];
|
|
1207
1294
|
}
|
|
1208
|
-
|
|
1295
|
+
if (size === "remainder") {
|
|
1296
|
+
while (offset < bytes.length) {
|
|
1297
|
+
const [value, newOffset2] = item.read(bytes, offset);
|
|
1298
|
+
offset = newOffset2;
|
|
1299
|
+
array.push(value);
|
|
1300
|
+
}
|
|
1301
|
+
return [array, offset];
|
|
1302
|
+
}
|
|
1303
|
+
const [resolvedSize, newOffset] = typeof size === "number" ? [size, offset] : size.read(bytes, offset);
|
|
1209
1304
|
offset = newOffset;
|
|
1210
1305
|
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1211
1306
|
const [value, newOffset2] = item.read(bytes, offset);
|
|
@@ -1216,27 +1311,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1216
1311
|
}
|
|
1217
1312
|
});
|
|
1218
1313
|
}
|
|
1219
|
-
function readArrayLikeCodecSize(size, itemSize, bytes, offset) {
|
|
1220
|
-
if (typeof size === "number") {
|
|
1221
|
-
return [size, offset];
|
|
1222
|
-
}
|
|
1223
|
-
if (typeof size === "object") {
|
|
1224
|
-
return size.read(bytes, offset);
|
|
1225
|
-
}
|
|
1226
|
-
if (size === "remainder") {
|
|
1227
|
-
if (itemSize === null) {
|
|
1228
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1229
|
-
}
|
|
1230
|
-
const remainder = Math.max(0, bytes.length - offset);
|
|
1231
|
-
if (remainder % itemSize !== 0) {
|
|
1232
|
-
throw new Error(
|
|
1233
|
-
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${itemSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${itemSize} should be equal to zero.`
|
|
1234
|
-
);
|
|
1235
|
-
}
|
|
1236
|
-
return [remainder / itemSize, offset];
|
|
1237
|
-
}
|
|
1238
|
-
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1239
|
-
}
|
|
1240
1314
|
function computeArrayLikeCodecSize(size, itemSize) {
|
|
1241
1315
|
if (typeof size !== "number")
|
|
1242
1316
|
return null;
|
|
@@ -1334,12 +1408,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1334
1408
|
});
|
|
1335
1409
|
}
|
|
1336
1410
|
|
|
1337
|
-
// ../functional/dist/index.browser.js
|
|
1338
|
-
init_env_shim();
|
|
1339
|
-
function pipe(init, ...fns) {
|
|
1340
|
-
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
1411
|
// ../transactions/dist/index.browser.js
|
|
1344
1412
|
function getUnsignedTransaction(transaction) {
|
|
1345
1413
|
if ("signatures" in transaction) {
|
|
@@ -1536,6 +1604,151 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1536
1604
|
Object.freeze(out);
|
|
1537
1605
|
return out;
|
|
1538
1606
|
}
|
|
1607
|
+
function getAccountMetas(message) {
|
|
1608
|
+
const { header } = message;
|
|
1609
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
1610
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
1611
|
+
const accountMetas = [];
|
|
1612
|
+
let accountIndex = 0;
|
|
1613
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
1614
|
+
accountMetas.push({
|
|
1615
|
+
address: message.staticAccounts[accountIndex],
|
|
1616
|
+
role: AccountRole2.WRITABLE_SIGNER
|
|
1617
|
+
});
|
|
1618
|
+
accountIndex++;
|
|
1619
|
+
}
|
|
1620
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1621
|
+
accountMetas.push({
|
|
1622
|
+
address: message.staticAccounts[accountIndex],
|
|
1623
|
+
role: AccountRole2.READONLY_SIGNER
|
|
1624
|
+
});
|
|
1625
|
+
accountIndex++;
|
|
1626
|
+
}
|
|
1627
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1628
|
+
accountMetas.push({
|
|
1629
|
+
address: message.staticAccounts[accountIndex],
|
|
1630
|
+
role: AccountRole2.WRITABLE
|
|
1631
|
+
});
|
|
1632
|
+
accountIndex++;
|
|
1633
|
+
}
|
|
1634
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
1635
|
+
accountMetas.push({
|
|
1636
|
+
address: message.staticAccounts[accountIndex],
|
|
1637
|
+
role: AccountRole2.READONLY
|
|
1638
|
+
});
|
|
1639
|
+
accountIndex++;
|
|
1640
|
+
}
|
|
1641
|
+
return accountMetas;
|
|
1642
|
+
}
|
|
1643
|
+
function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTableAddress) {
|
|
1644
|
+
const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
|
|
1645
|
+
const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
|
|
1646
|
+
if (missing.length > 0) {
|
|
1647
|
+
const missingAddresses = missing.join(", ");
|
|
1648
|
+
throw new Error(`Addresses not provided for lookup tables: [${missingAddresses}]`);
|
|
1649
|
+
}
|
|
1650
|
+
const readOnlyMetas = [];
|
|
1651
|
+
const writableMetas = [];
|
|
1652
|
+
for (const lookup of compiledAddressTableLookups) {
|
|
1653
|
+
const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
|
|
1654
|
+
const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
|
|
1655
|
+
if (highestIndex >= addresses.length) {
|
|
1656
|
+
throw new Error(
|
|
1657
|
+
`Cannot look up index ${highestIndex} in lookup table [${lookup.lookupTableAddress}]. The lookup table may have been extended since the addresses provided were retrieved.`
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
const readOnlyForLookup = lookup.readableIndices.map((r) => ({
|
|
1661
|
+
address: addresses[r],
|
|
1662
|
+
addressIndex: r,
|
|
1663
|
+
lookupTableAddress: lookup.lookupTableAddress,
|
|
1664
|
+
role: AccountRole2.READONLY
|
|
1665
|
+
}));
|
|
1666
|
+
readOnlyMetas.push(...readOnlyForLookup);
|
|
1667
|
+
const writableForLookup = lookup.writableIndices.map((w) => ({
|
|
1668
|
+
address: addresses[w],
|
|
1669
|
+
addressIndex: w,
|
|
1670
|
+
lookupTableAddress: lookup.lookupTableAddress,
|
|
1671
|
+
role: AccountRole2.WRITABLE
|
|
1672
|
+
}));
|
|
1673
|
+
writableMetas.push(...writableForLookup);
|
|
1674
|
+
}
|
|
1675
|
+
return [...writableMetas, ...readOnlyMetas];
|
|
1676
|
+
}
|
|
1677
|
+
function convertInstruction(instruction, accountMetas) {
|
|
1678
|
+
var _a, _b;
|
|
1679
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
1680
|
+
if (!programAddress) {
|
|
1681
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1682
|
+
}
|
|
1683
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
1684
|
+
const { data } = instruction;
|
|
1685
|
+
return {
|
|
1686
|
+
programAddress,
|
|
1687
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
1688
|
+
...data && data.length ? { data } : {}
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
1692
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1693
|
+
return {
|
|
1694
|
+
blockhash: messageLifetimeToken,
|
|
1695
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
1696
|
+
// U64 MAX
|
|
1697
|
+
};
|
|
1698
|
+
} else {
|
|
1699
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1700
|
+
assertIsAddress(nonceAccountAddress);
|
|
1701
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1702
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
1703
|
+
return {
|
|
1704
|
+
nonce: messageLifetimeToken,
|
|
1705
|
+
nonceAccountAddress,
|
|
1706
|
+
nonceAuthorityAddress
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
function convertSignatures(compiledTransaction) {
|
|
1711
|
+
const {
|
|
1712
|
+
compiledMessage: { staticAccounts },
|
|
1713
|
+
signatures
|
|
1714
|
+
} = compiledTransaction;
|
|
1715
|
+
return signatures.reduce((acc, sig, index) => {
|
|
1716
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
1717
|
+
if (allZeros)
|
|
1718
|
+
return acc;
|
|
1719
|
+
const address2 = staticAccounts[index];
|
|
1720
|
+
return { ...acc, [address2]: sig };
|
|
1721
|
+
}, {});
|
|
1722
|
+
}
|
|
1723
|
+
function decompileTransaction(compiledTransaction, config) {
|
|
1724
|
+
var _a;
|
|
1725
|
+
const { compiledMessage } = compiledTransaction;
|
|
1726
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
1727
|
+
if (!feePayer)
|
|
1728
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
1729
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
1730
|
+
const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, (_a = config == null ? void 0 : config.addressesByLookupTableAddress) != null ? _a : {}) : [];
|
|
1731
|
+
const transactionMetas = [...accountMetas, ...accountLookupMetas];
|
|
1732
|
+
const instructions = compiledMessage.instructions.map(
|
|
1733
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, transactionMetas)
|
|
1734
|
+
);
|
|
1735
|
+
const firstInstruction = instructions[0];
|
|
1736
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
1737
|
+
compiledMessage.lifetimeToken,
|
|
1738
|
+
firstInstruction,
|
|
1739
|
+
config == null ? void 0 : config.lastValidBlockHeight
|
|
1740
|
+
);
|
|
1741
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
1742
|
+
return pipe(
|
|
1743
|
+
createTransaction({ version: compiledMessage.version }),
|
|
1744
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1745
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
1746
|
+
return appendTransactionInstruction(instruction, acc);
|
|
1747
|
+
}, tx),
|
|
1748
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1749
|
+
(tx) => Object.keys(signatures).length > 0 ? { ...tx, signatures } : tx
|
|
1750
|
+
);
|
|
1751
|
+
}
|
|
1539
1752
|
function upsert(addressMap, address2, update) {
|
|
1540
1753
|
var _a;
|
|
1541
1754
|
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole2.READONLY });
|
|
@@ -2022,117 +2235,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2022
2235
|
signatures
|
|
2023
2236
|
};
|
|
2024
2237
|
}
|
|
2025
|
-
function getAccountMetas(message) {
|
|
2026
|
-
const { header } = message;
|
|
2027
|
-
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
2028
|
-
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
2029
|
-
const accountMetas = [];
|
|
2030
|
-
let accountIndex = 0;
|
|
2031
|
-
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
2032
|
-
accountMetas.push({
|
|
2033
|
-
address: message.staticAccounts[accountIndex],
|
|
2034
|
-
role: AccountRole2.WRITABLE_SIGNER
|
|
2035
|
-
});
|
|
2036
|
-
accountIndex++;
|
|
2037
|
-
}
|
|
2038
|
-
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
2039
|
-
accountMetas.push({
|
|
2040
|
-
address: message.staticAccounts[accountIndex],
|
|
2041
|
-
role: AccountRole2.READONLY_SIGNER
|
|
2042
|
-
});
|
|
2043
|
-
accountIndex++;
|
|
2044
|
-
}
|
|
2045
|
-
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
2046
|
-
accountMetas.push({
|
|
2047
|
-
address: message.staticAccounts[accountIndex],
|
|
2048
|
-
role: AccountRole2.WRITABLE
|
|
2049
|
-
});
|
|
2050
|
-
accountIndex++;
|
|
2051
|
-
}
|
|
2052
|
-
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
2053
|
-
accountMetas.push({
|
|
2054
|
-
address: message.staticAccounts[accountIndex],
|
|
2055
|
-
role: AccountRole2.READONLY
|
|
2056
|
-
});
|
|
2057
|
-
accountIndex++;
|
|
2058
|
-
}
|
|
2059
|
-
return accountMetas;
|
|
2060
|
-
}
|
|
2061
|
-
function convertInstruction(instruction, accountMetas) {
|
|
2062
|
-
var _a, _b;
|
|
2063
|
-
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
2064
|
-
if (!programAddress) {
|
|
2065
|
-
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
2066
|
-
}
|
|
2067
|
-
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
2068
|
-
const { data } = instruction;
|
|
2069
|
-
return {
|
|
2070
|
-
programAddress,
|
|
2071
|
-
...accounts && accounts.length ? { accounts } : {},
|
|
2072
|
-
...data && data.length ? { data } : {}
|
|
2073
|
-
};
|
|
2074
|
-
}
|
|
2075
|
-
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
2076
|
-
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
2077
|
-
return {
|
|
2078
|
-
blockhash: messageLifetimeToken,
|
|
2079
|
-
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
2080
|
-
// U64 MAX
|
|
2081
|
-
};
|
|
2082
|
-
} else {
|
|
2083
|
-
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
2084
|
-
assertIsAddress(nonceAccountAddress);
|
|
2085
|
-
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
2086
|
-
assertIsAddress(nonceAuthorityAddress);
|
|
2087
|
-
return {
|
|
2088
|
-
nonce: messageLifetimeToken,
|
|
2089
|
-
nonceAccountAddress,
|
|
2090
|
-
nonceAuthorityAddress
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
function convertSignatures(compiledTransaction) {
|
|
2095
|
-
const {
|
|
2096
|
-
compiledMessage: { staticAccounts },
|
|
2097
|
-
signatures
|
|
2098
|
-
} = compiledTransaction;
|
|
2099
|
-
return signatures.reduce((acc, sig, index) => {
|
|
2100
|
-
const allZeros = sig.every((byte) => byte === 0);
|
|
2101
|
-
if (allZeros)
|
|
2102
|
-
return acc;
|
|
2103
|
-
const address2 = staticAccounts[index];
|
|
2104
|
-
return { ...acc, [address2]: sig };
|
|
2105
|
-
}, {});
|
|
2106
|
-
}
|
|
2107
|
-
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
2108
|
-
const { compiledMessage } = compiledTransaction;
|
|
2109
|
-
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
2110
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
2111
|
-
}
|
|
2112
|
-
const feePayer = compiledMessage.staticAccounts[0];
|
|
2113
|
-
if (!feePayer)
|
|
2114
|
-
throw new Error("No fee payer set in CompiledTransaction");
|
|
2115
|
-
const accountMetas = getAccountMetas(compiledMessage);
|
|
2116
|
-
const instructions = compiledMessage.instructions.map(
|
|
2117
|
-
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
2118
|
-
);
|
|
2119
|
-
const firstInstruction = instructions[0];
|
|
2120
|
-
const lifetimeConstraint = getLifetimeConstraint(
|
|
2121
|
-
compiledMessage.lifetimeToken,
|
|
2122
|
-
firstInstruction,
|
|
2123
|
-
lastValidBlockHeight
|
|
2124
|
-
);
|
|
2125
|
-
const signatures = convertSignatures(compiledTransaction);
|
|
2126
|
-
return pipe(
|
|
2127
|
-
createTransaction({ version: compiledMessage.version }),
|
|
2128
|
-
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
2129
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
2130
|
-
return appendTransactionInstruction(instruction, acc);
|
|
2131
|
-
}, tx),
|
|
2132
|
-
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
2133
|
-
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
2134
|
-
);
|
|
2135
|
-
}
|
|
2136
2238
|
function getCompiledTransactionEncoder() {
|
|
2137
2239
|
return getStructEncoder([
|
|
2138
2240
|
["signatures", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],
|
|
@@ -2153,14 +2255,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2153
2255
|
function getTransactionEncoder() {
|
|
2154
2256
|
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
2155
2257
|
}
|
|
2156
|
-
function getTransactionDecoder(
|
|
2258
|
+
function getTransactionDecoder(config) {
|
|
2157
2259
|
return mapDecoder(
|
|
2158
2260
|
getCompiledTransactionDecoder(),
|
|
2159
|
-
(compiledTransaction) => decompileTransaction(compiledTransaction,
|
|
2261
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, config)
|
|
2160
2262
|
);
|
|
2161
2263
|
}
|
|
2162
|
-
function getTransactionCodec(
|
|
2163
|
-
return combineCodec(getTransactionEncoder(), getTransactionDecoder(
|
|
2264
|
+
function getTransactionCodec(config) {
|
|
2265
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(config));
|
|
2164
2266
|
}
|
|
2165
2267
|
var base58Decoder;
|
|
2166
2268
|
function getSignatureFromTransaction(transaction) {
|
|
@@ -2206,11 +2308,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2206
2308
|
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole2(a.role))) != null ? _b : [];
|
|
2207
2309
|
}).map((a) => a.address);
|
|
2208
2310
|
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
2311
|
+
const missingSigs = [];
|
|
2209
2312
|
requiredSigners.forEach((address2) => {
|
|
2210
2313
|
if (!transaction.signatures[address2]) {
|
|
2211
|
-
|
|
2314
|
+
missingSigs.push(address2);
|
|
2212
2315
|
}
|
|
2213
2316
|
});
|
|
2317
|
+
if (missingSigs.length > 0) {
|
|
2318
|
+
throw new Error("Transaction is missing signatures for addresses: " + missingSigs.join(", "));
|
|
2319
|
+
}
|
|
2214
2320
|
}
|
|
2215
2321
|
function getBase64EncodedWireTransaction(transaction) {
|
|
2216
2322
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
@@ -3954,22 +4060,52 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
3954
4060
|
|
|
3955
4061
|
// src/transaction-confirmation-strategy-blockheight.ts
|
|
3956
4062
|
init_env_shim();
|
|
3957
|
-
function createBlockHeightExceedencePromiseFactory(
|
|
3958
|
-
|
|
4063
|
+
function createBlockHeightExceedencePromiseFactory({
|
|
4064
|
+
rpc,
|
|
4065
|
+
rpcSubscriptions
|
|
4066
|
+
}) {
|
|
4067
|
+
return async function getBlockHeightExceedencePromise({
|
|
4068
|
+
abortSignal: callerAbortSignal,
|
|
4069
|
+
commitment,
|
|
4070
|
+
lastValidBlockHeight
|
|
4071
|
+
}) {
|
|
3959
4072
|
const abortController = new AbortController();
|
|
3960
|
-
|
|
4073
|
+
const handleAbort = () => {
|
|
3961
4074
|
abortController.abort();
|
|
3962
|
-
}
|
|
4075
|
+
};
|
|
3963
4076
|
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3964
|
-
|
|
4077
|
+
async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
|
|
4078
|
+
const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
|
|
4079
|
+
return {
|
|
4080
|
+
blockHeight,
|
|
4081
|
+
differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
|
|
4082
|
+
};
|
|
4083
|
+
}
|
|
3965
4084
|
try {
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
4085
|
+
const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
|
|
4086
|
+
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
|
|
4087
|
+
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
|
|
4088
|
+
]);
|
|
4089
|
+
if (blockHeight <= lastValidBlockHeight) {
|
|
4090
|
+
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
|
|
4091
|
+
for await (const slotNotification of slotNotifications) {
|
|
4092
|
+
const { slot } = slotNotification;
|
|
4093
|
+
if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
|
|
4094
|
+
const {
|
|
4095
|
+
blockHeight: currentBlockHeight,
|
|
4096
|
+
differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
|
|
4097
|
+
} = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
|
|
4098
|
+
if (currentBlockHeight > lastValidBlockHeight) {
|
|
4099
|
+
break;
|
|
4100
|
+
} else {
|
|
4101
|
+
lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
3971
4104
|
}
|
|
3972
4105
|
}
|
|
4106
|
+
throw new Error(
|
|
4107
|
+
"The network has progressed past the last block for which this transaction could have been committed."
|
|
4108
|
+
);
|
|
3973
4109
|
} finally {
|
|
3974
4110
|
abortController.abort();
|
|
3975
4111
|
}
|
|
@@ -4064,7 +4200,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4064
4200
|
rpc,
|
|
4065
4201
|
rpcSubscriptions
|
|
4066
4202
|
}) {
|
|
4067
|
-
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(
|
|
4203
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
4204
|
+
rpc,
|
|
4205
|
+
rpcSubscriptions
|
|
4206
|
+
});
|
|
4068
4207
|
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
4069
4208
|
rpc,
|
|
4070
4209
|
rpcSubscriptions
|
|
@@ -4097,10 +4236,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4097
4236
|
await raceStrategies(
|
|
4098
4237
|
getSignatureFromTransaction(config.transaction),
|
|
4099
4238
|
config,
|
|
4100
|
-
function getSpecificStrategiesForRace({
|
|
4239
|
+
function getSpecificStrategiesForRace({
|
|
4240
|
+
abortSignal,
|
|
4241
|
+
commitment,
|
|
4242
|
+
getBlockHeightExceedencePromise,
|
|
4243
|
+
transaction
|
|
4244
|
+
}) {
|
|
4101
4245
|
return [
|
|
4102
4246
|
getBlockHeightExceedencePromise({
|
|
4103
4247
|
abortSignal,
|
|
4248
|
+
commitment,
|
|
4104
4249
|
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
4105
4250
|
})
|
|
4106
4251
|
];
|
|
@@ -4223,8 +4368,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4223
4368
|
}
|
|
4224
4369
|
|
|
4225
4370
|
exports.AccountRole = AccountRole;
|
|
4371
|
+
exports.BASE_ACCOUNT_SIZE = BASE_ACCOUNT_SIZE;
|
|
4226
4372
|
exports.address = address;
|
|
4227
4373
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
4374
|
+
exports.assertAccountDecoded = assertAccountDecoded;
|
|
4375
|
+
exports.assertAccountExists = assertAccountExists;
|
|
4376
|
+
exports.assertAccountsDecoded = assertAccountsDecoded;
|
|
4377
|
+
exports.assertAccountsExist = assertAccountsExist;
|
|
4228
4378
|
exports.assertIsAddress = assertIsAddress;
|
|
4229
4379
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
4230
4380
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
@@ -4254,8 +4404,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4254
4404
|
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
4255
4405
|
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
4256
4406
|
exports.createTransaction = createTransaction;
|
|
4407
|
+
exports.decodeAccount = decodeAccount;
|
|
4408
|
+
exports.decompileTransaction = decompileTransaction;
|
|
4257
4409
|
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
4258
4410
|
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
4411
|
+
exports.fetchEncodedAccount = fetchEncodedAccount;
|
|
4412
|
+
exports.fetchEncodedAccounts = fetchEncodedAccounts;
|
|
4413
|
+
exports.fetchJsonParsedAccount = fetchJsonParsedAccount;
|
|
4414
|
+
exports.fetchJsonParsedAccounts = fetchJsonParsedAccounts;
|
|
4259
4415
|
exports.generateKeyPair = generateKeyPair;
|
|
4260
4416
|
exports.getAddressCodec = getAddressCodec;
|
|
4261
4417
|
exports.getAddressComparator = getAddressComparator;
|
|
@@ -4266,6 +4422,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4266
4422
|
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
4267
4423
|
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
4268
4424
|
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
4425
|
+
exports.getCompiledTransactionDecoder = getCompiledTransactionDecoder;
|
|
4269
4426
|
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
4270
4427
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
4271
4428
|
exports.getTransactionCodec = getTransactionCodec;
|
|
@@ -4283,7 +4440,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4283
4440
|
exports.isWritableRole = isWritableRole;
|
|
4284
4441
|
exports.lamports = lamports;
|
|
4285
4442
|
exports.mergeRoles = mergeRoles;
|
|
4443
|
+
exports.parseBase58RpcAccount = parseBase58RpcAccount;
|
|
4444
|
+
exports.parseBase64RpcAccount = parseBase64RpcAccount;
|
|
4445
|
+
exports.parseJsonRpcAccount = parseJsonRpcAccount;
|
|
4286
4446
|
exports.partiallySignTransaction = partiallySignTransaction;
|
|
4447
|
+
exports.pipe = pipe;
|
|
4287
4448
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
4288
4449
|
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
4289
4450
|
exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
|