@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,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('@solana/errors');
3
4
  var codecsStrings = require('@solana/codecs-strings');
4
5
  var addresses = require('@solana/addresses');
5
6
  var functional = require('@solana/functional');
6
7
  var codecsCore = require('@solana/codecs-core');
7
8
  var codecsDataStructures = require('@solana/codecs-data-structures');
8
9
  var codecsNumbers = require('@solana/codecs-numbers');
9
- var errors = require('@solana/errors');
10
10
  var keys = require('@solana/keys');
11
11
 
12
- // ../rpc-types/dist/index.browser.js
12
+ // src/blockhash.ts
13
13
  var base58Encoder;
14
14
  function assertIsBlockhash(putativeBlockhash) {
15
15
  if (!base58Encoder)
@@ -62,7 +62,7 @@ function isTransactionWithBlockhashLifetime(transaction) {
62
62
  }
63
63
  function assertIsTransactionWithBlockhashLifetime(transaction) {
64
64
  if (!isTransactionWithBlockhashLifetime(transaction)) {
65
- throw new Error("Transaction does not have a blockhash lifetime");
65
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_EXPECTED_BLOCKHASH_LIFETIME);
66
66
  }
67
67
  }
68
68
  function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
@@ -111,13 +111,11 @@ function isWritableRole(role) {
111
111
  function mergeRoles(roleA, roleB) {
112
112
  return roleA | roleB;
113
113
  }
114
-
115
- // src/durable-nonce.ts
116
114
  var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
117
115
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
118
116
  function assertIsDurableNonceTransaction(transaction) {
119
117
  if (!isDurableNonceTransaction(transaction)) {
120
- throw new Error("Transaction is not a durable nonce transaction");
118
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_EXPECTED_NONCE_LIFETIME);
121
119
  }
122
120
  }
123
121
  function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
@@ -266,8 +264,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
266
264
  const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
267
265
  const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
268
266
  if (missing.length > 0) {
269
- const missingAddresses = missing.join(", ");
270
- throw new Error(`Addresses not provided for lookup tables: [${missingAddresses}]`);
267
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, {
268
+ lookupTableAddresses: missing
269
+ });
271
270
  }
272
271
  const readOnlyMetas = [];
273
272
  const writableMetas = [];
@@ -275,8 +274,13 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
275
274
  const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
276
275
  const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
277
276
  if (highestIndex >= addresses.length) {
278
- throw new Error(
279
- `Cannot look up index ${highestIndex} in lookup table [${lookup.lookupTableAddress}]. The lookup table may have been extended since the addresses provided were retrieved.`
277
+ throw new errors.SolanaError(
278
+ errors.SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE,
279
+ {
280
+ highestKnownIndex: addresses.length - 1,
281
+ highestRequestedIndex: highestIndex,
282
+ lookupTableAddress: lookup.lookupTableAddress
283
+ }
280
284
  );
281
285
  }
282
286
  const readOnlyForLookup = lookup.readableIndices.map((r) => ({
@@ -299,7 +303,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
299
303
  function convertInstruction(instruction, accountMetas) {
300
304
  const programAddress = accountMetas[instruction.programAddressIndex]?.address;
301
305
  if (!programAddress) {
302
- throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
306
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, {
307
+ index: instruction.programAddressIndex
308
+ });
303
309
  }
304
310
  const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
305
311
  const { data } = instruction;
@@ -344,8 +350,9 @@ function convertSignatures(compiledTransaction) {
344
350
  function decompileTransaction(compiledTransaction, config) {
345
351
  const { compiledMessage } = compiledTransaction;
346
352
  const feePayer = compiledMessage.staticAccounts[0];
347
- if (!feePayer)
348
- throw new Error("No fee payer set in CompiledTransaction");
353
+ if (!feePayer) {
354
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_FEE_PAYER_MISSING);
355
+ }
349
356
  const accountMetas = getAccountMetas(compiledMessage);
350
357
  const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, config?.addressesByLookupTableAddress ?? {}) : [];
351
358
  const transactionMetas = [...accountMetas, ...accountLookupMetas];
@@ -385,13 +392,13 @@ function getAddressMapFromInstructions(feePayer, instructions) {
385
392
  if (isWritableRole(entry.role)) {
386
393
  switch (entry[TYPE]) {
387
394
  case 0 /* FEE_PAYER */:
388
- throw new Error(
389
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
390
- );
395
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, {
396
+ programAddress: instruction.programAddress
397
+ });
391
398
  default:
392
- throw new Error(
393
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
394
- );
399
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, {
400
+ programAddress: instruction.programAddress
401
+ });
395
402
  }
396
403
  }
397
404
  if (entry[TYPE] === 2 /* STATIC */) {
@@ -456,8 +463,11 @@ function getAddressMapFromInstructions(feePayer, instructions) {
456
463
  addressesOfInvokedPrograms.has(account.address)
457
464
  ) {
458
465
  if (isWritableRole(accountMeta.role)) {
459
- throw new Error(
460
- `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
466
+ throw new errors.SolanaError(
467
+ errors.SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE,
468
+ {
469
+ programAddress: account.address
470
+ }
461
471
  );
462
472
  }
463
473
  if (entry.role !== nextRole) {
@@ -747,7 +757,9 @@ function getTransactionVersionEncoder() {
747
757
  return offset;
748
758
  }
749
759
  if (value < 0 || value > 127) {
750
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
760
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_VERSION_NUMBER_OUT_OF_RANGE, {
761
+ actualVersion: value
762
+ });
751
763
  }
752
764
  bytes.set([value | VERSION_FLAG_MASK], offset);
753
765
  return offset + 1;
@@ -834,12 +846,15 @@ function getCompiledMessageEncoder() {
834
846
  });
835
847
  }
836
848
  function getCompiledMessageDecoder() {
837
- return codecsCore.mapDecoder(codecsDataStructures.getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
838
- if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
839
- return restOfMessage;
849
+ return codecsCore.mapDecoder(
850
+ codecsDataStructures.getStructDecoder(getPreludeStructDecoderTuple()),
851
+ ({ addressTableLookups, ...restOfMessage }) => {
852
+ if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
853
+ return restOfMessage;
854
+ }
855
+ return { ...restOfMessage, addressTableLookups };
840
856
  }
841
- return { ...restOfMessage, addressTableLookups };
842
- });
857
+ );
843
858
  }
844
859
  function getCompiledMessageCodec() {
845
860
  return codecsCore.combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());