Skip to content

feat(xrpl): add contains flag utility#197

Merged
GuillemGarciaDev merged 2 commits intoXRPLF:mainfrom
kpitapeersyst:xrpl/feat/contains-flag-util
Feb 25, 2026
Merged

feat(xrpl): add contains flag utility#197
GuillemGarciaDev merged 2 commits intoXRPLF:mainfrom
kpitapeersyst:xrpl/feat/contains-flag-util

Conversation

@kpitapeersyst
Copy link

feat(xrpl): add contains flag utility

Description

This PR aims to create a new utility package flag and use it across the existing transaction and ledger-entry-types to check bitwise flags in a consistent and reusable way.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where needed
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

Changes

xrpl

  • Added xrpl/flag package with a Contains(currentFlag, flag uint32) bool utility function that checks if a flag is fully set within a combined flag value.
  • Exported all flag constants across transaction and ledger-entry-types packages (e.g. asfRequireDest → AsfRequireDest) so they can be used externally with flag.Contains.
  • Refactored all flag checks across transaction and ledger-entry-types packages to use flag.Contains.
  • Added documentation for the flag package.

Notes

My first thought was to use currentFlag & flag != 0, which returns true if any bit overlaps between the two flags. This would have worked fine in most cases since flags are usually single-bit, but it breaks down for multi-bit flags where only a subset of bits match. For a function named Contains, the correct semantic is that all bits of the flag must be present, so I went with (currentFlag & flag) == flag instead. A flag != 0 guard was also added since without it, (x & 0) == 0 would always be true, silently making zero flags pass the check.

@GuillemGarciaDev GuillemGarciaDev self-requested a review February 25, 2026 14:29
Copy link
Collaborator

@GuillemGarciaDev GuillemGarciaDev left a comment

Choose a reason for hiding this comment

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

Nice PR, just a small change!

@GuillemGarciaDev GuillemGarciaDev self-requested a review February 25, 2026 14:36
Copy link
Collaborator

@GuillemGarciaDev GuillemGarciaDev left a comment

Choose a reason for hiding this comment

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

Just a little change

@GuillemGarciaDev GuillemGarciaDev merged commit 80a0388 into XRPLF:main Feb 25, 2026
3 checks passed
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.

2 participants