From 3766c1095fffd377e591819119b3a9a41071112a Mon Sep 17 00:00:00 2001 From: Yevhen Viter Date: Mon, 13 Dec 2021 19:03:58 +0200 Subject: [PATCH] For review #bug-empty-json - tag is used for quick search --- .../peerplays_sidechain/bitcoin/utils.cpp | 4 +++- .../sidechain_net_handler_bitcoin.cpp | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/utils.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/utils.cpp index 6d802a2f..37ed8e61 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/utils.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/utils.cpp @@ -48,6 +48,8 @@ bytes public_key_data_to_bytes(const fc::ecc::public_key_data &key) { } std::vector read_byte_arrays_from_string(const std::string &string_buf) { + if (string_buf.empty()) + return std::vector(); std::stringstream ss(string_buf); boost::property_tree::ptree json; boost::property_tree::read_json(ss, json); @@ -77,7 +79,7 @@ std::string write_transaction_signatures(const std::vector &data) { void read_transaction_data(const std::string &string_buf, std::string &tx_hex, std::vector &in_amounts, std::string &redeem_script) { std::stringstream ss(string_buf); boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); + boost::property_tree::read_json(ss, json); //! failure if string_buf is empty/invalid #bug-empty-json tx_hex = json.get("tx_hex"); in_amounts.clear(); for (auto &v : json.get_child("in_amounts")) diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 1ad0d9c8..4616ea06 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -958,7 +958,7 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain std::string blockchain_info = bitcoin_client->getblockchaininfo(); std::stringstream bci_ss(std::string(blockchain_info.begin(), blockchain_info.end())); boost::property_tree::ptree bci_json; - boost::property_tree::read_json(bci_ss, bci_json); + boost::property_tree::read_json(bci_ss, bci_json); //! failure if blockchain_info is empty/invalid #bug-empty-json using namespace bitcoin; network_type = bitcoin_address::network::mainnet; if (bci_json.count("chain")) { @@ -1050,7 +1050,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) std::stringstream active_pw_ss(reply_str); boost::property_tree::ptree active_pw_pt; - boost::property_tree::read_json(active_pw_ss, active_pw_pt); + boost::property_tree::read_json(active_pw_ss, active_pw_pt); //! failure if reply_str is empty/invalid #bug-empty-json if (active_pw_pt.count("error") && active_pw_pt.get_child("error").empty()) { std::stringstream res; boost::property_tree::json_parser::write_json(res, active_pw_pt.get_child("result")); @@ -1106,7 +1106,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) std::string tx_str = bitcoin_client->getrawtransaction(swdo_txid, true); std::stringstream tx_ss(tx_str); boost::property_tree::ptree tx_json; - boost::property_tree::read_json(tx_ss, tx_json); + boost::property_tree::read_json(tx_ss, tx_json); //! failure if reply_str is empty/invalid #bug-empty-json if (tx_json.count("error") && tx_json.get_child("error").empty()) { @@ -1290,7 +1290,7 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() { std::stringstream active_pw_ss(reply_str); boost::property_tree::ptree active_pw_pt; - boost::property_tree::read_json(active_pw_ss, active_pw_pt); + boost::property_tree::read_json(active_pw_ss, active_pw_pt); //! failure if reply_str is empty/invalid #bug-empty-json if (active_pw_pt.count("error") && active_pw_pt.get_child("error").empty()) { if (!plugin.can_son_participate(chain::operation::tag::value, active_sw->id)) { return; @@ -1510,7 +1510,7 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain std::string tx_str = bitcoin_client->getrawtransaction(sto.sidechain_transaction, true); std::stringstream tx_ss(tx_str); boost::property_tree::ptree tx_json; - boost::property_tree::read_json(tx_ss, tx_json); + boost::property_tree::read_json(tx_ss, tx_json); //! failure if tx_str is empty/invalid #bug-empty-json if ((tx_json.count("error")) && (!tx_json.get_child("error").empty())) { return false; @@ -1640,7 +1640,7 @@ std::string sidechain_net_handler_bitcoin::create_deposit_transaction(const son_ std::stringstream ss(pw_address_json); boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); + boost::property_tree::read_json(ss, json); //! failure if pw_address_json is empty/invalid #bug-empty-json std::string pw_address = json.get("address"); @@ -1680,7 +1680,7 @@ std::string sidechain_net_handler_bitcoin::create_withdrawal_transaction(const s std::stringstream ss(pw_address_json); boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); + boost::property_tree::read_json(ss, json); //! failure if pw_address_json is empty/invalid #bug-empty-json std::string pw_address = json.get("address"); std::string redeem_script = json.get("redeemScript"); @@ -1869,7 +1869,7 @@ std::string sidechain_net_handler_bitcoin::get_redeemscript_for_userdeposit(cons std::vector sidechain_net_handler_bitcoin::extract_info_from_block(const std::string &_block) { std::stringstream ss(_block); boost::property_tree::ptree block; - boost::property_tree::read_json(ss, block); + boost::property_tree::read_json(ss, block); //! failure if _block is empty/invalid #bug-empty-json std::vector result; @@ -1919,7 +1919,7 @@ void sidechain_net_handler_bitcoin::on_changed_objects_cb(const vectoraddresses.at(sidechain)); boost::property_tree::ptree pw_pt; - boost::property_tree::read_json(pw_ss, pw_pt); + boost::property_tree::read_json(pw_ss, pw_pt); //! failure if swo->addresses.at(sidechain) is empty/invalid #bug-empty-json if (pw_pt.count("address")) { std::string pw_address = pw_pt.get("address");