@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.
@@ -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
- // ../rpc-types/dist/index.browser.js
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 Error("Transaction does not have a blockhash lifetime");
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 Error("Transaction is not a durable nonce transaction");
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
- const missingAddresses = missing.join(", ");
268
- throw new Error(`Addresses not provided for lookup tables: [${missingAddresses}]`);
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 Error(
277
- `Cannot look up index ${highestIndex} in lookup table [${lookup.lookupTableAddress}]. The lookup table may have been extended since the addresses provided were retrieved.`
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 Error(`Could not find program address at index ${instruction.programAddressIndex}`);
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 Error("No fee payer set in CompiledTransaction");
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 Error(
387
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
388
- );
393
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, {
394
+ programAddress: instruction.programAddress
395
+ });
389
396
  default:
390
- throw new Error(
391
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
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 Error(
458
- `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
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 Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
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(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
836
- if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
837
- return restOfMessage;
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
- return { ...restOfMessage, addressTableLookups };
840
- });
855
+ );
841
856
  }
842
857
  function getCompiledMessageCodec() {
843
858
  return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());