Skip to content

feat: Enhance parseTransactionFlags with string overload and includeAll option (#1903)#3224

Open
slurpyone wants to merge 2 commits intoXRPLF:mainfrom
slurpyone:feat/parse-transaction-flags
Open

feat: Enhance parseTransactionFlags with string overload and includeAll option (#1903)#3224
slurpyone wants to merge 2 commits intoXRPLF:mainfrom
slurpyone:feat/parse-transaction-flags

Conversation

@slurpyone
Copy link
Copy Markdown

Summary

Enhances the existing parseTransactionFlags utility to address the usability gaps described in #1903.

Changes

  1. String overload: Accept (txType: string, flags: number) directly, so users working with raw API responses can parse flags without constructing a full Transaction object:
import { parseTransactionFlags } from 'xrpl'

// Parse flags from a raw API response
parseTransactionFlags('OfferCreate', 2148007936)
// => { tfSell: true, tfFullyCanonicalSig: true }
  1. includeAll option: Optionally include all possible flags for a transaction type (with false for disabled ones):
parseTransactionFlags('Payment', 0x00020000, { includeAll: true })
// => { tfNoRippleDirect: false, tfPartialPayment: true, tfLimitQuality: false, tfInnerBatchTxn: false }
  1. Improved typing: Return type changed from object to Record<string, boolean>.

  2. Missing flag mappings: Added EnableAmendment and LoanSet to the txToFlag map.

Backward Compatibility

Fully backward compatible — the existing parseTransactionFlags(tx: Transaction) signature continues to work identically.

Tests

Added 7 new test cases covering:

  • String overload with single and combined flags
  • Zero flags edge case
  • includeAll option with both string and Transaction overloads
  • Unknown transaction types (global flags only)
  • String overload with global flags

All existing tests continue to pass.

Closes #1903

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 7, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

parseTransactionFlags now accepts either a Transaction object or a (txType, flagsNum) pair, adds an optional includeAll option to include disabled flags, registers EnableAmendmentFlags and LoanSetFlags in the txToFlag mapping, and always returns a Record<string, boolean> map including global flags.

Changes

Cohort / File(s) Summary
Transaction flags parsing utility
packages/xrpl/src/models/utils/flags.ts
Added exported ParseTransactionFlagsOptions (includeAll?: boolean); overloaded parseTransactionFlags to accept (tx: Transaction, options?) or (txType: string, flagsNum: number, options?); unified implementation derives transactionType and numeric flags from either form, includes transaction-specific and global flags, includes disabled flags when includeAll is true, and added EnableAmendmentFlags and LoanSetFlags to txToFlag. Return type changed to Record<string, boolean>.
Test coverage expansion
packages/xrpl/test/models/utils.test.ts
Added tests for parsing from transaction-type string + numeric flags (single, combined, zero), includeAll behavior for both string and Transaction inputs, and cases involving unknown transaction types and global flags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ckeshava
  • khancode
  • mvadari

Poem

🐰 I hop through flags both old and new,
Numbers whisper names I always knew.
Type or tx — I count each bit,
includeAll invites the quietest fit.
A nimble hop, and clarity grew.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main enhancement: adding a string overload and includeAll option to parseTransactionFlags.
Description check ✅ Passed The PR description follows the template with clear summary, context, changes, backward compatibility statement, and test coverage details.
Linked Issues check ✅ Passed The PR fully addresses objectives from #1903: implements parseTransactionFlags to convert flags to boolean maps, adds string overload for raw API responses, and provides includeAll option for flexibility.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #1903 requirements: string overload implementation, includeAll option, typing improvements, missing flag mappings, and comprehensive test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/xrpl/test/models/utils.test.ts (1)

397-471: Add one regression case per new txToFlag entry.

These cases cover the new overload mechanics, but none of them prove the new EnableAmendment and LoanSet mappings work. Dropping either key from packages/xrpl/src/models/utils/flags.ts would still leave this suite green.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/xrpl/test/models/utils.test.ts` around lines 397 - 471, Add explicit
regression tests that exercise the new txToFlag mappings for the EnableAmendment
and LoanSet entries: call parseTransactionFlags using the transaction type
string (e.g., 'EnableAmendment' and 'LoanSet') with relevant numeric flags (and
with includeAll true where appropriate) and assert the resulting flagsMap
contains the expected mapped keys; ensure each new txToFlag entry has at least
one test that would fail if its mapping in txToFlag were removed or incorrect so
the suite actually verifies the new overload mechanics (reference
parseTransactionFlags and txToFlag, and the specific keys EnableAmendment and
LoanSet).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/xrpl/src/models/utils/flags.ts`:
- Around line 170-179: The public signature parseTransactionFlags currently uses
a union that allows invalid call shapes (e.g., parseTransactionFlags(tx, 123))
and forces callers to pass undefined for options; replace it with two TypeScript
overloads matching the docblock: one overload parseTransactionFlags(tx:
Transaction, options?: { includeAll?: boolean }) and a second overload
parseTransactionFlags(txType: string, flagsNum: number, options?: { includeAll?:
boolean }), then keep a single implementation signature (e.g.,
parseTransactionFlags(txOrType: Transaction | string, flagsNumOrOptions?: number
| { includeAll?: boolean }, maybeOptions?: { includeAll?: boolean })) and adapt
the body to detect whether the second argument is a number or options and to
require flagsNum when txOrType is a string; ensure the JSDoc and exported types
(if you introduce ParseTransactionFlagsOptions) are updated accordingly.

---

Nitpick comments:
In `@packages/xrpl/test/models/utils.test.ts`:
- Around line 397-471: Add explicit regression tests that exercise the new
txToFlag mappings for the EnableAmendment and LoanSet entries: call
parseTransactionFlags using the transaction type string (e.g., 'EnableAmendment'
and 'LoanSet') with relevant numeric flags (and with includeAll true where
appropriate) and assert the resulting flagsMap contains the expected mapped
keys; ensure each new txToFlag entry has at least one test that would fail if
its mapping in txToFlag were removed or incorrect so the suite actually verifies
the new overload mechanics (reference parseTransactionFlags and txToFlag, and
the specific keys EnableAmendment and LoanSet).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6f4049c1-9130-4018-a18a-976695add183

📥 Commits

Reviewing files that changed from the base of the PR and between 928be9a and 9012438.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/utils/flags.ts
  • packages/xrpl/test/models/utils.test.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/xrpl/src/models/utils/flags.ts`:
- Around line 173-175: The example for parseTransactionFlags showing includeAll:
true is inaccurate because includeAll merges transaction-specific flags with
global flags; update the example return value to include those global flags (the
same fix for the duplicate example at lines 228–235). Locate the
parseTransactionFlags usage in flags.ts and modify the example comment to show
the full returned object (transaction flags plus global flags names returned by
the code path that combines GLOBAL flags), or alternatively adjust the example
wording to state that global flags are included when includeAll is true.
- Around line 202-205: When txOrType is a string (the code path that sets
transactionType = txOrType), validate that flagsNumOrOptions is actually a
number before using it as flags: check typeof flagsNumOrOptions === 'number' and
assign flags = flagsNumOrOptions, otherwise throw a clear TypeError (or similar)
explaining the second argument must be a numeric flags bitmask; still assign
options = maybeOptions as before. Update the logic around transactionType,
flags, flagsNumOrOptions, and maybeOptions so callers get a deterministic
runtime error instead of silently getting 0/invalid flags.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 51909c26-0041-4b05-9536-8bd06f7e4e76

📥 Commits

Reviewing files that changed from the base of the PR and between 9012438 and 278fbfd.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/utils/flags.ts
  • packages/xrpl/test/models/utils.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/xrpl/test/models/utils.test.ts

Comment on lines +202 to +205
if (typeof txOrType === 'string') {
transactionType = txOrType
flags = (flagsNumOrOptions as number) ?? 0
options = maybeOptions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Validate flagsNum at runtime for string-based calls.

When txOrType is a string, Line 204 currently accepts a missing or mis-typed second argument and falls through as 0/an invalid bit source. That makes JS callers and any-typed TS callers get an empty flag map instead of a contract error, which is hard to debug for the new overload.

Suggested fix
   if (typeof txOrType === 'string') {
     transactionType = txOrType
-    flags = (flagsNumOrOptions as number) ?? 0
+    if (typeof flagsNumOrOptions !== 'number') {
+      throw new ValidationError(
+        'flagsNum is required and must be a number when txOrType is a string.',
+      )
+    }
+    flags = flagsNumOrOptions
     options = maybeOptions
   } else {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (typeof txOrType === 'string') {
transactionType = txOrType
flags = (flagsNumOrOptions as number) ?? 0
options = maybeOptions
if (typeof txOrType === 'string') {
transactionType = txOrType
if (typeof flagsNumOrOptions !== 'number') {
throw new ValidationError(
'flagsNum is required and must be a number when txOrType is a string.',
)
}
flags = flagsNumOrOptions
options = maybeOptions
} else {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/xrpl/src/models/utils/flags.ts` around lines 202 - 205, When
txOrType is a string (the code path that sets transactionType = txOrType),
validate that flagsNumOrOptions is actually a number before using it as flags:
check typeof flagsNumOrOptions === 'number' and assign flags =
flagsNumOrOptions, otherwise throw a clear TypeError (or similar) explaining the
second argument must be a numeric flags bitmask; still assign options =
maybeOptions as before. Update the logic around transactionType, flags,
flagsNumOrOptions, and maybeOptions so callers get a deterministic runtime error
instead of silently getting 0/invalid flags.

@slurpyone slurpyone force-pushed the feat/parse-transaction-flags branch from 278fbfd to 81adabe Compare March 14, 2026 12:41
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
packages/xrpl/src/models/utils/flags.ts (2)

173-175: ⚠️ Potential issue | 🟡 Minor

includeAll example is still missing global flags in the return shape.

When includeAll: true, implementation also includes global flags (for example tfInnerBatchTxn: false), so this example is currently misleading.

✏️ Suggested doc fix
- * // => { tfNoRippleDirect: false, tfPartialPayment: true, tfLimitQuality: false }
+ * // => { tfNoRippleDirect: false, tfPartialPayment: true, tfLimitQuality: false, tfInnerBatchTxn: false }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/xrpl/src/models/utils/flags.ts` around lines 173 - 175, The example
in parseTransactionFlags's docstring is misleading because when includeAll: true
the function also returns global flags (e.g., tfInnerBatchTxn), so update the
example and/or text in the comment near the parseTransactionFlags function to
show that global flags are included in the returned shape (for example include
tfInnerBatchTxn: false alongside
tfNoRippleDirect/tfPartialPayment/tfLimitQuality) or explicitly state that
global flags are present when includeAll is true.

202-205: ⚠️ Potential issue | 🟠 Major

Enforce numeric flagsNum for string-based calls at runtime.

This path currently defaults missing flagsNum to 0 and accepts mis-typed values, which violates the documented contract and can hide caller mistakes.

🛠️ Suggested fix
   if (typeof txOrType === 'string') {
     transactionType = txOrType
-    flags = (flagsNumOrOptions as number) ?? 0
+    if (typeof flagsNumOrOptions !== 'number' || Number.isNaN(flagsNumOrOptions)) {
+      throw new ValidationError(
+        'flagsNum is required and must be a number when txOrType is a string.',
+      )
+    }
+    flags = flagsNumOrOptions
     options = maybeOptions
   } else {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/xrpl/src/models/utils/flags.ts` around lines 202 - 205, When
txOrType is a string (the "string-based" overload), validate that
flagsNumOrOptions is a numeric flags value before assigning: instead of
defaulting to 0, test typeof flagsNumOrOptions === 'number' and if not throw a
TypeError (or similar) indicating a required numeric flagsNum; then set flags =
flagsNumOrOptions and options = maybeOptions. Update the branch that currently
sets transactionType = txOrType, flags = (flagsNumOrOptions as number) ?? 0,
options = maybeOptions to perform this runtime type-check and error on
missing/mistyped flagsNum to enforce the documented contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/xrpl/src/models/utils/flags.ts`:
- Around line 173-175: The example in parseTransactionFlags's docstring is
misleading because when includeAll: true the function also returns global flags
(e.g., tfInnerBatchTxn), so update the example and/or text in the comment near
the parseTransactionFlags function to show that global flags are included in the
returned shape (for example include tfInnerBatchTxn: false alongside
tfNoRippleDirect/tfPartialPayment/tfLimitQuality) or explicitly state that
global flags are present when includeAll is true.
- Around line 202-205: When txOrType is a string (the "string-based" overload),
validate that flagsNumOrOptions is a numeric flags value before assigning:
instead of defaulting to 0, test typeof flagsNumOrOptions === 'number' and if
not throw a TypeError (or similar) indicating a required numeric flagsNum; then
set flags = flagsNumOrOptions and options = maybeOptions. Update the branch that
currently sets transactionType = txOrType, flags = (flagsNumOrOptions as number)
?? 0, options = maybeOptions to perform this runtime type-check and error on
missing/mistyped flagsNum to enforce the documented contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7fba20b8-edf2-401f-bae5-af8b08de76c7

📥 Commits

Reviewing files that changed from the base of the PR and between 278fbfd and 81adabe.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/utils/flags.ts
  • packages/xrpl/test/models/utils.test.ts

@slurpyone slurpyone force-pushed the feat/parse-transaction-flags branch from 81adabe to bb8603d Compare March 17, 2026 00:41
@slurpyone slurpyone force-pushed the feat/parse-transaction-flags branch 5 times, most recently from b3da2f7 to f080931 Compare March 31, 2026 00:41
@slurpyone slurpyone force-pushed the feat/parse-transaction-flags branch 4 times, most recently from 86f3f3e to d01618d Compare April 8, 2026 00:41
@slurpyone slurpyone force-pushed the feat/parse-transaction-flags branch 3 times, most recently from 9c9f87a to 6d59daa Compare April 13, 2026 00:41
…ll option (XRPLF#1903)

- Add overload accepting (txType: string, flags: number) for parsing
  numeric flags directly from raw API responses without constructing
  a full Transaction object
- Add optional { includeAll: true } parameter to include all possible
  flags for a transaction type with their boolean values (not just
  enabled flags)
- Improve return type from object to Record<string, boolean>
- Add missing EnableAmendment and LoanSet to txToFlag mapping
- Add comprehensive tests for all new functionality
Address CodeRabbit review feedback: replace union signature with
proper overloads to prevent invalid call shapes.

- Add ParseTransactionFlagsOptions interface
- Overload 1: parseTransactionFlags(tx, options?) for Transaction objects
- Overload 2: parseTransactionFlags(txType, flagsNum, options?) for strings
- Update tests to use new overload-friendly calling convention
@slurpyone slurpyone force-pushed the feat/parse-transaction-flags branch from 6d59daa to cefea2a Compare April 13, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse transaction flags into map of names:booleans

1 participant