1#ifndef PROTOCOL_GET_OR_THROW_H_
2#define PROTOCOL_GET_OR_THROW_H_
4#include <xrpl/basics/Buffer.h>
5#include <xrpl/basics/StringUtilities.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/SField.h>
18 char const*
const key;
24 what() const noexcept
override
36 char const*
const key;
44 what() const noexcept
override
59 static_assert(
sizeof(T) == -1,
"This function must be specialized");
69 Throw<JsonMissingKeyError>(key);
73 Throw<JsonTypeMismatchError>(key,
"string");
85 Throw<JsonMissingKeyError>(key);
90 Throw<JsonTypeMismatchError>(key,
"bool");
92 return inner.
asInt() != 0;
102 Throw<JsonMissingKeyError>(key);
108 auto const r = inner.
asInt();
110 Throw<JsonTypeMismatchError>(key,
"uint64");
119 auto [p, ec] =
std::from_chars(s.data(), s.data() + s.size(), val, 16);
121 if (ec !=
std::errc() || (p != s.data() + s.size()))
122 Throw<JsonTypeMismatchError>(key,
"uint64");
125 Throw<JsonTypeMismatchError>(key,
"uint64");
133 std::string const hex = getOrThrow<std::string>(v, field);
134 if (
auto const r = strUnHex(hex))
139 Throw<JsonTypeMismatchError>(field.getJsonName(),
"Buffer");
149 return getOrThrow<T>(v, field);
Lightweight wrapper to tag static string.
std::string asString() const
Returns the unquoted string value.
bool isMember(const char *key) const
Return true if the object has a member named key.
Like std::vector<char> but better.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
JSON (JavaScript Object Notation).
ripple::AccountID getOrThrow(Json::Value const &v, ripple::SField const &field)
std::optional< T > getOptional(Json::Value const &v, ripple::SField const &field)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
JsonMissingKeyError(Json::StaticString const &k)
const char * what() const noexcept override
JsonTypeMismatchError(Json::StaticString const &k, std::string et)
std::string const expectedType
const char * what() const noexcept override