mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
wallet2+cli+rpc: eliminate redundant m_http_client from cli/rpc and delegate calls to wallet2
This commit is contained in:
parent
71d186566e
commit
a7266d6d7b
5 changed files with 27 additions and 13 deletions
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue