diff options
author | Lee Clagett <code@leeclagett.com> | 2020-05-31 01:22:33 -0400 |
---|---|---|
committer | Lee Clagett <code@leeclagett.com> | 2020-08-14 23:01:00 +0000 |
commit | 4e2377995d286eb01456ed1dfd29cd278282ec19 (patch) | |
tree | c722a778b7c07d71008d35ce6d5907f92a7de25e /src/serialization/json_object.cpp | |
parent | Merge pull request #6582 (diff) | |
download | monero-4e2377995d286eb01456ed1dfd29cd278282ec19.tar.xz |
Change ZMQ-JSON txextra to hex and remove unnecessary base fields
Diffstat (limited to 'src/serialization/json_object.cpp')
-rw-r--r-- | src/serialization/json_object.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/serialization/json_object.cpp b/src/serialization/json_object.cpp index 6228b4bec..1f71126c3 100644 --- a/src/serialization/json_object.cpp +++ b/src/serialization/json_object.cpp @@ -146,6 +146,26 @@ void fromJsonValue(const rapidjson::Value& val, std::string& str) str = val.GetString(); } +void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const std::vector<std::uint8_t>& src) +{ + const std::string hex = epee::to_hex::string(epee::to_span(src)); + dest.String(hex.data(), hex.size()); +} + +void fromJsonValue(const rapidjson::Value& val, std::vector<std::uint8_t>& dest) +{ + if (!val.IsString()) + { + throw WRONG_TYPE("string"); + } + + dest.resize(val.GetStringLength() / 2); + if ((val.GetStringLength() % 2) != 0 || !epee::from_hex::to_buffer(epee::to_mut_span(dest), {val.GetString(), val.GetStringLength()})) + { + throw BAD_INPUT(); + } +} + void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, bool i) { dest.Bool(i); |