@solana/transactions 2.0.0-experimental.098806e → 2.0.0-experimental.0ba8f21

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,3 +1,4 @@
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';
@@ -6,7 +7,7 @@ import { getStructDecoder, getArrayDecoder, getBytesDecoder, getStructEncoder, g
6
7
  import { getShortU16Decoder, getShortU16Encoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
7
8
  import { signBytes } from '@solana/keys';
8
9
 
9
- // ../rpc-types/dist/index.browser.js
10
+ // src/blockhash.ts
10
11
  var base58Encoder;
11
12
  function assertIsBlockhash(putativeBlockhash) {
12
13
  if (!base58Encoder)
@@ -59,7 +60,7 @@ function isTransactionWithBlockhashLifetime(transaction) {
59
60
  }
60
61
  function assertIsTransactionWithBlockhashLifetime(transaction) {
61
62
  if (!isTransactionWithBlockhashLifetime(transaction)) {
62
- throw new Error("Transaction does not have a blockhash lifetime");
63
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_EXPECTED_BLOCKHASH_LIFETIME);
63
64
  }
64
65
  }
65
66
  function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
@@ -108,13 +109,11 @@ function isWritableRole(role) {
108
109
  function mergeRoles(roleA, roleB) {
109
110
  return roleA | roleB;
110
111
  }
111
-
112
- // src/durable-nonce.ts
113
112
  var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
114
113
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
115
114
  function assertIsDurableNonceTransaction(transaction) {
116
115
  if (!isDurableNonceTransaction(transaction)) {
117
- throw new Error("Transaction is not a durable nonce transaction");
116
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_EXPECTED_NONCE_LIFETIME);
118
117
  }
119
118
  }
120
119
  function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
@@ -200,17 +199,23 @@ function setTransactionFeePayer(feePayer, transaction) {
200
199
 
201
200
  // src/instructions.ts
202
201
  function appendTransactionInstruction(instruction, transaction) {
202
+ return appendTransactionInstructions([instruction], transaction);
203
+ }
204
+ function appendTransactionInstructions(instructions, transaction) {
203
205
  const out = {
204
206
  ...getUnsignedTransaction(transaction),
205
- instructions: [...transaction.instructions, instruction]
207
+ instructions: [...transaction.instructions, ...instructions]
206
208
  };
207
209
  Object.freeze(out);
208
210
  return out;
209
211
  }
210
212
  function prependTransactionInstruction(instruction, transaction) {
213
+ return prependTransactionInstructions([instruction], transaction);
214
+ }
215
+ function prependTransactionInstructions(instructions, transaction) {
211
216
  const out = {
212
217
  ...getUnsignedTransaction(transaction),
213
- instructions: [instruction, ...transaction.instructions]
218
+ instructions: [...instructions, ...transaction.instructions]
214
219
  };
215
220
  Object.freeze(out);
216
221
  return out;
@@ -257,8 +262,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
257
262
  const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
258
263
  const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
259
264
  if (missing.length > 0) {
260
- const missingAddresses = missing.join(", ");
261
- 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
+ });
262
268
  }
263
269
  const readOnlyMetas = [];
264
270
  const writableMetas = [];
@@ -266,8 +272,13 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
266
272
  const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
267
273
  const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
268
274
  if (highestIndex >= addresses.length) {
269
- throw new Error(
270
- `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
+ }
271
282
  );
272
283
  }
273
284
  const readOnlyForLookup = lookup.readableIndices.map((r) => ({
@@ -290,7 +301,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
290
301
  function convertInstruction(instruction, accountMetas) {
291
302
  const programAddress = accountMetas[instruction.programAddressIndex]?.address;
292
303
  if (!programAddress) {
293
- 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
+ });
294
307
  }
295
308
  const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
296
309
  const { data } = instruction;
@@ -335,8 +348,9 @@ function convertSignatures(compiledTransaction) {
335
348
  function decompileTransaction(compiledTransaction, config) {
336
349
  const { compiledMessage } = compiledTransaction;
337
350
  const feePayer = compiledMessage.staticAccounts[0];
338
- if (!feePayer)
339
- 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
+ }
340
354
  const accountMetas = getAccountMetas(compiledMessage);
341
355
  const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, config?.addressesByLookupTableAddress ?? {}) : [];
342
356
  const transactionMetas = [...accountMetas, ...accountLookupMetas];
@@ -376,13 +390,13 @@ function getAddressMapFromInstructions(feePayer, instructions) {
376
390
  if (isWritableRole(entry.role)) {
377
391
  switch (entry[TYPE]) {
378
392
  case 0 /* FEE_PAYER */:
379
- throw new Error(
380
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
381
- );
393
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, {
394
+ programAddress: instruction.programAddress
395
+ });
382
396
  default:
383
- throw new Error(
384
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
385
- );
397
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, {
398
+ programAddress: instruction.programAddress
399
+ });
386
400
  }
387
401
  }
388
402
  if (entry[TYPE] === 2 /* STATIC */) {
@@ -447,8 +461,11 @@ function getAddressMapFromInstructions(feePayer, instructions) {
447
461
  addressesOfInvokedPrograms.has(account.address)
448
462
  ) {
449
463
  if (isWritableRole(accountMeta.role)) {
450
- throw new Error(
451
- `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
+ }
452
469
  );
453
470
  }
454
471
  if (entry.role !== nextRole) {
@@ -738,7 +755,9 @@ function getTransactionVersionEncoder() {
738
755
  return offset;
739
756
  }
740
757
  if (value < 0 || value > 127) {
741
- 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
+ });
742
761
  }
