#337 - lock/unlock wallet when importmulti
This commit is contained in:
parent
cc7f7fc103
commit
28f44b093b
2 changed files with 66 additions and 54 deletions
|
|
@ -67,9 +67,9 @@ public:
|
||||||
std::string sendrawtransaction(const std::string &tx_hex);
|
std::string sendrawtransaction(const std::string &tx_hex);
|
||||||
std::string signrawtransactionwithwallet(const std::string &tx_hash);
|
std::string signrawtransactionwithwallet(const std::string &tx_hash);
|
||||||
std::string unloadwallet(const std::string &filename);
|
std::string unloadwallet(const std::string &filename);
|
||||||
//std::string walletlock();
|
std::string walletlock();
|
||||||
std::string walletprocesspsbt(std::string const &tx_psbt);
|
std::string walletprocesspsbt(std::string const &tx_psbt);
|
||||||
//bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
fc::http::reply send_post_request(std::string body, bool show_log);
|
fc::http::reply send_post_request(std::string body, bool show_log);
|
||||||
|
|
|
||||||
|
|
@ -834,32 +834,32 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::string bitcoin_rpc_client::walletlock() {
|
std::string bitcoin_rpc_client::walletlock() {
|
||||||
// std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": "
|
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": "
|
||||||
// "\"walletlock\", \"params\": [] }");
|
"\"walletlock\", \"params\": [] }");
|
||||||
//
|
|
||||||
// const auto reply = send_post_request(body, debug_rpc_calls);
|
const auto reply = send_post_request(body, debug_rpc_calls);
|
||||||
//
|
|
||||||
// if (reply.body.empty()) {
|
if (reply.body.empty()) {
|
||||||
// wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
|
wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
|
||||||
// return "";
|
return "";
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
||||||
// boost::property_tree::ptree json;
|
boost::property_tree::ptree json;
|
||||||
// boost::property_tree::read_json(ss, json);
|
boost::property_tree::read_json(ss, json);
|
||||||
//
|
|
||||||
// if (reply.status == 200) {
|
if (reply.status == 200) {
|
||||||
// std::stringstream ss;
|
std::stringstream ss;
|
||||||
// boost::property_tree::json_parser::write_json(ss, json.get_child("result"));
|
boost::property_tree::json_parser::write_json(ss, json.get_child("result"));
|
||||||
// return ss.str();
|
return ss.str();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (json.count("error") && !json.get_child("error").empty()) {
|
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()));
|
wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str()));
|
||||||
// }
|
}
|
||||||
// return "";
|
return "";
|
||||||
//}
|
}
|
||||||
|
|
||||||
std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) {
|
std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) {
|
||||||
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletprocesspsbt\", \"method\": "
|
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletprocesspsbt\", \"method\": "
|
||||||
|
|
@ -887,31 +887,31 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool bitcoin_rpc_client::walletpassphrase(const std::string &passphrase, uint32_t timeout) {
|
bool bitcoin_rpc_client::walletpassphrase(const std::string &passphrase, uint32_t timeout) {
|
||||||
// std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletpassphrase\", \"method\": "
|
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletpassphrase\", \"method\": "
|
||||||
// "\"walletpassphrase\", \"params\": [\"" +
|
"\"walletpassphrase\", \"params\": [\"" +
|
||||||
// passphrase + "\", " + std::to_string(timeout) + "] }");
|
passphrase + "\", " + std::to_string(timeout) + "] }");
|
||||||
//
|
|
||||||
// const auto reply = send_post_request(body, debug_rpc_calls);
|
const auto reply = send_post_request(body, debug_rpc_calls);
|
||||||
//
|
|
||||||
// if (reply.body.empty()) {
|
if (reply.body.empty()) {
|
||||||
// wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
|
wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
||||||
// boost::property_tree::ptree json;
|
boost::property_tree::ptree json;
|
||||||
// boost::property_tree::read_json(ss, json);
|
boost::property_tree::read_json(ss, json);
|
||||||
//
|
|
||||||
// if (reply.status == 200) {
|
if (reply.status == 200) {
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (json.count("error") && !json.get_child("error").empty()) {
|
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()));
|
wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str()));
|
||||||
// }
|
}
|
||||||
// return false;
|
return false;
|
||||||
//}
|
}
|
||||||
|
|
||||||
fc::http::reply bitcoin_rpc_client::send_post_request(std::string body, bool show_log) {
|
fc::http::reply bitcoin_rpc_client::send_post_request(std::string body, bool show_log) {
|
||||||
fc::http::connection conn;
|
fc::http::connection conn;
|
||||||
|
|
@ -2052,8 +2052,20 @@ void sidechain_net_handler_bitcoin::on_changed_objects_cb(const vector<object_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!address_or_script_array.empty())
|
//! importmulti all addreses in one bulk
|
||||||
|
if (!address_or_script_array.empty()) {
|
||||||
|
//! Unlock wallet
|
||||||
|
if (!wallet_password.empty()) {
|
||||||
|
if( !bitcoin_client->walletpassphrase(wallet_password) )
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! importmulti
|
||||||
bitcoin_client->importmulti(address_or_script_array);
|
bitcoin_client->importmulti(address_or_script_array);
|
||||||
|
|
||||||
|
//! Lock wallet
|
||||||
|
bitcoin_client->walletlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue