aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/simplewallet/simplewallet.cpp11
-rw-r--r--src/simplewallet/simplewallet.h1
-rw-r--r--src/wallet/wallet2.h19
-rw-r--r--src/wallet/wallet_rpc_server.cpp8
-rw-r--r--src/wallet/wallet_rpc_server.h1
5 files changed, 27 insertions, 13 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 3668df7b9..93221c2bd 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -2683,7 +2683,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
if (!m_trusted_daemon)
message_writer() << (boost::format(tr("Warning: using an untrusted daemon at %s, privacy will be lessened")) % m_wallet->get_daemon_address()).str();
- m_http_client.set_server(m_wallet->get_daemon_address(), m_wallet->get_daemon_login());
m_wallet->callback(this);
return true;
@@ -3216,7 +3215,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
}
COMMAND_RPC_START_MINING::response res;
- bool r = net_utils::invoke_http_json("/start_mining", req, res, m_http_client);
+ bool r = m_wallet->invoke_http_json("/start_mining", req, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining started in daemon");
@@ -3238,7 +3237,7 @@ bool simple_wallet::stop_mining(const std::vector<std::string>& args)
COMMAND_RPC_STOP_MINING::request req;
COMMAND_RPC_STOP_MINING::response res;
- bool r = net_utils::invoke_http_json("/stop_mining", req, res, m_http_client);
+ bool r = m_wallet->invoke_http_json("/stop_mining", req, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining stopped in daemon");
@@ -3295,7 +3294,7 @@ bool simple_wallet::save_bc(const std::vector<std::string>& args)
}
COMMAND_RPC_SAVE_BC::request req;
COMMAND_RPC_SAVE_BC::response res;
- bool r = net_utils::invoke_http_json("/save_bc", req, res, m_http_client);
+ bool r = m_wallet->invoke_http_json("/save_bc", req, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Blockchain saved");
@@ -3641,7 +3640,7 @@ uint64_t simple_wallet::get_daemon_blockchain_height(std::string& err)
COMMAND_RPC_GET_HEIGHT::request req;
COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>();
- bool r = net_utils::invoke_http_json("/getheight", req, res, m_http_client);
+ bool r = m_wallet->invoke_http_json("/getheight", req, res);
err = interpret_rpc_response(r, res.status);
return res.height;
}
@@ -3763,7 +3762,7 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending
req.outputs[j].index = absolute_offsets[j];
}
COMMAND_RPC_GET_OUTPUTS_BIN::response res = AUTO_VAL_INIT(res);
- bool r = net_utils::invoke_http_bin("/get_outs.bin", req, res, m_http_client);
+ bool r = m_wallet->invoke_http_bin("/get_outs.bin", req, res);
err = interpret_rpc_response(r, res.status);
if (!err.empty())
{
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 4c7818bf1..6f344439e 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -328,7 +328,6 @@ namespace cryptonote
epee::console_handlers_binder m_cmd_binder;
std::unique_ptr<tools::wallet2> m_wallet;
- epee::net_utils::http::http_simple_client m_http_client;
refresh_progress_reporter_t m_refresh_progress_reporter;
std::atomic<bool> m_idle_run;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 9accc65ca..d2e484e05 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1027,6 +1027,25 @@ namespace tools
crypto::public_key get_multisig_signing_public_key(size_t idx) const;
crypto::public_key get_multisig_signing_public_key(const crypto::secret_key &skey) const;
+ template<class t_request, class t_response>
+ inline bool invoke_http_json(const boost::string_ref uri, const t_request& req, t_response& res, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET")
+ {
+ boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
+ return epee::net_utils::invoke_http_json(uri, req, res, m_http_client, timeout, http_method);
+ }
+ template<class t_request, class t_response>
+ inline bool invoke_http_bin(const boost::string_ref uri, const t_request& req, t_response& res, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET")
+ {
+ boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
+ return epee::net_utils::invoke_http_bin(uri, req, res, m_http_client, timeout, http_method);
+ }
+ template<class t_request, class t_response>
+ inline bool invoke_http_json_rpc(const boost::string_ref uri, const std::string& method_name, const t_request& req, t_response& res, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET", const std::string& req_id = "0")
+ {
+ boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
+ return epee::net_utils::invoke_http_json_rpc(uri, method_name, req, res, m_http_client, timeout, http_method, req_id);
+ }
+
private:
/*!
* \brief Stores wallet information to wallet file.
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 220dbbc58..70874c65a 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -229,8 +229,6 @@ namespace tools
assert(bool(http_login));
} // end auth enabled
- m_http_client.set_server(walvars->get_daemon_address(), walvars->get_daemon_login());
-
m_net_server.set_threads_prefix("RPC");
auto rng = [](size_t len, uint8_t *ptr) { return crypto::rand(len, ptr); };
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
@@ -2257,7 +2255,7 @@ namespace tools
daemon_req.ignore_battery = req.ignore_battery;
cryptonote::COMMAND_RPC_START_MINING::response daemon_res;
- bool r = net_utils::invoke_http_json("/start_mining", daemon_req, daemon_res, m_http_client);
+ bool r = m_wallet->invoke_http_json("/start_mining", daemon_req, daemon_res);
if (!r || daemon_res.status != CORE_RPC_STATUS_OK)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
@@ -2271,7 +2269,7 @@ namespace tools
{
cryptonote::COMMAND_RPC_STOP_MINING::request daemon_req;
cryptonote::COMMAND_RPC_STOP_MINING::response daemon_res;
- bool r = net_utils::invoke_http_json("/stop_mining", daemon_req, daemon_res, m_http_client);
+ bool r = m_wallet->invoke_http_json("/stop_mining", daemon_req, daemon_res);
if (!r || daemon_res.status != CORE_RPC_STATUS_OK)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
@@ -2351,7 +2349,7 @@ namespace tools
cryptonote::COMMAND_RPC_GET_HEIGHT::request hreq;
cryptonote::COMMAND_RPC_GET_HEIGHT::response hres;
hres.height = 0;
- bool r = net_utils::invoke_http_json("/getheight", hreq, hres, m_http_client);
+ bool r = wal->invoke_http_json("/getheight", hreq, hres);
wal->set_refresh_from_block_height(hres.height);
crypto::secret_key dummy_key;
try {
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index bb458aa99..63e886dda 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -224,7 +224,6 @@ namespace tools
tools::private_file rpc_login_file;
std::atomic<bool> m_stop;
bool m_trusted_daemon;
- epee::net_utils::http::http_simple_client m_http_client;
const boost::program_options::variables_map *m_vm;
};
}