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

@@ -32,22 +32,12 @@ namespace ripple {
STLedgerEntry::STLedgerEntry(Keylet const& k)
: STObject(sfLedgerEntry), key_(k.key), type_(k.type)
{
// The on-ledger representation of a key type is a 16-bit unsigned integer
// but the LedgerEntryType enum has a larger range (including negative
// values), so catch obviously wrong values:
constexpr auto const minValidValue =
static_cast<LedgerEntryType>(std::numeric_limits<std::uint16_t>::min());
constexpr auto const maxValidValue =
static_cast<LedgerEntryType>(std::numeric_limits<std::uint16_t>::max());
if (type_ < minValidValue || type_ > maxValidValue)
Throw<std::runtime_error>("invalid ledger entry type: out of range");
auto const format = LedgerFormats::getInstance().findByType(type_);
if (format == nullptr)
Throw<std::runtime_error>("unknown ledger entry type");
Throw<std::runtime_error>(
"Attempt to create a SLE of unknown type " +
std::to_string(safe_cast<std::uint16_t>(k.type)));
set(format->getSOTemplate());