mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-25 16:10:15 +00:00
Cleanup LedgerEntryType & TxType:
This commit removes the `ltINVALID` pseudo-type identifier from `LedgerEntryType` and the `ttINVALID` pseudo-type identifier from `TxType` and includes several small additional improvements that help to simplify the code base. It also improves the documentation `LedgerEntryType` and `TxType`, which was all over the place, and highlights some important caveats associated with making changes to the ledger and transaction type identifiers. The commit also adds a safety check to the `KnownFormats<>` class, that will catch the the accidental reuse of format identifiers. Ideally, this should be done at compile time but C++ does not (yet?) allow for the sort of introspection that would enable this.
This commit is contained in:
@@ -293,37 +293,22 @@ parseLeaf(
|
||||
{
|
||||
if (field == sfTransactionType)
|
||||
{
|
||||
TxType const txType(
|
||||
TxFormats::getInstance().findTypeByName(
|
||||
strValue));
|
||||
|
||||
if (txType == ttINVALID)
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid transaction format name");
|
||||
ret = detail::make_stvar<STUInt16>(
|
||||
field, static_cast<std::uint16_t>(txType));
|
||||
field,
|
||||
static_cast<std::uint16_t>(
|
||||
TxFormats::getInstance().findTypeByName(
|
||||
strValue)));
|
||||
|
||||
if (*name == sfGeneric)
|
||||
name = &sfTransaction;
|
||||
}
|
||||
else if (field == sfLedgerEntryType)
|
||||
{
|
||||
LedgerEntryType const type(
|
||||
LedgerFormats::getInstance().findTypeByName(
|
||||
strValue));
|
||||
|
||||
if (!(0u <= type &&
|
||||
type <=
|
||||
std::min<unsigned>(
|
||||
std::numeric_limits<
|
||||
std::uint16_t>::max(),
|
||||
std::numeric_limits<
|
||||
std::underlying_type_t<
|
||||
LedgerEntryType>>::max())))
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid ledger entry type: out of range");
|
||||
ret = detail::make_stvar<STUInt16>(
|
||||
field, static_cast<std::uint16_t>(type));
|
||||
field,
|
||||
static_cast<std::uint16_t>(
|
||||
LedgerFormats::getInstance().findTypeByName(
|
||||
strValue)));
|
||||
|
||||
if (*name == sfGeneric)
|
||||
name = &sfLedgerEntry;
|
||||
|
||||
Reference in New Issue
Block a user