From 4324091de33e716b3d18322a8abe68504320d472 Mon Sep 17 00:00:00 2001 From: serkixenos Date: Tue, 5 Apr 2022 18:38:57 -0400 Subject: [PATCH] Code formatting --- .../sidechain_net_handler_bitcoin.cpp | 198 +++++------------- 1 file changed, 57 insertions(+), 141 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index dbf7aadd..583effde 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -41,8 +41,7 @@ bitcoin_rpc_client::bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::stri std::string bitcoin_rpc_client::addmultisigaddress(const uint32_t nrequired, const std::vector public_keys) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"addmultisigaddress\", " "\"method\": \"addmultisigaddress\", \"params\": ["); - try - { + try { std::string params = std::to_string(nrequired) + ", ["; std::string pubkeys = ""; for (std::string pubkey : public_keys) { @@ -73,9 +72,7 @@ std::string bitcoin_rpc_client::addmultisigaddress(const uint32_t nrequired, con wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -84,8 +81,7 @@ std::string bitcoin_rpc_client::addmultisigaddress(const uint32_t nrequired, con std::string bitcoin_rpc_client::combinepsbt(const vector &psbts) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"combinepsbt\", \"method\": " "\"combinepsbt\", \"params\": [["); - try - { + try { std::string params = ""; for (std::string psbt : psbts) { if (!params.empty()) { @@ -115,9 +111,7 @@ std::string bitcoin_rpc_client::combinepsbt(const vector &psbts) { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -126,8 +120,7 @@ std::string bitcoin_rpc_client::combinepsbt(const vector &psbts) { std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const std::vector public_keys) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"createmultisig\", " "\"method\": \"createmultisig\", \"params\": ["); - try - { + try { std::string params = std::to_string(nrequired) + ", ["; std::string pubkeys = ""; for (std::string pubkey : public_keys) { @@ -158,9 +151,7 @@ std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const s wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -169,8 +160,7 @@ std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const s std::string bitcoin_rpc_client::createpsbt(const std::vector &ins, const fc::flat_map outs) { std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"createpsbt\", " "\"method\": \"createpsbt\", \"params\": ["); - try - { + try { body += "["; bool first = true; for (const auto &entry : ins) { @@ -210,9 +200,7 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector &ins, co wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -221,8 +209,7 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector &ins, co std::string bitcoin_rpc_client::createrawtransaction(const std::vector &ins, const fc::flat_map outs) { std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"createrawtransaction\", " "\"method\": \"createrawtransaction\", \"params\": ["); - try - { + try { body += "["; bool first = true; for (const auto &entry : ins) { @@ -262,9 +249,7 @@ std::string bitcoin_rpc_client::createrawtransaction(const std::vector &address_or_script_array, const bool rescan) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"importmulti\", " "\"method\": \"importmulti\", \"params\": ["); - try - { + try { std::string argument_1 = "["; for (const auto ¶m : address_or_script_array) { argument_1 += "{\"scriptPubKey\": "; @@ -778,9 +723,7 @@ void bitcoin_rpc_client::importmulti(const std::vector &address_or } else if (json.count("error") && !json.get_child("error").empty()) { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); } } @@ -789,10 +732,9 @@ std::vector bitcoin_rpc_client::listunspent(const uint32_t minconf, c const auto body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"pp_plugin\", \"method\": " "\"listunspent\", \"params\": [" + std::to_string(minconf) + "," + std::to_string(maxconf) + "] }"); - + std::vector result; - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -820,9 +762,7 @@ std::vector bitcoin_rpc_client::listunspent(const uint32_t minconf, c wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return result; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return result; } @@ -840,8 +780,7 @@ std::vector bitcoin_rpc_client::listunspent_by_address_and_amount(con std::vector result; - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -869,9 +808,7 @@ std::vector bitcoin_rpc_client::listunspent_by_address_and_amount(con wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return result; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return result; } @@ -881,8 +818,7 @@ std::string bitcoin_rpc_client::loadwallet(const std::string &filename) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"loadwallet\", \"method\": " "\"loadwallet\", \"params\": [\"" + filename + "\"] }"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -904,9 +840,7 @@ std::string bitcoin_rpc_client::loadwallet(const std::string &filename) { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -916,8 +850,7 @@ std::string bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) { const auto body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"sendrawtransaction\", " "\"method\": \"sendrawtransaction\", \"params\": [") + std::string("\"") + tx_hex + std::string("\"") + std::string("] }"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -937,9 +870,7 @@ std::string bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -951,8 +882,7 @@ std::string bitcoin_rpc_client::signrawtransactionwithwallet(const std::string & std::string params = "\"" + tx_hash + "\""; body = body + params + std::string("]}"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -972,9 +902,7 @@ std::string bitcoin_rpc_client::signrawtransactionwithwallet(const std::string & wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -984,8 +912,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"unloadwallet\", \"method\": " "\"unloadwallet\", \"params\": [\"" + filename + "\"] }"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -1007,9 +934,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -1018,8 +943,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { std::string bitcoin_rpc_client::walletlock() { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": " "\"walletlock\", \"params\": [] }"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -1041,9 +965,7 @@ std::string bitcoin_rpc_client::walletlock() { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -1053,8 +975,7 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletprocesspsbt\", \"method\": " "\"walletprocesspsbt\", \"params\": [\"" + tx_psbt + "\"] }"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -1074,9 +995,7 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return ""; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return ""; } @@ -1086,8 +1005,7 @@ bool bitcoin_rpc_client::walletpassphrase(const std::string &passphrase, uint32_ std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletpassphrase\", \"method\": " "\"walletpassphrase\", \"params\": [\"" + passphrase + "\", " + std::to_string(timeout) + "] }"); - try - { + try { const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { @@ -1107,9 +1025,7 @@ bool bitcoin_rpc_client::walletpassphrase(const std::string &passphrase, uint32_ wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); } return false; - } - catch(const boost::exception& ex) - { + } catch (const boost::exception &ex) { wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex))); return false; }