From 3639521c1a106737ac0a54623e742c9d9078fb4c Mon Sep 17 00:00:00 2001 From: Callum Date: Fri, 30 Jan 2026 17:11:10 +0000 Subject: [PATCH] Refactor transaction-messages to use using BaseTransactionMessage --- .changeset/metal-rice-make.md | 5 ++ .../src/__tests__/fee-payer-test.ts | 8 +-- .../src/__tests__/instructions-test.ts | 4 +- .../src/__typetests__/fee-payer-typetest.ts | 10 +-- .../__typetests__/instructions-typetest.ts | 61 +++++++++---------- .../src/compile/__tests__/message-test.ts | 6 +- .../src/compile/message.ts | 10 +-- .../src/transaction-message-size.ts | 4 +- 8 files changed, 54 insertions(+), 54 deletions(-) create mode 100644 .changeset/metal-rice-make.md diff --git a/.changeset/metal-rice-make.md b/.changeset/metal-rice-make.md new file mode 100644 index 000000000..a01f766b0 --- /dev/null +++ b/.changeset/metal-rice-make.md @@ -0,0 +1,5 @@ +--- +'@solana/transaction-messages': patch +--- + +Refactor transaction-messages package to stop using BaseTransactionMessage diff --git a/packages/transaction-messages/src/__tests__/fee-payer-test.ts b/packages/transaction-messages/src/__tests__/fee-payer-test.ts index 039c722c7..685d3ebc9 100644 --- a/packages/transaction-messages/src/__tests__/fee-payer-test.ts +++ b/packages/transaction-messages/src/__tests__/fee-payer-test.ts @@ -3,7 +3,7 @@ import '@solana/test-matchers/toBeFrozenObject'; import { Address } from '@solana/addresses'; import { setTransactionMessageFeePayer, TransactionMessageWithFeePayer } from '../fee-payer'; -import { BaseTransactionMessage } from '../transaction-message'; +import { TransactionMessage } from '../transaction-message'; const EXAMPLE_FEE_PAYER_A = '7mvYAxeCui21xYkAyQSjh6iBVZPpgVyt7PYv9km8V5mE' as Address<'7mvYAxeCui21xYkAyQSjh6iBVZPpgVyt7PYv9km8V5mE'>; @@ -11,7 +11,7 @@ const EXAMPLE_FEE_PAYER_B = '5LHng8dLBxCYyR3jdDbobLiRQ6pR74pYtxKohY93RbZN' as Address<'5LHng8dLBxCYyR3jdDbobLiRQ6pR74pYtxKohY93RbZN'>; describe('setTransactionMessageFeePayer', () => { - let baseTx: BaseTransactionMessage; + let baseTx: TransactionMessage; beforeEach(() => { baseTx = { instructions: [], @@ -23,7 +23,7 @@ describe('setTransactionMessageFeePayer', () => { expect(txWithFeePayerA).toHaveProperty('feePayer', { address: EXAMPLE_FEE_PAYER_A }); }); describe('given a transaction with a fee payer already set', () => { - let txWithFeePayerA: BaseTransactionMessage & TransactionMessageWithFeePayer; + let txWithFeePayerA: TransactionMessage & TransactionMessageWithFeePayer; beforeEach(() => { txWithFeePayerA = { ...baseTx, @@ -40,7 +40,7 @@ describe('setTransactionMessageFeePayer', () => { }); }); describe('given a transaction with a fee payer with extra properties set', () => { - let txWithFeePayerA: BaseTransactionMessage & { + let txWithFeePayerA: TransactionMessage & { readonly feePayer: Readonly<{ address: Address; extra: 'extra' }>; }; beforeEach(() => { diff --git a/packages/transaction-messages/src/__tests__/instructions-test.ts b/packages/transaction-messages/src/__tests__/instructions-test.ts index 09db019ee..877981f94 100644 --- a/packages/transaction-messages/src/__tests__/instructions-test.ts +++ b/packages/transaction-messages/src/__tests__/instructions-test.ts @@ -9,7 +9,7 @@ import { prependTransactionMessageInstruction, prependTransactionMessageInstructions, } from '../instructions'; -import { BaseTransactionMessage } from '../transaction-message'; +import { TransactionMessage } from '../transaction-message'; const PROGRAM_A = 'AALQD2dt1k43Acrkp4SvdhZaN4S115Ff2Bi7rHPti3sL' as Address<'AALQD2dt1k43Acrkp4SvdhZaN4S115Ff2Bi7rHPti3sL'>; @@ -19,7 +19,7 @@ const PROGRAM_C = '6Bkt4j67rxzFF6s9DaMRyfitftRrGxe4oYHPRHuFChzi' as Address<'6Bkt4j67rxzFF6s9DaMRyfitftRrGxe4oYHPRHuFChzi'>; describe('Transaction instruction helpers', () => { - let baseTx: BaseTransactionMessage; + let baseTx: TransactionMessage; let exampleInstruction: Instruction; let secondExampleInstruction: Instruction; beforeEach(() => { diff --git a/packages/transaction-messages/src/__typetests__/fee-payer-typetest.ts b/packages/transaction-messages/src/__typetests__/fee-payer-typetest.ts index d10f0f9cc..bec57ef16 100644 --- a/packages/transaction-messages/src/__typetests__/fee-payer-typetest.ts +++ b/packages/transaction-messages/src/__typetests__/fee-payer-typetest.ts @@ -3,7 +3,7 @@ import { Address } from '@solana/addresses'; import { TransactionMessageWithBlockhashLifetime } from '../blockhash'; import { TransactionMessageWithDurableNonceLifetime } from '../durable-nonce'; import { setTransactionMessageFeePayer, TransactionMessageWithFeePayer } from '../fee-payer'; -import { BaseTransactionMessage, TransactionMessage } from '../transaction-message'; +import { TransactionMessage } from '../transaction-message'; const mockFeePayer = 'mock' as Address<'mockFeePayer'>; const aliceAddress = 'alice' as Address<'alice'>; @@ -16,17 +16,17 @@ type V0TransactionMessage = Extract; { // It adds the fee payer to the new message { - const message = null as unknown as BaseTransactionMessage & { some: 1 }; + const message = null as unknown as TransactionMessage & { some: 1 }; const messageWithFeePayer = setTransactionMessageFeePayer(aliceAddress, message); - messageWithFeePayer satisfies BaseTransactionMessage & TransactionMessageWithFeePayer<'alice'> & { some: 1 }; + messageWithFeePayer satisfies TransactionMessage & TransactionMessageWithFeePayer<'alice'> & { some: 1 }; } // It *replaces* an existing fee payer with the new one { - const messageWithAliceFeePayer = null as unknown as BaseTransactionMessage & + const messageWithAliceFeePayer = null as unknown as TransactionMessage & TransactionMessageWithFeePayer<'alice'> & { some: 1 }; const messageWithBobFeePayer = setTransactionMessageFeePayer(bobAddress, messageWithAliceFeePayer); - messageWithBobFeePayer satisfies BaseTransactionMessage & TransactionMessageWithFeePayer<'bob'> & { some: 1 }; + messageWithBobFeePayer satisfies TransactionMessage & TransactionMessageWithFeePayer<'bob'> & { some: 1 }; // @ts-expect-error Alice should no longer be a payer. messageWithBobFeePayer satisfies TransactionMessageWithFeePayer<'alice'>; } diff --git a/packages/transaction-messages/src/__typetests__/instructions-typetest.ts b/packages/transaction-messages/src/__typetests__/instructions-typetest.ts index e349512fa..dbe8b179d 100644 --- a/packages/transaction-messages/src/__typetests__/instructions-typetest.ts +++ b/packages/transaction-messages/src/__typetests__/instructions-typetest.ts @@ -15,10 +15,10 @@ import { prependTransactionMessageInstruction, prependTransactionMessageInstructions, } from '../instructions'; -import { BaseTransactionMessage, TransactionMessage } from '../transaction-message'; +import { TransactionMessage } from '../transaction-message'; import { TransactionMessageWithinSizeLimit } from '../transaction-message-size'; -type Instruction = BaseTransactionMessage['instructions'][number]; +type Instruction = TransactionMessage['instructions'][number]; type InstructionA = Instruction & { identifier: 'A' }; type InstructionB = Instruction & { identifier: 'B' }; type InstructionC = Instruction & { identifier: 'C' }; @@ -29,9 +29,9 @@ type TransactionMessageNotLegacy = Exclude appendTransactionMessageInstruction(null as unknown as InstructionA, m), ); - message satisfies BaseTransactionMessage & - TransactionMessageWithBlockhashLifetime & - TransactionMessageWithFeePayer; + message satisfies TransactionMessage & TransactionMessageWithBlockhashLifetime & TransactionMessageWithFeePayer; message.instructions satisfies readonly [InstructionA]; } @@ -80,7 +78,7 @@ type TransactionMessageNotLegacy = Exclude appendTransactionMessageInstruction(null as unknown as InstructionA, m), ); - message satisfies BaseTransactionMessage & + message satisfies TransactionMessage & TransactionMessageWithDurableNonceLifetime & TransactionMessageWithFeePayer; message.instructions satisfies readonly [AdvanceNonceAccountInstruction, InstructionA]; @@ -88,7 +86,7 @@ type TransactionMessageNotLegacy = Exclude prependTransactionMessageInstruction(null as unknown as InstructionA, m), ); - message satisfies BaseTransactionMessage & - TransactionMessageWithBlockhashLifetime & - TransactionMessageWithFeePayer; + message satisfies TransactionMessage & TransactionMessageWithBlockhashLifetime & TransactionMessageWithFeePayer; message.instructions satisfies readonly [InstructionA]; } @@ -233,14 +228,14 @@ type TransactionMessageNotLegacy = Exclude { - let baseTx: BaseTransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithLifetime; + let baseTx: TransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithLifetime; beforeEach(() => { baseTx = { feePayer: { address: 'abc' as Address<'abc'> }, @@ -50,7 +50,7 @@ describe('compileTransactionMessage', () => { }); }); it('sets `addressTableLookups` to the return value of `getCompiledAddressTableLookups`', () => { - const message = compileTransactionMessage(baseTx); + const message = compileTransactionMessage(baseTx as typeof baseTx & { version: 0 }); expect(getCompiledAddressTableLookups).toHaveBeenCalled(); expect(message.addressTableLookups).toBe(expectedAddressTableLookups); }); diff --git a/packages/transaction-messages/src/compile/message.ts b/packages/transaction-messages/src/compile/message.ts index e3a3fdda9..9b67bc4c5 100644 --- a/packages/transaction-messages/src/compile/message.ts +++ b/packages/transaction-messages/src/compile/message.ts @@ -1,6 +1,6 @@ import { TransactionMessageWithFeePayer } from '../fee-payer'; import { TransactionMessageWithLifetime } from '../lifetime'; -import { BaseTransactionMessage } from '../transaction-message'; +import { TransactionMessage } from '../transaction-message'; import { getAddressMapFromInstructions, getOrderedAccountsFromAddressMap } from './accounts'; import { getCompiledAddressTableLookups } from './address-table-lookups'; import { getCompiledMessageHeader } from './header'; @@ -63,7 +63,7 @@ type VersionedCompiledTransactionMessage = BaseCompiledTransactionMessage & * @see {@link decompileTransactionMessage} */ export function compileTransactionMessage< - TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer, + TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer, >(transactionMessage: TTransactionMessage): CompiledTransactionMessageFromTransactionMessage { type ReturnType = CompiledTransactionMessageFromTransactionMessage; @@ -86,17 +86,17 @@ export function compileTransactionMessage< } as ReturnType; } -type CompiledTransactionMessageFromTransactionMessage = +type CompiledTransactionMessageFromTransactionMessage = ForwardTransactionMessageLifetime, TTransactionMessage>; -type ForwardTransactionMessageVersion = +type ForwardTransactionMessageVersion = TTransactionMessage extends Readonly<{ version: 'legacy' }> ? LegacyCompiledTransactionMessage : VersionedCompiledTransactionMessage; type ForwardTransactionMessageLifetime< TCompiledTransactionMessage extends CompiledTransactionMessage, - TTransactionMessage extends BaseTransactionMessage, + TTransactionMessage extends TransactionMessage, > = TTransactionMessage extends TransactionMessageWithLifetime ? CompiledTransactionMessageWithLifetime & TCompiledTransactionMessage : TCompiledTransactionMessage; diff --git a/packages/transaction-messages/src/transaction-message-size.ts b/packages/transaction-messages/src/transaction-message-size.ts index 61eccc856..b63fbbfaa 100644 --- a/packages/transaction-messages/src/transaction-message-size.ts +++ b/packages/transaction-messages/src/transaction-message-size.ts @@ -1,6 +1,6 @@ import type { NominalType } from '@solana/nominal-types'; -import type { BaseTransactionMessage } from './transaction-message'; +import type { TransactionMessage } from './transaction-message'; /** * A type guard that checks if a transaction message is within the size limit @@ -12,7 +12,7 @@ export type TransactionMessageWithinSizeLimit = NominalType<'transactionSize', ' * Helper type that removes the `TransactionMessageWithinSizeLimit` flag * from a transaction message. */ -export type ExcludeTransactionMessageWithinSizeLimit = Omit< +export type ExcludeTransactionMessageWithinSizeLimit = Omit< TTransactionMessage, '__transactionSize:@solana/kit' >;