Skip to content

Commit 335a322

Browse files
committed
refactor: rename LedgerTransactionExpanded to LedgerTransactionExpandedV2
Make both API version types explicitly versioned for clarity: - LedgerTransactionExpandedV2 (APIv2 flat format) - LedgerTransactionExpandedV1 (APIv1 wrapped format)
1 parent 76ce3d9 commit 335a322

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

packages/xrpl/src/models/ledger/Ledger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface BaseLedger {
6161
* Transactions are returned as flat objects with the transaction fields
6262
* directly on the object, plus `hash` and `metaData`.
6363
*/
64-
export type LedgerTransactionExpanded = Transaction & {
64+
export type LedgerTransactionExpandedV2 = Transaction & {
6565
hash: string
6666
metaData?: TransactionMetadata
6767
}
@@ -96,7 +96,7 @@ export interface Ledger extends BaseLedger {
9696
* full representations of the transactions as flat objects with the
9797
* transaction fields directly on the object, plus `hash` and `metaData`.
9898
*/
99-
transactions?: Array<string | LedgerTransactionExpanded>
99+
transactions?: Array<string | LedgerTransactionExpandedV2>
100100
}
101101

102102
/**

packages/xrpl/src/models/ledger/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import FeeSettings, {
2020
import {
2121
Ledger,
2222
LedgerV1,
23-
LedgerTransactionExpanded,
23+
LedgerTransactionExpandedV2,
2424
LedgerTransactionExpandedV1,
2525
} from './Ledger'
2626
import { LedgerEntry, LedgerEntryFilter } from './LedgerEntry'
@@ -63,7 +63,7 @@ export {
6363
FeeSettingsPostAmendmentFields,
6464
Ledger,
6565
LedgerV1,
66-
LedgerTransactionExpanded,
66+
LedgerTransactionExpandedV2,
6767
LedgerTransactionExpandedV1,
6868
LedgerEntryFilter,
6969
LedgerEntry,

packages/xrpl/src/utils/hashes/hashLedger.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { APIVersion } from '../../models'
1212
import { LedgerEntry } from '../../models/ledger'
1313
import {
1414
LedgerVersionMap,
15-
LedgerTransactionExpanded,
15+
LedgerTransactionExpandedV2,
1616
LedgerTransactionExpandedV1,
1717
} from '../../models/ledger/Ledger'
1818
import { Transaction } from '../../models/transactions'
@@ -134,7 +134,7 @@ export function hashLedgerHeader(
134134
* @returns The root hash of the SHAMap.
135135
* @category Utilities
136136
*/
137-
export function hashTxTree(transactions: LedgerTransactionExpanded[]): string {
137+
export function hashTxTree(transactions: LedgerTransactionExpandedV2[]): string {
138138
const shamap = new SHAMap()
139139
for (const txJSON of transactions) {
140140
const txBlobHex = encode(txJSON)
@@ -172,8 +172,8 @@ export function hashStateTree(entries: LedgerEntry[]): string {
172172
* @returns The normalized v2 transaction.
173173
*/
174174
function normalizeToV2(
175-
tx: LedgerTransactionExpanded | LedgerTransactionExpandedV1,
176-
): LedgerTransactionExpanded {
175+
tx: LedgerTransactionExpandedV2 | LedgerTransactionExpandedV1,
176+
): LedgerTransactionExpandedV2 {
177177
if ('tx_json' in tx) {
178178
// Transaction union type cannot be spread directly (TS2698), so we
179179
// widen to a plain record first.
@@ -184,7 +184,7 @@ function normalizeToV2(
184184
...txJson,
185185
hash: tx.hash,
186186
metaData: tx.meta,
187-
} as LedgerTransactionExpanded
187+
} as LedgerTransactionExpandedV2
188188
}
189189
return tx
190190
}
@@ -206,11 +206,11 @@ function computeTransactionHash(
206206
// Normalize transactions to the v2 flat format expected by hashTxTree.
207207
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- ledger is a version union
208208
const txs = ledger.transactions as Array<
209-
string | LedgerTransactionExpanded | LedgerTransactionExpandedV1
209+
string | LedgerTransactionExpandedV2 | LedgerTransactionExpandedV1
210210
>
211211
const normalizedTransactions = txs
212212
.filter(
213-
(tx): tx is LedgerTransactionExpanded | LedgerTransactionExpandedV1 =>
213+
(tx): tx is LedgerTransactionExpandedV2 | LedgerTransactionExpandedV1 =>
214214
typeof tx !== 'string',
215215
)
216216
.map(normalizeToV2)

packages/xrpl/test/models/LedgerTransactionExpanded.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { assert } from 'chai'
33
import {
44
Ledger,
55
LedgerV1,
6-
LedgerTransactionExpanded,
6+
LedgerTransactionExpandedV2,
77
LedgerTransactionExpandedV1,
88
} from '../../src/models/ledger/Ledger'
99

10-
describe('LedgerTransactionExpanded types', function () {
10+
describe('LedgerTransactionExpandedV2 types', function () {
1111
it('Ledger (v2) transactions use flat format with metaData', function () {
12-
const tx: LedgerTransactionExpanded = {
12+
const tx: LedgerTransactionExpandedV2 = {
1313
Account: 'rPrioTXJgZJF8bpdXq2X73PcVPfvYqjVKd',
1414
Amount: '1000000',
1515
Destination: 'rsRy14FvipgqudiGmptJBhr1RtpsgfzKMM',

0 commit comments

Comments
 (0)