refactor: Use static_cast instead of switch in getVaultVersion

Address PR review comment: VaultVersion's enumerators already have
explicit values, so static_cast<VaultVersion>(leVersion) avoids
repeating them as switch-case magic numbers. Out-of-range values
still hit the UNREACHABLE guard.
This commit is contained in:
Vito
2026-07-27 14:50:08 +02:00
parent 63e8158769
commit 59c779fc01

View File

@@ -14,6 +14,7 @@
#include <cstdint>
#include <optional>
#include <utility>
namespace xrpl {
@@ -145,18 +146,15 @@ getVaultVersion(SLE::const_ref vault)
if (!vault->isFieldPresent(sfLEVersion))
return VaultVersion::Legacy;
switch (vault->at(sfLEVersion))
auto const version = vault->at(sfLEVersion);
if (version > std::to_underlying(VaultVersion::CashBasis))
{
case 0:
return VaultVersion::Legacy;
case 1:
return VaultVersion::CashBasis;
default:
// LCOV_EXCL_START
UNREACHABLE("xrpl::getVaultVersion : invalid vault version");
return VaultVersion::Legacy;
// LCOV_EXCL_STOP
// LCOV_EXCL_START
UNREACHABLE("xrpl::getVaultVersion : invalid vault version");
return VaultVersion::Legacy;
// LCOV_EXCL_STOP
}
return static_cast<VaultVersion>(version);
}
} // namespace xrpl