Sponsored Content
Skip to content

refactor: Use more scoped enums - #7086

Merged
bthomee merged 18 commits into
XRPLF:developfrom
godexsoft:refactor/scoped-enums
May 11, 2026
Merged

refactor: Use more scoped enums#7086
bthomee merged 18 commits into
XRPLF:developfrom
godexsoft:refactor/scoped-enums

Conversation

@godexsoft

Copy link
Copy Markdown
Contributor

High Level Overview of Change

This PR converts more C enums to modern scoped enums.
Remaining enums with NOLINT are best left alone for now. Comments above their respective NOLINT indicate why.

API Impact

No impact.

Copilot AI review requested due to automatic review settings May 6, 2026 16:53

Copilot AI left a comment

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings May 7, 2026 12:57

Copilot AI left a comment

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.34682% with 102 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.1%. Comparing base (779b49c) to head (93fdb56).

Files with missing lines Patch % Lines
src/libxrpl/basics/Log.cpp 13.8% 25 Missing ⚠️
src/xrpld/app/ledger/LedgerHistory.cpp 0.0% 11 Missing ⚠️
include/xrpl/resource/detail/Logic.h 45.5% 6 Missing ⚠️
src/libxrpl/json/JsonPropertyStream.cpp 0.0% 5 Missing ⚠️
src/libxrpl/json/json_reader.cpp 89.6% 5 Missing ⚠️
src/xrpld/app/ledger/detail/InboundLedger.cpp 44.4% 5 Missing ⚠️
src/libxrpl/beast/utility/beast_Journal.cpp 33.3% 4 Missing ⚠️
src/xrpld/app/ledger/detail/LedgerToJson.cpp 81.0% 4 Missing ⚠️
src/xrpld/app/main/GRPCServer.cpp 0.0% 4 Missing ⚠️
src/xrpld/app/misc/NetworkOPs.cpp 88.9% 4 Missing ⚠️
... and 19 more
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #7086   +/-   ##
=======================================
  Coverage     82.1%   82.1%           
=======================================
  Files         1010    1010           
  Lines        76070   76064    -6     
  Branches      7381    7374    -7     
=======================================
+ Hits         62457   62472   +15     
+ Misses       13613   13592   -21     
Files with missing lines Coverage Δ
include/xrpl/basics/Log.h 71.4% <ø> (ø)
include/xrpl/basics/StringUtilities.h 100.0% <ø> (ø)
include/xrpl/beast/utility/Journal.h 96.5% <100.0%> (ø)
include/xrpl/json/json_reader.h 100.0% <ø> (ø)
include/xrpl/json/json_value.h 98.5% <ø> (ø)
include/xrpl/json/json_writer.h 100.0% <100.0%> (ø)
include/xrpl/ledger/AmendmentTable.h 100.0% <ø> (ø)
include/xrpl/protocol/ApiVersion.h 100.0% <100.0%> (ø)
include/xrpl/protocol/SField.h 100.0% <ø> (ø)
include/xrpl/protocol/STAmount.h 93.7% <ø> (ø)
... and 142 more

... and 14 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@bthomee bthomee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I went through all lines to the best of my ability, and only a few things stood out that are mostly unrelated to this PR.

For good measure I used Claude to also perform a scan and it reported that the changed enums etc. were safe and resulted in identical behavior. It also noticed the changes to Beast severities as a breaking API change, but in our case this is fine to ignore.

// object. Intended for STNumber.
SMdDefault = SMdChangeOrig | SMdChangeNew | SMdDeleteFinal | SMdCreate
};
static constexpr auto kSMD_NEVER = 0x00;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is having these as constexpr better than as enum class members?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The intention of anonymous enum as used here is exactly to make constants. At the time of writing this was a good way but i believe in modern c++ there are better ways, like static constexpr auto for example :)

Comment thread include/xrpl/protocol/STBase.h Outdated
DisableApiPriorV2 = 0b0000'0010,

// IMPORTANT `All` must be union of all of the above; see also operator~
All = 0b0000'0011

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FWIW setting this to All = IncludeDate | DisableApiPriorV2 would be more elegant, and also consistent with how a similar value was set in SField.h.

It's probably outside the scope of this PR though, but at the same time not something anyone would create a dedicated PR for...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can try to apply that here

// MaxPacketSize = 484
MaxPacketSize = 1472
};
// MaxPacketSize = 484

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's delete this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deleted. i only left it before as it already was the "old value" that was left in a comment for some reason

Comment thread src/tests/libxrpl/json/Value.cpp
TokenMemberSeparator,
TokenComment,
TokenError
enum class TokenType {

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.

Could you make all enums where it's possible to be uint8_t?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds like an unrelated and slightly dangerous change

Comment thread include/xrpl/json/json_writer.h Outdated
break;

case UintValue:
case ValueType::Uint:

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.

Suggested change
case ValueType::Uint:
case ValueType::UInt:

While it's not too late (uint is weird for me though - I like uint or UInt)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's just fix all Uint in the project while we are here :)

Comment on lines +137 to +138
static constexpr auto kSMD_ALWAYS = 0x10; // value when node containing it is affected at all
static constexpr auto kSMD_BASE_TEN = 0x20; // value is treated as base 10, overriding behavior

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.

Let's align comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can't align them differently unless we want to clang-format: off

// Bitwise flags, 86 files
// Bitwise flags, 86 files, used in macros files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Privilege {

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.

Can't we make this an enum class?
If there are other enums left, please, take a look as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No and it even says why it was not converted. It would break macros files and i don't want to deal with external scripts in this PR so leaving this for future.

Comment thread src/libxrpl/json/Output.cpp Outdated
switch (value.type())
{
case json::NullValue: {
case json::ValueType::Null: {

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.

We're in json namespace, so we can probably remove json:: prefix here

Copilot AI review requested due to automatic review settings May 11, 2026 13:38

Copilot AI left a comment

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@godexsoft
godexsoft requested review from bthomee and mathbunnyru May 11, 2026 13:39

@mathbunnyru mathbunnyru left a comment

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.

Nice 👍

@godexsoft godexsoft added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label May 11, 2026
Copilot AI review requested due to automatic review settings May 11, 2026 14:19

Copilot AI left a comment

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@bthomee
bthomee enabled auto-merge May 11, 2026 14:28
@bthomee
bthomee added this pull request to the merge queue May 11, 2026
Merged via the queue into XRPLF:develop with commit cdee9a6 May 11, 2026
3 checks passed
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants