From cbf791ccbec387ac5031dcd988913682e357c420 Mon Sep 17 00:00:00 2001 From: moss9001 Date: Fri, 3 Dec 2021 16:58:27 +0200 Subject: [PATCH] Update rpc_client.cpp update rpc_client::retrieve_value_from_reply and rpc_client::retrieve_array_value_from_reply; fault on empty reply_str was fixed (empty value is returned) --- .../peerplays_sidechain/common/rpc_client.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp index 36359c30..d08d337b 100644 --- a/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp +++ b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp @@ -834,15 +834,17 @@ rpc_client::rpc_client(const std::string &url, const std::string &user_name, con } std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx) { + if (reply_str.empty()) + return std::string(); std::stringstream ss(reply_str); boost::property_tree::ptree json; boost::property_tree::read_json(ss, json); if (json.find("result") == json.not_found()) { - return ""; + return std::string(); } auto json_result = json.get_child("result"); if (json_result.find(array_path) == json_result.not_found()) { - return ""; + return std::string(); } boost::property_tree::ptree array_ptree = json_result; @@ -859,19 +861,21 @@ std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, s } } - return ""; + return std::string(); } std::string rpc_client::retrieve_value_from_reply(std::string reply_str, std::string value_path) { + if (reply_str.empty()) + return std::string(); std::stringstream ss(reply_str); boost::property_tree::ptree json; boost::property_tree::read_json(ss, json); if (json.find("result") == json.not_found()) { - return ""; + return std::string(); } auto json_result = json.get_child("result"); if (json_result.find(value_path) == json_result.not_found()) { - return ""; + return std::string(); } return json_result.get(value_path); }