mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-04 17:26:39 +00:00
Simplify & modernize code:
- Simplify and consolidate code for parsing hex input. - Replace beast::endian::order with boost::endian::order. - Simplify CountedObject code. - Remove pre-C++17 workarounds in favor of C++17 based solutions. - Improve `base_uint` and simplify its hex-parsing interface by consolidating the `SexHex` and `SetHexExact` methods into one API: `parseHex` which forces callers to verify the result of the operation; as a result some public-facing API endpoints may now return errors when passed values that were previously accepted. - Remove the simple fallback implementations of SHA2 and RIPEMD introduced to reduce our dependency on OpenSSL. The code is slow and rarely, if ever, exercised and we rely on OpenSSL functionality for Boost.ASIO as well.
This commit is contained in:
@@ -25,22 +25,29 @@
|
||||
#include <ripple/protocol/STLedgerEntry.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <boost/format.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
STLedgerEntry::STLedgerEntry(Keylet const& k)
|
||||
: STObject(sfLedgerEntry), key_(k.key), type_(k.type)
|
||||
{
|
||||
if (!(0u <= type_ &&
|
||||
type_ <= std::min<unsigned>(
|
||||
std::numeric_limits<std::uint16_t>::max(),
|
||||
std::numeric_limits<
|
||||
std::underlying_type_t<LedgerEntryType>>::max())))
|
||||
// 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>("invalid ledger entry type");
|
||||
Throw<std::runtime_error>("unknown ledger entry type");
|
||||
|
||||
set(format->getSOTemplate());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user