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>
17 char const*
const key;
23 what() const noexcept
override
35 char const*
const key;
43 what() const noexcept
override
58 static_assert(
sizeof(T) == -1,
"This function must be specialized");
68 Throw<JsonMissingKeyError>(key);
72 Throw<JsonTypeMismatchError>(key,
"string");
84 Throw<JsonMissingKeyError>(key);
89 Throw<JsonTypeMismatchError>(key,
"bool");
91 return inner.
asInt() != 0;
101 Throw<JsonMissingKeyError>(key);
107 auto const r = inner.
asInt();
109 Throw<JsonTypeMismatchError>(key,
"uint64");
118 auto [p, ec] =
std::from_chars(s.data(), s.data() + s.size(), val, 16);
120 if (ec !=
std::errc() || (p != s.data() + s.size()))
121 Throw<JsonTypeMismatchError>(key,
"uint64");
124 Throw<JsonTypeMismatchError>(key,
"uint64");
132 std::string const hex = getOrThrow<std::string>(v, field);
133 if (
auto const r = strUnHex(hex))
138 Throw<JsonTypeMismatchError>(field.getJsonName(),
"Buffer");
148 return getOrThrow<T>(v, field);
Lightweight wrapper to tag static string.
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *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.
char const * what() const noexcept override
JsonMissingKeyError(Json::StaticString const &k)
char const * what() const noexcept override
JsonTypeMismatchError(Json::StaticString const &k, std::string et)
std::string const expectedType