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:
Nik Bougalis
2021-08-25 01:14:53 -07:00
parent 234b754038
commit af5f28cbf8
15 changed files with 295 additions and 120 deletions

View File

@@ -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;