@@ -10,8 +10,10 @@ import { AMMDepositFlags } from '../transactions/AMMDeposit'
1010import { AMMWithdrawFlags } from '../transactions/AMMWithdraw'
1111import { BatchFlags } from '../transactions/batch'
1212import { GlobalFlags } from '../transactions/common'
13+ import { EnableAmendmentFlags } from '../transactions/enableAmendment'
1314import { LoanManageFlags } from '../transactions/loanManage'
1415import { LoanPayFlags } from '../transactions/loanPay'
16+ import { LoanSetFlags } from '../transactions/loanSet'
1517import { MPTokenAuthorizeFlags } from '../transactions/MPTokenAuthorize'
1618import { MPTokenIssuanceCreateFlags } from '../transactions/MPTokenIssuanceCreate'
1719import { MPTokenIssuanceSetFlags } from '../transactions/MPTokenIssuanceSet'
@@ -57,8 +59,10 @@ const txToFlag = {
5759 AMMDeposit : AMMDepositFlags ,
5860 AMMWithdraw : AMMWithdrawFlags ,
5961 Batch : BatchFlags ,
62+ EnableAmendment : EnableAmendmentFlags ,
6063 LoanManage : LoanManageFlags ,
6164 LoanPay : LoanPayFlags ,
65+ LoanSet : LoanSetFlags ,
6266 MPTokenAuthorize : MPTokenAuthorizeFlags ,
6367 MPTokenIssuanceCreate : MPTokenIssuanceCreateFlags ,
6468 MPTokenIssuanceSet : MPTokenIssuanceSetFlags ,
@@ -141,32 +145,72 @@ export function convertTxFlagsToNumber(tx: Transaction): number {
141145/**
142146 * Convert a Transaction flags property into a map for easy interpretation.
143147 *
144- * @param tx - A transaction to parse flags for.
145- * @returns A map with all flags as booleans.
148+ * Can be called with a Transaction object or with a transaction type string
149+ * and numeric flags value directly (useful when working with raw API responses).
150+ *
151+ * By default, only enabled (true) flags are included in the result.
152+ * Pass `includeAll: true` in options to include all possible flags for the
153+ * transaction type with their boolean values.
154+ *
155+ * @example
156+ * ```typescript
157+ * // With a Transaction object (existing behavior)
158+ * parseTransactionFlags(tx)
159+ * // => { tfSell: true }
160+ *
161+ * // With transaction type and numeric flags
162+ * parseTransactionFlags('OfferCreate', 0x00080000)
163+ * // => { tfSell: true }
164+ *
165+ * // Include all possible flags for the transaction type
166+ * parseTransactionFlags('Payment', 0x00020000, { includeAll: true })
167+ * // => { tfNoRippleDirect: false, tfPartialPayment: true, tfLimitQuality: false }
168+ * ```
169+ *
170+ * @param txOrType - A transaction to parse flags for, or a transaction type string.
171+ * @param flagsNum - The numeric flags value (required when txOrType is a string).
172+ * @param options - Optional settings.
173+ * @param options.includeAll - Set to `true` to include disabled flags.
174+ * @returns A map of flag names to booleans.
146175 */
147- export function parseTransactionFlags ( tx : Transaction ) : object {
148- const flags = convertTxFlagsToNumber ( tx )
149- if ( flags === 0 ) {
150- return { }
176+ export function parseTransactionFlags (
177+ txOrType : Transaction | string ,
178+ flagsNum ?: number ,
179+ options ?: { includeAll ?: boolean } ,
180+ ) : Record < string , boolean > {
181+ let flags : number
182+ let transactionType : string
183+
184+ if ( typeof txOrType === 'string' ) {
185+ transactionType = txOrType
186+ flags = flagsNum ?? 0
187+ } else {
188+ transactionType = txOrType . TransactionType
189+ flags = convertTxFlagsToNumber ( txOrType )
151190 }
152191
153- const booleanFlagMap = { }
192+ const includeAll = options ?. includeAll ?? false
154193
155- if ( isTxToFlagKey ( tx . TransactionType ) ) {
156- const transactionTypeFlags = txToFlag [ tx . TransactionType ]
194+ const booleanFlagMap : Record < string , boolean > = { }
195+
196+ if ( isTxToFlagKey ( transactionType ) ) {
197+ const transactionTypeFlags = txToFlag [ transactionType ]
157198 Object . values ( transactionTypeFlags ) . forEach ( ( flag ) => {
158- if (
159- typeof flag === 'string' &&
160- isFlagEnabled ( flags , transactionTypeFlags [ flag ] )
161- ) {
162- booleanFlagMap [ flag ] = true
199+ if ( typeof flag === 'string' ) {
200+ const enabled = isFlagEnabled ( flags , transactionTypeFlags [ flag ] )
201+ if ( enabled || includeAll ) {
202+ booleanFlagMap [ flag ] = enabled
203+ }
163204 }
164205 } )
165206 }
166207
167208 Object . values ( GlobalFlags ) . forEach ( ( flag ) => {
168- if ( typeof flag === 'string' && isFlagEnabled ( flags , GlobalFlags [ flag ] ) ) {
169- booleanFlagMap [ flag ] = true
209+ if ( typeof flag === 'string' ) {
210+ const enabled = isFlagEnabled ( flags , GlobalFlags [ flag ] )
211+ if ( enabled || includeAll ) {
212+ booleanFlagMap [ flag ] = enabled
213+ }
170214 }
171215 } )
172216
0 commit comments