743
762
  bytes.set([value | VERSION_FLAG_MASK], offset);
744
763
  return offset + 1;
@@ -825,12 +844,15 @@ function getCompiledMessageEncoder() {
825
844
  });
826
845
  }
827
846
  function getCompiledMessageDecoder() {
828
- return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
829
- if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
830
- 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 };
831
854
  }
832
- return { ...restOfMessage, addressTableLookups };
833
- });
855
+ );
834
856
  }
835
857
  function getCompiledMessageCodec() {
836
858
  return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
@@ -890,9 +912,7 @@ function getSignatureFromTransaction(transaction) {
890
912
  base58Decoder = getBase58Decoder();
891
913
  const signatureBytes = transaction.signatures[transaction.feePayer];
892
914
  if (!signatureBytes) {
893
- throw new Error(
894
- "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
895
- );
915
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE);
896
916
  }
897
917
  const transactionSignature = base58Decoder.decode(signatureBytes);
898
918
  return transactionSignature;
@@ -932,7 +952,9 @@ function assertTransactionIsFullySigned(transaction) {
932
952
  }
933
953
  });
934
954
  if (missingSigs.length > 0) {
935
- throw new Error("Transaction is missing signatures for addresses: " + missingSigs.join(", "));
955
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, {
956
+ addresses: missingSigs
957
+ });
936
958
  }
937
959
  }
938
960
  function getBase64EncodedWireTransaction(transaction) {
@@ -940,6 +962,6 @@ function getBase64EncodedWireTransaction(transaction) {
940
962
  return getBase64Decoder().decode(wireTransactionBytes);
941
963
  }
942
964
 
943
- export { appendTransactionInstruction, assertIsDurableNonceTransaction, assertIsTransactionWithBlockhashLifetime, assertTransactionIsFullySigned, compileMessage, createTransaction, decompileTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getCompiledTransactionDecoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
965
+ export { appendTransactionInstruction, appendTransactionInstructions, assertIsDurableNonceTransaction, assertIsTransactionWithBlockhashLifetime, assertTransactionIsFullySigned, compileMessage, createTransaction, decompileTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getCompiledTransactionDecoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, getUnsignedTransaction, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, prependTransactionInstructions, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
944
966
  //# sourceMappingURL=out.js.map
945
967
  //# sourceMappingURL=index.native.js.map