@solana/transactions 2.0.0-experimental.06517d7 → 2.0.0-experimental.080a7d1
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 +42 -27
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +42 -27
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +42 -27
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +42 -27
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +42 -27
- package/dist/index.node.js.map +1 -1
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/decompile-transaction.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/serializers/message.d.ts.map +1 -1
- package/dist/types/serializers/transaction-version.d.ts.map +1 -1
- package/package.json +17 -40
package/dist/index.browser.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { SolanaError, SOLANA_ERROR__TRANSACTION_EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION_EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION_VERSION_NUMBER_OUT_OF_RANGE } from '@solana/errors';
|
|
1
2
|
import { getBase58Decoder, getBase64Decoder, getStringEncoder, getBase58Encoder, getStringDecoder } from '@solana/codecs-strings';
|
|
2
3
|
import { getAddressFromPublicKey, assertIsAddress, getAddressComparator, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
|
|
3
4
|
import { pipe } from '@solana/functional';
|
|
4
5
|
import { createEncoder, mapDecoder, combineCodec, mapEncoder, createDecoder } from '@solana/codecs-core';
|
|
5
6
|
import { getStructDecoder, getArrayDecoder, getBytesDecoder, getStructEncoder, getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';
|
|
6
7
|
import { getShortU16Decoder, getShortU16Encoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
|
|
7
|
-
import { SolanaError, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES } from '@solana/errors';
|
|
8
8
|
import { signBytes } from '@solana/keys';
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// src/blockhash.ts
|
|
11
11
|
var base58Encoder;
|
|
12
12
|
function assertIsBlockhash(putativeBlockhash) {
|
|
13
13
|
if (!base58Encoder)
|
|
@@ -60,7 +60,7 @@ function isTransactionWithBlockhashLifetime(transaction) {
|
|
|
60
60
|
}
|
|
61
61
|
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
62
62
|
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
63
|
-
throw new
|
|
63
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_EXPECTED_BLOCKHASH_LIFETIME);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
@@ -109,13 +109,11 @@ function isWritableRole(role) {
|
|
|
109
109
|
function mergeRoles(roleA, roleB) {
|
|
110
110
|
return roleA | roleB;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
// src/durable-nonce.ts
|
|
114
112
|
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
115
113
|
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
116
114
|
function assertIsDurableNonceTransaction(transaction) {
|
|
117
115
|
if (!isDurableNonceTransaction(transaction)) {
|
|
118
|
-
throw new
|
|
116
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_EXPECTED_NONCE_LIFETIME);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
119
|
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
@@ -264,8 +262,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
|
|
|
264
262
|
const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
|
|
265
263
|
const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
|
|
266
264
|
if (missing.length > 0) {
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, {
|
|
266
|
+
lookupTableAddresses: missing
|
|
267
|
+
});
|
|
269
268
|
}
|
|
270
269
|
const readOnlyMetas = [];
|
|
271
270
|
const writableMetas = [];
|
|
@@ -273,8 +272,13 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
|
|
|
273
272
|
const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
|
|
274
273
|
const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
|
|
275
274
|
if (highestIndex >= addresses.length) {
|
|
276
|
-
throw new
|
|
277
|
-
|
|
275
|
+
throw new SolanaError(
|
|
276
|
+
SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE,
|
|
277
|
+
{
|
|
278
|
+
highestKnownIndex: addresses.length - 1,
|
|
279
|
+
highestRequestedIndex: highestIndex,
|
|
280
|
+
lookupTableAddress: lookup.lookupTableAddress
|
|
281
|
+
}
|
|
278
282
|
);
|
|
279
283
|
}
|
|
280
284
|
const readOnlyForLookup = lookup.readableIndices.map((r) => ({
|
|
@@ -297,7 +301,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
|
|
|
297
301
|
function convertInstruction(instruction, accountMetas) {
|
|
298
302
|
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
299
303
|
if (!programAddress) {
|
|
300
|
-
throw new
|
|
304
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, {
|
|
305
|
+
index: instruction.programAddressIndex
|
|
306
|
+
});
|
|
301
307
|
}
|
|
302
308
|
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
303
309
|
const { data } = instruction;
|
|
@@ -342,8 +348,9 @@ function convertSignatures(compiledTransaction) {
|
|
|
342
348
|
function decompileTransaction(compiledTransaction, config) {
|
|
343
349
|
const { compiledMessage } = compiledTransaction;
|
|
344
350
|
const feePayer = compiledMessage.staticAccounts[0];
|
|
345
|
-
if (!feePayer)
|
|
346
|
-
throw new
|
|
351
|
+
if (!feePayer) {
|
|
352
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_FEE_PAYER_MISSING);
|
|
353
|
+
}
|
|
347
354
|
const accountMetas = getAccountMetas(compiledMessage);
|
|
348
355
|
const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, config?.addressesByLookupTableAddress ?? {}) : [];
|
|
349
356
|
const transactionMetas = [...accountMetas, ...accountLookupMetas];
|
|
@@ -383,13 +390,13 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
383
390
|
if (isWritableRole(entry.role)) {
|
|
384
391
|
switch (entry[TYPE]) {
|
|
385
392
|
case 0 /* FEE_PAYER */:
|
|
386
|
-
throw new
|
|
387
|
-
|
|
388
|
-
);
|
|
393
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, {
|
|
394
|
+
programAddress: instruction.programAddress
|
|
395
|
+
});
|
|
389
396
|
default:
|
|
390
|
-
throw new
|
|
391
|
-
|
|
392
|
-
);
|
|
397
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, {
|
|
398
|
+
programAddress: instruction.programAddress
|
|
399
|
+
});
|
|
393
400
|
}
|
|
394
401
|
}
|
|
395
402
|
if (entry[TYPE] === 2 /* STATIC */) {
|
|
@@ -454,8 +461,11 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
454
461
|
addressesOfInvokedPrograms.has(account.address)
|
|
455
462
|
) {
|
|
456
463
|
if (isWritableRole(accountMeta.role)) {
|
|
457
|
-
throw new
|
|
458
|
-
|
|
464
|
+
throw new SolanaError(
|
|
465
|
+
SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE,
|
|
466
|
+
{
|
|
467
|
+
programAddress: account.address
|
|
468
|
+
}
|
|
459
469
|
);
|
|
460
470
|
}
|
|
461
471
|
if (entry.role !== nextRole) {
|
|
@@ -745,7 +755,9 @@ function getTransactionVersionEncoder() {
|
|
|
745
755
|
return offset;
|
|
746
756
|
}
|
|
747
757
|
if (value < 0 || value > 127) {
|
|
748
|
-
throw new
|
|
758
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_VERSION_NUMBER_OUT_OF_RANGE, {
|
|
759
|
+
actualVersion: value
|
|
760
|
+
});
|
|
749
761
|
}
|
|
750
762
|
bytes.set([value | VERSION_FLAG_MASK], offset);
|
|
751
763
|
return offset + 1;
|
|
@@ -832,12 +844,15 @@ function getCompiledMessageEncoder() {
|
|
|
832
844
|
});
|
|
833
845
|
}
|
|
834
846
|
function getCompiledMessageDecoder() {
|
|
835
|
-
return mapDecoder(
|
|
836
|
-
|
|
837
|
-
|
|
847
|
+
return mapDecoder(
|
|
848
|
+
getStructDecoder(getPreludeStructDecoderTuple()),
|
|
849
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
850
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
851
|
+
return restOfMessage;
|
|
852
|
+
}
|
|
853
|
+
return { ...restOfMessage, addressTableLookups };
|
|
838
854
|
}
|
|
839
|
-
|
|
840
|
-
});
|
|
855
|
+
);
|
|
841
856
|
}
|
|
842
857
|
function getCompiledMessageCodec() {
|
|
843
858
|
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|