From 65d60d35b9c1b5529dcdc161a3a1a3be15a1ef2a Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 9 Oct 2019 11:00:11 -0400 Subject: [PATCH] monero_utils::deserialize() accepts target node as param --- src/utils/monero_utils.cpp | 10 ++++++---- src/utils/monero_utils.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/utils/monero_utils.cpp b/src/utils/monero_utils.cpp index b7a63cf..07279a6 100644 --- a/src/utils/monero_utils.cpp +++ b/src/utils/monero_utils.cpp @@ -452,11 +452,13 @@ string monero_utils::serialize(const boost::property_tree::ptree& node) { } // TODO: switch deserializes in this utils class to use this deserialize util -boost::property_tree::ptree monero_utils::deserialize(const string& json) { +void monero_utils::deserialize(const string& json, boost::property_tree::ptree& root) { std::istringstream iss = json.empty() ? std::istringstream() : std::istringstream(json); - boost::property_tree::ptree node; - boost::property_tree::read_json(iss, node); - return node; + try { + boost::property_tree::read_json(iss, root); + } catch (std::exception const& e) { + throw runtime_error("Invalid JSON"); + } } boost::property_tree::ptree monero_utils::to_property_tree(const vector& strs) { diff --git a/src/utils/monero_utils.h b/src/utils/monero_utils.h index 2442002..1c63783 100644 --- a/src/utils/monero_utils.h +++ b/src/utils/monero_utils.h @@ -84,7 +84,7 @@ namespace monero_utils string serialize(const boost::property_tree::ptree& node); - boost::property_tree::ptree deserialize(const string& json); + void deserialize(const string& json, boost::property_tree::ptree& root); /** * Convert a Monero Core cryptonote::block to a block in this library's native model.