aboutsummaryrefslogtreecommitdiff
path: root/src/serialization/json_object.cpp
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-16 12:43:38 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-16 12:43:38 -0700
commita08df6eb1beaf442ef6d9b27c1f47497b74d3471 (patch)
treeef0f0ac25c2932f26cdd0a389a4ad44ec2a97826 /src/serialization/json_object.cpp
parentMerge pull request #6601 (diff)
parentChange ZMQ-JSON txextra to hex and remove unnecessary base fields (diff)
downloadmonero-a08df6eb1beaf442ef6d9b27c1f47497b74d3471.tar.xz
Merge pull request #6603
4e2377995 Change ZMQ-JSON txextra to hex and remove unnecessary base fields (Lee Clagett)
Diffstat (limited to 'src/serialization/json_object.cpp')
-rw-r--r--src/serialization/json_object.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/serialization/json_object.cpp b/src/serialization/json_object.cpp
index 7cb9c2ed4..7c48cf6c3 100644
--- a/src/serialization/json_object.cpp
+++ b/src/serialization/json_object.cpp
@@ -148,6 +148,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);