@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.
package/README.md CHANGED
@@ -24,11 +24,11 @@ import {
24
24
  setTransactionMessageLifetimeUsingBlockhash,
25
25
  } from '@solana/transaction-messages';
26
26
 
27
- const transferTransaction = pipe(
27
+ const transferTransactionMessage = pipe(
28
28
  createTransactionMessage({ version: 0 }),
29
- tx => setTransactionMessageFeePayer(myAddress, tx),
30
- tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
31
- tx => appendTransactionMessageInstruction(getTransferSolInstruction({ source, destination, amount }), tx),
29
+ m => setTransactionMessageFeePayer(myAddress, m),
30
+ m => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
31
+ m => appendTransactionMessageInstruction(getTransferSolInstruction({ source, destination, amount }), m),
32
32
  );
33
33
  ```
34
34
 
@@ -49,7 +49,7 @@ Given a `TransactionVersion` this method will return an empty transaction having
49
49
  ```ts
50
50
  import { createTransactionMessage } from '@solana/transaction-messages';
51
51
 
52
- const tx = createTransactionMessage({ version: 0 });
52
+ const message = createTransactionMessage({ version: 0 });
53
53
  ```
54
54
 
55
55
  ## Setting the fee payer
@@ -111,7 +111,7 @@ Given a blockhash and the last block height at which that blockhash is considere
111
111
  import { setTransactionMessageLifetimeUsingBlockhash } from '@solana/transaction-messages';
112
112
 
113
113
  const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
114
- const txWithBlockhashLifetime = setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx);
114
+ const txMessageWithBlockhashLifetime = setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, txMessage);
115
115
  ```
116
116
 
117
117
  #### `setTransactionMessageLifetimeUsingDurableNonce()`
@@ -164,7 +164,7 @@ function handleSubmit() {
164
164
  // Typescript will upcast `blockhash` to `Blockhash`.
165
165
  assertIsBlockhash(blockhash);
166
166
  // At this point, `blockhash` is a `Blockhash` that can be used with the RPC.
167
- const blockhashIsValid = await rpc.isBlockhashValid(blockhash).send();
167
+ const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();
168
168
  } catch (e) {
169
169
  // `blockhash` turned out not to be a base58-encoded blockhash
170
170
  }
@@ -10,27 +10,27 @@ var instructions = require('@solana/instructions');
10
10
  var functional = require('@solana/functional');
11
11
 
12
12
  // src/blockhash.ts
13
- function isTransactionMessageWithBlockhashLifetime(transaction) {
14
- const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
13
+ function isTransactionMessageWithBlockhashLifetime(transactionMessage) {
14
+ const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint";
15
15
  if (!lifetimeConstraintShapeMatches) return false;
16
16
  try {
17
- rpcTypes.assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
17
+ rpcTypes.assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
18
18
  return true;
19
19
  } catch {
20
20
  return false;
21
21
  }
22
22
  }
23
- function assertIsTransactionMessageWithBlockhashLifetime(transaction) {
24
- if (!isTransactionMessageWithBlockhashLifetime(transaction)) {
23
+ function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
24
+ if (!isTransactionMessageWithBlockhashLifetime(transactionMessage)) {
25
25
  throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME);
26
26
  }
27
27
  }
28
- function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
29
- if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
30
- return transaction;
28
+ function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transactionMessage) {
29
+ if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
30
+ return transactionMessage;
31
31
  }
32
32
  const out = {
33
- ...transaction,
33
+ ...transactionMessage,
34
34
  lifetimeConstraint: Object.freeze(blockhashLifetimeConstraint)
35
35
  };
36
36
  Object.freeze(out);
@@ -586,16 +586,19 @@ function getCompiledStaticAccounts(orderedAccounts) {
586
586
  }
587
587
 
588
588
  // src/compile/message.ts
589
- function compileTransactionMessage(transaction) {
590
- const addressMap = getAddressMapFromInstructions(transaction.feePayer.address, transaction.instructions);
589
+ function compileTransactionMessage(transactionMessage) {
590
+ const addressMap = getAddressMapFromInstructions(
591
+ transactionMessage.feePayer.address,
592
+ transactionMessage.instructions
593
+ );
591
594
  const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
592
595
  return {
593
- ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
596
+ ...transactionMessage.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
594
597
  header: getCompiledMessageHeader(orderedAccounts),
595
- instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
596
- lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
598
+ instructions: getCompiledInstructions(transactionMessage.instructions, orderedAccounts),
599
+ lifetimeToken: getCompiledLifetimeToken(transactionMessage.lifetimeConstraint),
597
600
  staticAccounts: getCompiledStaticAccounts(orderedAccounts),
598
- version: transaction.version
601
+ version: transactionMessage.version
599
602
  };
600
603
  }
601
604
  function findAddressInLookupTables(address, role, addressesByLookupTableAddress) {
@@ -657,8 +660,8 @@ function createTransactionMessage({
657
660
  }
658
661
  var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
659
662
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
660
- function assertIsDurableNonceTransactionMessage(transaction) {
661
- if (!isDurableNonceTransaction(transaction)) {
663
+ function assertIsDurableNonceTransactionMessage(transactionMessage) {
664
+ if (!isDurableNonceTransaction(transactionMessage)) {
662
665
  throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
663
666
  }
664
667
  }
@@ -687,8 +690,8 @@ function isAdvanceNonceAccountInstruction(instruction) {
687
690
  function isAdvanceNonceAccountInstructionData(data) {
688
691
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
689
692
  }
690
- function isDurableNonceTransaction(transaction) {
691
- return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
693
+ function isDurableNonceTransaction(transactionMessage) {
694
+ return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.nonce === "string" && transactionMessage.instructions[0] != null && isAdvanceNonceAccountInstruction(transactionMessage.instructions[0]);
692
695
  }
693
696
  function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
694
697
  return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
@@ -697,30 +700,30 @@ function setTransactionMessageLifetimeUsingDurableNonce({
697
700
  nonce,
698
701
  nonceAccountAddress,
699
702
  nonceAuthorityAddress
700
- }, transaction) {
703
+ }, transactionMessage) {
701
704
  let newInstructions;
702
- const firstInstruction = transaction.instructions[0];
705
+ const firstInstruction = transactionMessage.instructions[0];
703
706
  if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
704
707
  if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
705
- if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
706
- return transaction;
708
+ if (isDurableNonceTransaction(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
709
+ return transactionMessage;
707
710
  } else {
708
- newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
711
+ newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
709
712
  }
710
713
  } else {
711
714
  newInstructions = [
712
715
  Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
713
- ...transaction.instructions.slice(1)
716
+ ...transactionMessage.instructions.slice(1)
714
717
  ];
715
718
  }
716
719
  } else {
717
720
  newInstructions = [
718
721
  Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
719
- ...transaction.instructions
722
+ ...transactionMessage.instructions
720
723
  ];
721
724
  }
722
725
  return Object.freeze({
723
- ...transaction,
726
+ ...transactionMessage,
724
727
  instructions: Object.freeze(newInstructions),
725
728
  lifetimeConstraint: Object.freeze({
726
729
  nonce
@@ -745,22 +748,22 @@ function isAddressOnlyFeePayer(feePayer) {
745
748
  }
746
749
 
747
750
  // src/instructions.ts
748
- function appendTransactionMessageInstruction(instruction, transaction) {
749
- return appendTransactionMessageInstructions([instruction], transaction);
751
+ function appendTransactionMessageInstruction(instruction, transactionMessage) {
752
+ return appendTransactionMessageInstructions([instruction], transactionMessage);
750
753
  }
751
- function appendTransactionMessageInstructions(instructions, transaction) {
754
+ function appendTransactionMessageInstructions(instructions, transactionMessage) {
752
755
  return Object.freeze({
753
- ...transaction,
754
- instructions: Object.freeze([...transaction.instructions, ...instructions])
756
+ ...transactionMessage,
757
+ instructions: Object.freeze([...transactionMessage.instructions, ...instructions])
755
758
  });
756
759
  }
757
- function prependTransactionMessageInstruction(instruction, transaction) {
758
- return prependTransactionMessageInstructions([instruction], transaction);
760
+ function prependTransactionMessageInstruction(instruction, transactionMessage) {
761
+ return prependTransactionMessageInstructions([instruction], transactionMessage);
759
762
  }
760
- function prependTransactionMessageInstructions(instructions, transaction) {
763
+ function prependTransactionMessageInstructions(instructions, transactionMessage) {
761
764
  return Object.freeze({
762
- ...transaction,
763
- instructions: Object.freeze([...instructions, ...transaction.instructions])
765
+ ...transactionMessage,
766
+ instructions: Object.freeze([...instructions, ...transactionMessage.instructions])
764
767
  });
765
768
  }
766
769
 
@@ -897,11 +900,11 @@ function decompileTransactionMessage(compiledTransactionMessage, config) {
897
900
  );
898
901
  return functional.pipe(
899
902
  createTransactionMessage({ version: compiledTransactionMessage.version }),
900
- (tx) => setTransactionMessageFeePayer(feePayer, tx),
901
- (tx) => instructions.reduce((acc, instruction) => {
903
+ (m) => setTransactionMessageFeePayer(feePayer, m),
904
+ (m) => instructions.reduce((acc, instruction) => {
902
905
  return appendTransactionMessageInstruction(instruction, acc);
903
- }, tx),
904
- (tx) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, tx)
906
+ }, m),
907
+ (m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
905
908
  );
906
909
  }
907
910