31#include <boost/utility/string_ref.hpp>
45#define OBJECT_HAS_MEMBER_OR_THROW(val, key) \
48 if (!val.HasMember(key)) \
50 throw cryptonote::json::MISSING_KEY(key); \
54#define INSERT_INTO_JSON_OBJECT(dest, key, source) \
55 dest.Key(#key, sizeof(#key) - 1); \
56 cryptonote::json::toJsonValue(dest, source);
58#define GET_FROM_JSON_OBJECT(source, dst, key) \
59 OBJECT_HAS_MEMBER_OR_THROW(source, #key) \
60 decltype(dst) dstVal##key; \
61 cryptonote::json::fromJsonValue(source[#key], dstVal##key); \
79 const char*
what()
const throw()
89 m = std::string(
"Key \"") +
key +
"\" missing from object.";
97 m = std::string(
"Json value has incorrect type, expected: ") + type;
105 m =
"An item failed to convert from json object to native object";
113 m =
"Failed to parse the json request";
117template<
typename Type>
120 return std::is_pod<Type>() && !std::is_integral<Type>();
127inline typename std::enable_if<is_to_hex<Type>()>::type
toJsonKey(rapidjson::Writer<epee::byte_stream>&
dest,
const Type& pod)
135inline typename std::enable_if<is_to_hex<Type>()>::type
toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const Type& pod)
142inline typename std::enable_if<is_to_hex<Type>()>::type
fromJsonValue(
const rapidjson::Value& val,
Type& t)
144 static_assert(std::is_standard_layout<Type>(),
"expected standard layout type");
148void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const rapidjson::Value& src);
150void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest, boost::string_ref i);
151inline void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const std::string& i)
157void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const std::vector<std::uint8_t>&);
158void fromJsonValue(
const rapidjson::Value& src, std::vector<std::uint8_t>& i);
165void fromJsonValue(
const rapidjson::Value& val,
unsigned char& i);
167void fromJsonValue(
const rapidjson::Value& val,
signed char& i);
171void fromJsonValue(
const rapidjson::Value& val,
unsigned short& i);
178void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const int);
182void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const unsigned long long i);
183void fromJsonValue(
const rapidjson::Value& val,
unsigned long long& i);
185void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const long long i);
186void fromJsonValue(
const rapidjson::Value& val,
long long& i);
188inline void toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const unsigned long i) {
191void fromJsonValue(
const rapidjson::Value& val,
unsigned long& i);
319template <
typename Map>
320typename std::enable_if<sfinae::is_map_like<Map>::value,
void>::type
toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const Map& map);
322template <
typename Map>
323typename std::enable_if<sfinae::is_map_like<Map>::value,
void>::type
fromJsonValue(
const rapidjson::Value& val, Map& map);
325template <
typename Vec>
326typename std::enable_if<sfinae::is_vector_like<Vec>::value,
void>::type
toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const Vec &vec);
328template <
typename Vec>
329typename std::enable_if<sfinae::is_vector_like<Vec>::value,
void>::type
fromJsonValue(
const rapidjson::Value& val, Vec& vec);
335template <
typename Map>
336inline typename std::enable_if<sfinae::is_map_like<Map>::value,
void>::type
toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const Map& map)
338 using key_type =
typename Map::key_type;
339 static_assert(std::is_same<std::string, key_type>() ||
is_to_hex<key_type>(),
"invalid map key type");
342 for (
const auto& i : map)
350template <
typename Map>
351inline typename std::enable_if<sfinae::is_map_like<Map>::value,
void>::type
fromJsonValue(
const rapidjson::Value& val, Map& map)
358 auto itr = val.MemberBegin();
361 while (itr != val.MemberEnd())
363 typename Map::key_type k;
364 typename Map::mapped_type m;
372template <
typename Vec>
373inline typename std::enable_if<sfinae::is_vector_like<Vec>::value,
void>::type
toJsonValue(rapidjson::Writer<epee::byte_stream>&
dest,
const Vec &vec)
375 using value_type =
typename Vec::value_type;
376 static_assert(!std::is_same<value_type, char>::value,
"encoding an array of chars is faster as hex");
377 static_assert(!std::is_same<value_type, unsigned char>::value,
"encoding an array of unsigned char is faster as hex");
392 void reserve(std::vector<T>& vec,
const std::size_t count)
398template <
typename Vec>
399inline typename std::enable_if<sfinae::is_vector_like<Vec>::value,
void>::type
fromJsonValue(
const rapidjson::Value& val, Vec& vec)
401 using value_type =
typename Vec::value_type;
402 static_assert(!std::is_same<value_type, char>::value,
"encoding a vector of chars is faster as hex");
403 static_assert(!std::is_same<value_type, unsigned char>::value,
"encoding a vector of unsigned char is faster as hex");
412 for (rapidjson::SizeType i=0; i < val.Size(); i++)
cryptonote::block b
Definition block.cpp:40
static void prune(MDB_env *env0, MDB_env *env1)
Definition blockchain_prune.cpp:249
Definition cryptonote_basic.h:205
Non-owning sequence of data. Does not deep copy.
Definition span.h:55
const char * key
Definition hmac_keccak.cpp:40
static MDB_envinfo info
Definition mdb_load.c:37
Definition json_object.h:386
void reserve(const T &, std::size_t)
Definition json_object.h:388
constexpr bool is_to_hex()
Definition json_object.h:118
void read_hex(const rapidjson::Value &val, epee::span< std::uint8_t > dest)
Definition json_object.cpp:119
void fromJsonValue(const rapidjson::Value &val, std::string &str)
Definition json_object.cpp:142
void toJsonValue(rapidjson::Writer< epee::byte_stream > &dest, const rapidjson::Value &src)
Definition json_object.cpp:132
std::enable_if< is_to_hex< Type >()>::type toJsonKey(rapidjson::Writer< epee::byte_stream > &dest, const Type &pod)
Definition json_object.h:127
Holds cryptonote related classes and helpers.
Definition blockchain_db.cpp:45
boost::variant< txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key > txout_target_v
Definition cryptonote_basic.h:154
boost::variant< txin_gen, txin_to_script, txin_to_scripthash, txin_to_key > txin_v
Definition cryptonote_basic.h:152
std::string hex(difficulty_type v)
Definition difficulty.cpp:242
span< std::uint8_t > as_mut_byte_span(T &src) noexcept
Definition span.h:172
const char *const str
Definition portlistingparse.c:23
Type
Type of JSON value.
Definition rapidjson.h:623
CXA_THROW_INFO_T void(* dest)(void *))
Definition stack_trace.cpp:91
Definition cryptonote_protocol_defs.h:133
Definition cryptonote_basic.h:475
Definition cryptonote_protocol_defs.h:48
const char * what() const
Definition json_object.h:79
std::string m
Definition json_object.h:74
virtual ~JSON_ERROR()
Definition json_object.h:77
JSON_ERROR()
Definition json_object.h:73
MISSING_KEY(const char *key)
Definition json_object.h:87
PARSE_FAIL()
Definition json_object.h:111
Definition json_object.h:94
WRONG_TYPE(const char *type)
Definition json_object.h:95
Definition core_rpc_server_commands_defs.h:1338
Definition message_data_structs.h:176
Definition message_data_structs.h:72
Definition message_data_structs.h:47
Definition message_data_structs.h:144
Definition message_data_structs.h:131
Definition message_data_structs.h:118
Definition message_data_structs.h:110
Definition message_data_structs.h:207
Definition message_data_structs.h:64
Definition message_data_structs.h:124
Definition message_data_structs.h:78
Definition message_data_structs.h:57
Definition message_data_structs.h:89
Definition cryptonote_protocol_defs.h:122
Definition cryptonote_tx_utils.h:113
Definition core_rpc_server_commands_defs.h:1523
Definition cryptonote_basic.h:158
Definition cryptonote_basic.h:102
Definition cryptonote_basic.h:139
Definition cryptonote_basic.h:111
Definition cryptonote_basic.h:124
Definition cryptonote_basic.h:79
Definition cryptonote_basic.h:62
Definition cryptonote_basic.h:73
Definition cryptonote_basic.h:87
static std::array< char, N *2 > array(const std::array< std::uint8_t, N > &src) noexcept
Definition hex.h:52
Definition rctTypes.h:250
Definition rctTypes.h:213
Definition rctTypes.h:155
Definition rctTypes.h:181
Definition rctTypes.h:140
Definition rctTypes.h:168
Definition rctTypes.h:202
Definition rctTypes.h:613
cryptonote::transaction tx
Definition transaction.cpp:40
rapidjson::Document json
Definition transport.cpp:49