@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 +7 -7
- package/dist/index.browser.cjs +44 -41
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +44 -41
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +44 -41
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +44 -41
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +44 -41
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/blockhash.d.ts +4 -4
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compile/message.d.ts +2 -2
- package/dist/types/compile/message.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/instructions.d.ts +4 -4
- package/dist/types/instructions.d.ts.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -24,11 +24,11 @@ import {
|
|
|
24
24
|
setTransactionMessageLifetimeUsingBlockhash,
|
|
25
25
|
} from '@solana/transaction-messages';
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const transferTransactionMessage = pipe(
|
|
28
28
|
createTransactionMessage({ version: 0 }),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
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
|
|
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
|
}
|
package/dist/index.browser.cjs
CHANGED
|
@@ -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(
|
|
14
|
-
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in
|
|
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(
|
|
17
|
+
rpcTypes.assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
|
|
18
18
|
return true;
|
|
19
19
|
} catch {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
function assertIsTransactionMessageWithBlockhashLifetime(
|
|
24
|
-
if (!isTransactionMessageWithBlockhashLifetime(
|
|
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,
|
|
29
|
-
if ("lifetimeConstraint" in
|
|
30
|
-
return
|
|
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
|
-
...
|
|
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(
|
|
590
|
-
const addressMap = getAddressMapFromInstructions(
|
|
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
|
-
...
|
|
596
|
+
...transactionMessage.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
594
597
|
header: getCompiledMessageHeader(orderedAccounts),
|
|
595
|
-
instructions: getCompiledInstructions(
|
|
596
|
-
lifetimeToken: getCompiledLifetimeToken(
|
|
598
|
+
instructions: getCompiledInstructions(transactionMessage.instructions, orderedAccounts),
|
|
599
|
+
lifetimeToken: getCompiledLifetimeToken(transactionMessage.lifetimeConstraint),
|
|
597
600
|
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
598
|
-
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(
|
|
661
|
-
if (!isDurableNonceTransaction(
|
|
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(
|
|
691
|
-
return "lifetimeConstraint" in
|
|
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
|
-
},
|
|
703
|
+
}, transactionMessage) {
|
|
701
704
|
let newInstructions;
|
|
702
|
-
const firstInstruction =
|
|
705
|
+
const firstInstruction = transactionMessage.instructions[0];
|
|
703
706
|
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
704
707
|
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
705
|
-
if (isDurableNonceTransaction(
|
|
706
|
-
return
|
|
708
|
+
if (isDurableNonceTransaction(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
|
|
709
|
+
return transactionMessage;
|
|
707
710
|
} else {
|
|
708
|
-
newInstructions = [firstInstruction, ...
|
|
711
|
+
newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
|
|
709
712
|
}
|
|
710
713
|
} else {
|
|
711
714
|
newInstructions = [
|
|
712
715
|
Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
|
|
713
|
-
...
|
|
716
|
+
...transactionMessage.instructions.slice(1)
|
|
714
717
|
];
|
|
715
718
|
}
|
|
716
719
|
} else {
|
|
717
720
|
newInstructions = [
|
|
718
721
|
Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
|
|
719
|
-
...
|
|
722
|
+
...transactionMessage.instructions
|
|
720
723
|
];
|
|
721
724
|
}
|
|
722
725
|
return Object.freeze({
|
|
723
|
-
...
|
|
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,
|
|
749
|
-
return appendTransactionMessageInstructions([instruction],
|
|
751
|
+
function appendTransactionMessageInstruction(instruction, transactionMessage) {
|
|
752
|
+
return appendTransactionMessageInstructions([instruction], transactionMessage);
|
|
750
753
|
}
|
|
751
|
-
function appendTransactionMessageInstructions(instructions,
|
|
754
|
+
function appendTransactionMessageInstructions(instructions, transactionMessage) {
|
|
752
755
|
return Object.freeze({
|
|
753
|
-
...
|
|
754
|
-
instructions: Object.freeze([...
|
|
756
|
+
...transactionMessage,
|
|
757
|
+
instructions: Object.freeze([...transactionMessage.instructions, ...instructions])
|
|
755
758
|
});
|
|
756
759
|
}
|
|
757
|
-
function prependTransactionMessageInstruction(instruction,
|
|
758
|
-
return prependTransactionMessageInstructions([instruction],
|
|
760
|
+
function prependTransactionMessageInstruction(instruction, transactionMessage) {
|
|
761
|
+
return prependTransactionMessageInstructions([instruction], transactionMessage);
|
|
759
762
|
}
|
|
760
|
-
function prependTransactionMessageInstructions(instructions,
|
|
763
|
+
function prependTransactionMessageInstructions(instructions, transactionMessage) {
|
|
761
764
|
return Object.freeze({
|
|
762
|
-
...
|
|
763
|
-
instructions: Object.freeze([...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
|
-
(
|
|
901
|
-
(
|
|
903
|
+
(m) => setTransactionMessageFeePayer(feePayer, m),
|
|
904
|
+
(m) => instructions.reduce((acc, instruction) => {
|
|
902
905
|
return appendTransactionMessageInstruction(instruction, acc);
|
|
903
|
-
},
|
|
904
|
-
(
|
|
906
|
+
}, m),
|
|
907
|
+
(m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
|
|
905
908
|
);
|
|
906
909
|
}
|
|
907
910
|
|