@solana/transaction-messages 2.1.1-canary-20250425205850 → 2.1.1-canary-20250425210025

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.
@@ -8,27 +8,27 @@ import { isSignerRole, AccountRole, isWritableRole, mergeRoles } from '@solana/i
8
8
  import { pipe } from '@solana/functional';
9
9
 
10
10
  // src/blockhash.ts
11
- function isTransactionMessageWithBlockhashLifetime(transaction) {
12
- const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
11
+ function isTransactionMessageWithBlockhashLifetime(transactionMessage) {
12
+ const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint";
13
13
  if (!lifetimeConstraintShapeMatches) return false;
14
14
  try {
15
- assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
15
+ assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
16
16
  return true;
17
17
  } catch {
18
18
  return false;
19
19
  }
20
20
  }
21
- function assertIsTransactionMessageWithBlockhashLifetime(transaction) {
22
- if (!isTransactionMessageWithBlockhashLifetime(transaction)) {
21
+ function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
22
+ if (!isTransactionMessageWithBlockhashLifetime(transactionMessage)) {
23
23
  throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME);
24
24
  }
25
25
  }
26
- function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
27
- if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
28
- return transaction;
26
+ function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transactionMessage) {
27
+ if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
28
+ return transactionMessage;
29
29
  }
30
30
  const out = {
31
- ...transaction,
31
+ ...transactionMessage,
32
32
  lifetimeConstraint: Object.freeze(blockhashLifetimeConstraint)
33
33
  };
34
34
  Object.freeze(out);
@@ -584,16 +584,19 @@ function getCompiledStaticAccounts(orderedAccounts) {
584
584
  }
585
585
 
586
586
  // src/compile/message.ts
587
- function compileTransactionMessage(transaction) {
588
- const addressMap = getAddressMapFromInstructions(transaction.feePayer.address, transaction.instructions);
587
+ function compileTransactionMessage(transactionMessage) {
588
+ const addressMap = getAddressMapFromInstructions(
589
+ transactionMessage.feePayer.address,
590
+ transactionMessage.instructions
591
+ );
589
592
  const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
590
593
  return {
591
- ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
594
+ ...transactionMessage.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
592
595
  header: getCompiledMessageHeader(orderedAccounts),
593
- instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
594
- lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
596
+ instructions: getCompiledInstructions(transactionMessage.instructions, orderedAccounts),
597
+ lifetimeToken: getCompiledLifetimeToken(transactionMessage.lifetimeConstraint),
595
598
  staticAccounts: getCompiledStaticAccounts(orderedAccounts),
596
- version: transaction.version
599
+ version: transactionMessage.version
597
600
  };
598
601
  }
599
602
  function findAddressInLookupTables(address, role, addressesByLookupTableAddress) {
@@ -655,8 +658,8 @@ function createTransactionMessage({
655
658
  }
656
659
  var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
657
660
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
658
- function assertIsDurableNonceTransactionMessage(transaction) {
659
- if (!isDurableNonceTransaction(transaction)) {
661
+ function assertIsDurableNonceTransactionMessage(transactionMessage) {
662
+ if (!isDurableNonceTransaction(transactionMessage)) {
660
663
  throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
661
664
  }
662
665
  }
@@ -685,8 +688,8 @@ function isAdvanceNonceAccountInstruction(instruction) {
685
688
  function isAdvanceNonceAccountInstructionData(data) {
686
689
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
687
690
  }
688
- function isDurableNonceTransaction(transaction) {
689
- return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
691
+ function isDurableNonceTransaction(transactionMessage) {
692
+ return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.nonce === "string" && transactionMessage.instructions[0] != null && isAdvanceNonceAccountInstruction(transactionMessage.instructions[0]);
690
693
  }
691
694
  function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
692
695
  return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
@@ -695,30 +698,30 @@ function setTransactionMessageLifetimeUsingDurableNonce({
695
698
  nonce,
696
699
  nonceAccountAddress,
697
700
  nonceAuthorityAddress
698
- }, transaction) {
701
+ }, transactionMessage) {
699
702
  let newInstructions;
700
- const firstInstruction = transaction.instructions[0];
703
+ const firstInstruction = transactionMessage.instructions[0];
701
704
  if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
702
705
  if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
703
- if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
704
- return transaction;
706
+ if (isDurableNonceTransaction(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
707
+ return transactionMessage;
705
708
  } else {
706
- newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
709
+ newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
707
710
  }
708
711
  } else {
709
712
  newInstructions = [
710
713
  Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
711
- ...transaction.instructions.slice(1)
714
+ ...transactionMessage.instructions.slice(1)
712
715
  ];
713
716
  }
714
717
  } else {
715
718
  newInstructions = [
716
719
  Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
717
- ...transaction.instructions
720
+ ...transactionMessage.instructions
718
721
  ];
719
722
  }
720
723
  return Object.freeze({
721
- ...transaction,
724
+ ...transactionMessage,
722
725
  instructions: Object.freeze(newInstructions),
723
726
  lifetimeConstraint: Object.freeze({
724
727
  nonce
@@ -743,22 +746,22 @@ function isAddressOnlyFeePayer(feePayer) {
743
746
  }
744
747
 
745
748
  // src/instructions.ts
746
- function appendTransactionMessageInstruction(instruction, transaction) {
747
- return appendTransactionMessageInstructions([instruction], transaction);
749
+ function appendTransactionMessageInstruction(instruction, transactionMessage) {
750
+ return appendTransactionMessageInstructions([instruction], transactionMessage);
748
751
  }
749
- function appendTransactionMessageInstructions(instructions, transaction) {
752
+ function appendTransactionMessageInstructions(instructions, transactionMessage) {
750
753
  return Object.freeze({
751
- ...transaction,
752
- instructions: Object.freeze([...transaction.instructions, ...instructions])
754
+ ...transactionMessage,
755
+ instructions: Object.freeze([...transactionMessage.instructions, ...instructions])
753
756
  });
754
757
  }
755
- function prependTransactionMessageInstruction(instruction, transaction) {
756
- return prependTransactionMessageInstructions([instruction], transaction);
758
+ function prependTransactionMessageInstruction(instruction, transactionMessage) {
759
+ return prependTransactionMessageInstructions([instruction], transactionMessage);
757
760
  }
758
- function prependTransactionMessageInstructions(instructions, transaction) {
761
+ function prependTransactionMessageInstructions(instructions, transactionMessage) {
759
762
  return Object.freeze({
760
- ...transaction,
761
- instructions: Object.freeze([...instructions, ...transaction.instructions])
763
+ ...transactionMessage,
764
+ instructions: Object.freeze([...instructions, ...transactionMessage.instructions])
762
765
  });
763
766
  }
764
767
 
@@ -895,11 +898,11 @@ function decompileTransactionMessage(compiledTransactionMessage, config) {
895
898
  );
896
899
  return pipe(
897
900
  createTransactionMessage({ version: compiledTransactionMessage.version }),
898
- (tx) => setTransactionMessageFeePayer(feePayer, tx),
899
- (tx) => instructions.reduce((acc, instruction) => {
901
+ (m) => setTransactionMessageFeePayer(feePayer, m),
902
+ (m) => instructions.reduce((acc, instruction) => {
900
903
  return appendTransactionMessageInstruction(instruction, acc);
901
- }, tx),
902
- (tx) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, tx)
904
+ }, m),
905
+ (m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
903
906
  );
904
907
  }
905
908