#336 exception parse json

This commit is contained in:
Vlad Dobromyslov 2022-04-06 23:23:47 +00:00 committed by serkixenos
parent 6ee37d0916
commit d49017ff21

View file

@ -41,6 +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<std::string> public_keys) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"addmultisigaddress\", "
"\"method\": \"addmultisigaddress\", \"params\": [");
try {
std::string params = std::to_string(nrequired) + ", [";
std::string pubkeys = "";
for (std::string pubkey : public_keys) {
@ -71,11 +72,16 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::combinepsbt(const vector<std::string> &psbts) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"combinepsbt\", \"method\": "
"\"combinepsbt\", \"params\": [[");
try {
std::string params = "";
for (std::string psbt : psbts) {
if (!params.empty()) {
@ -105,11 +111,16 @@ std::string bitcoin_rpc_client::combinepsbt(const vector<std::string> &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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const std::vector<std::string> public_keys) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"createmultisig\", "
"\"method\": \"createmultisig\", \"params\": [");
try {
std::string params = std::to_string(nrequired) + ", [";
std::string pubkeys = "";
for (std::string pubkey : public_keys) {
@ -140,11 +151,16 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::createpsbt(const std::vector<btc_txout> &ins, const fc::flat_map<std::string, double> outs) {
std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"createpsbt\", "
"\"method\": \"createpsbt\", \"params\": [");
try {
body += "[";
bool first = true;
for (const auto &entry : ins) {
@ -184,11 +200,16 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector<btc_txout> &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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::createrawtransaction(const std::vector<btc_txout> &ins, const fc::flat_map<std::string, double> outs) {
std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"createrawtransaction\", "
"\"method\": \"createrawtransaction\", \"params\": [");
try {
body += "[";
bool first = true;
for (const auto &entry : ins) {
@ -228,13 +249,17 @@ std::string bitcoin_rpc_client::createrawtransaction(const std::vector<btc_txout
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::createwallet(const std::string &wallet_name) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"createwallet\", \"method\": "
"\"createwallet\", \"params\": [\"" +
wallet_name + "\"] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -256,13 +281,17 @@ std::string bitcoin_rpc_client::createwallet(const std::string &wallet_name) {
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::decodepsbt(std::string const &tx_psbt) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"decodepsbt\", \"method\": "
"\"decodepsbt\", \"params\": [\"" +
tx_psbt + "\"] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -284,13 +313,17 @@ std::string bitcoin_rpc_client::decodepsbt(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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::decoderawtransaction(std::string const &tx_hex) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"decoderawtransaction\", \"method\": "
"\"decoderawtransaction\", \"params\": [\"" +
tx_hex + "\"] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -312,13 +345,17 @@ std::string bitcoin_rpc_client::decoderawtransaction(std::string const &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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::encryptwallet(const std::string &passphrase) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"encryptwallet\", \"method\": "
"\"encryptwallet\", \"params\": [\"" +
passphrase + "\"] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -340,13 +377,17 @@ std::string bitcoin_rpc_client::encryptwallet(const std::string &passphrase) {
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) {
const auto body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"estimatesmartfee\", "
"\"method\": \"estimatesmartfee\", \"params\": [" +
std::to_string(conf_target) + std::string("] }"));
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -377,13 +418,17 @@ uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) {
wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str()));
}
return 20000;
} 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 20000;
}
}
std::string bitcoin_rpc_client::finalizepsbt(std::string const &tx_psbt) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"finalizepsbt\", \"method\": "
"\"finalizepsbt\", \"params\": [\"" +
tx_psbt + "\"] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -403,13 +448,17 @@ std::string bitcoin_rpc_client::finalizepsbt(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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::getaddressinfo(const std::string &address) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"getaddressinfo\", \"method\": "
"\"getaddressinfo\", \"params\": [\"" +
address + "\"] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -431,13 +480,17 @@ std::string bitcoin_rpc_client::getaddressinfo(const std::string &address) {
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::getblock(const std::string &block_hash, int32_t verbosity) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"getblock\", \"method\": "
"\"getblock\", \"params\": [\"" +
block_hash + "\", " + std::to_string(verbosity) + "] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -459,12 +512,16 @@ std::string bitcoin_rpc_client::getblock(const std::string &block_hash, int32_t
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::getnetworkinfo() {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"getnetworkinfo\", \"method\": "
"\"getnetworkinfo\", \"params\": [] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -485,12 +542,16 @@ std::string bitcoin_rpc_client::getnetworkinfo() {
}
return "";
} 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 "";
}
}
std::string bitcoin_rpc_client::getrawtransaction(const std::string &txid, const bool verbose) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"getrawtransaction\", \"method\": "
"\"getrawtransaction\", \"params\": [");
try {
std::string params = "\"" + txid + "\", " + (verbose ? "true" : "false");
body = body + params + "] }";
@ -513,12 +574,16 @@ std::string bitcoin_rpc_client::getrawtransaction(const std::string &txid, const
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::gettransaction(const std::string &txid, const bool include_watch_only) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"gettransaction\", \"method\": "
"\"gettransaction\", \"params\": [");
try {
std::string params = "\"" + txid + "\", " + (include_watch_only ? "true" : "false");
body = body + params + "] }";
@ -541,12 +606,16 @@ std::string bitcoin_rpc_client::gettransaction(const std::string &txid, const bo
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::getblockchaininfo() {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"getblockchaininfo\", \"method\": "
"\"getblockchaininfo\", \"params\": [] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -568,12 +637,16 @@ std::string bitcoin_rpc_client::getblockchaininfo() {
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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
void bitcoin_rpc_client::importaddress(const std::string &address_or_script, const std::string &label, const bool rescan, const bool p2sh) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"importaddress\", "
"\"method\": \"importaddress\", \"params\": [");
try {
std::string params = "\"" + address_or_script + "\", " +
"\"" + label + "\", " +
(rescan ? "true" : "false") + ", " +
@ -596,12 +669,15 @@ void bitcoin_rpc_client::importaddress(const std::string &address_or_script, con
} 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
}
}
void bitcoin_rpc_client::importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"importmulti\", "
"\"method\": \"importmulti\", \"params\": [");
try {
std::string argument_1 = "[";
for (const auto &param : address_or_script_array) {
argument_1 += "{\"scriptPubKey\": ";
@ -647,6 +723,9 @@ void bitcoin_rpc_client::importmulti(const std::vector<multi_params> &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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
}
}
std::vector<btc_txout> bitcoin_rpc_client::listunspent(const uint32_t minconf, const uint32_t maxconf) {
@ -654,9 +733,9 @@ std::vector<btc_txout> bitcoin_rpc_client::listunspent(const uint32_t minconf, c
"\"listunspent\", \"params\": [" +
std::to_string(minconf) + "," + std::to_string(maxconf) + "] }");
const auto reply = send_post_request(body, debug_rpc_calls);
std::vector<btc_txout> result;
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
@ -683,6 +762,10 @@ std::vector<btc_txout> 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return result;
}
}
std::vector<btc_txout> bitcoin_rpc_client::listunspent_by_address_and_amount(const std::string &address, double minimum_amount, const uint32_t minconf, const uint32_t maxconf) {
@ -695,9 +778,11 @@ std::vector<btc_txout> bitcoin_rpc_client::listunspent_by_address_and_amount(con
body += std::to_string(minimum_amount);
body += std::string("} ] }");
std::vector<btc_txout> result;
try {
const auto reply = send_post_request(body, debug_rpc_calls);
std::vector<btc_txout> result;
if (reply.body.empty()) {
wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
return result;
@ -723,13 +808,17 @@ std::vector<btc_txout> 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return result;
}
}
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 {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -751,13 +840,17 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
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 {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -777,6 +870,10 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::signrawtransactionwithwallet(const std::string &tx_hash) {
@ -785,6 +882,7 @@ std::string bitcoin_rpc_client::signrawtransactionwithwallet(const std::string &
std::string params = "\"" + tx_hash + "\"";
body = body + params + std::string("]}");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -804,13 +902,17 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
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 {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -832,12 +934,16 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
std::string bitcoin_rpc_client::walletlock() {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": "
"\"walletlock\", \"params\": [] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -859,13 +965,17 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
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 {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -885,13 +995,17 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return "";
}
}
bool bitcoin_rpc_client::walletpassphrase(const std::string &passphrase, uint32_t timeout) {
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletpassphrase\", \"method\": "
"\"walletpassphrase\", \"params\": [\"" +
passphrase + "\", " + std::to_string(timeout) + "] }");
try {
const auto reply = send_post_request(body, debug_rpc_calls);
if (reply.body.empty()) {
@ -911,6 +1025,10 @@ 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) {
wlog("Bitcoin RPC call ${function} with body ${body} generate exception: '${exception}'", ("function", __FUNCTION__)("body", body)("exception", boost::diagnostic_information(ex)));
return false;
}
}
fc::http::reply bitcoin_rpc_client::send_post_request(std::string body, bool show_log) {
@ -929,6 +1047,7 @@ fc::http::reply bitcoin_rpc_client::send_post_request(std::string body, bool sho
ilog("### Request URL: ${url}", ("url", url));
ilog("### Request: ${body}", ("body", body));
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
ilog("### Response status: ${status}", ("status", reply.status));
ilog("### Response: ${ss}", ("ss", ss.str()));
}