aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/api/wallet_manager.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-02 19:32:01 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-02 19:32:01 +0200
commit5fb3f97a55a9b8f31a69119c41557a9774deffb5 (patch)
treeabf27b7fd1bf7fc164ce91f5179dbddf899112db /src/wallet/api/wallet_manager.cpp
parentMerge pull request #1628 (diff)
parentUpdates to epee HTTP client code (diff)
downloadmonero-5fb3f97a55a9b8f31a69119c41557a9774deffb5.tar.xz
Merge pull request #1629
c02e1cb9 Updates to epee HTTP client code - http_simple_client now uses std::chrono for timeouts - http_simple_client accepts timeouts per connect / invoke call - shortened names of epee http invoke functions - invoke command functions only take relative path, connection is not automatically performed (Lee Clagett)
Diffstat (limited to 'src/wallet/api/wallet_manager.cpp')
-rw-r--r--src/wallet/api/wallet_manager.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index fcb39d1f3..c761cc6d2 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -43,6 +43,15 @@ namespace epee {
unsigned int g_test_dbg_lock_sleep = 0;
}
+namespace {
+ template<typename Request, typename Response>
+ bool connect_and_invoke(const std::string& address, const std::string& path, const Request& request, Response& response)
+ {
+ epee::net_utils::http::http_simple_client client{};
+ return client.set_server(address) && epee::net_utils::invoke_http_json(path, request, response, client);
+ }
+}
+
namespace Monero {
Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::string &password,
@@ -161,9 +170,7 @@ bool WalletManagerImpl::connected(uint32_t *version) const
req_t.jsonrpc = "2.0";
req_t.id = epee::serialization::storage_entry(0);
req_t.method = "get_version";
- epee::net_utils::http::http_simple_client http_client;
- bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/json_rpc", req_t, resp_t, http_client);
- if (!r)
+ if (!connect_and_invoke(m_daemonAddress, "/json_rpc", req_t, resp_t))
return false;
if (version)
@@ -209,8 +216,7 @@ bool WalletManagerImpl::checkPayment(const std::string &address_text, const std:
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request req;
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response res;
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(daemon_address + "/gettransactions", req, res, http_client) ||
+ if (!connect_and_invoke(m_daemonAddress, "/gettransactions", req, res) ||
(res.txs.size() != 1 && res.txs_as_hex.size() != 1))
{
error = tr("failed to get transaction from daemon");
@@ -328,8 +334,7 @@ uint64_t WalletManagerImpl::blockchainHeight() const
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/getinfo", ireq, ires, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/getinfo", ireq, ires))
return 0;
return ires.height;
}
@@ -339,8 +344,7 @@ uint64_t WalletManagerImpl::blockchainTargetHeight() const
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/getinfo", ireq, ires, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/getinfo", ireq, ires))
return 0;
return ires.target_height >= ires.height ? ires.target_height : ires.height;
}
@@ -350,8 +354,7 @@ uint64_t WalletManagerImpl::networkDifficulty() const
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/getinfo", ireq, ires, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/getinfo", ireq, ires))
return 0;
return ires.difficulty;
}
@@ -362,7 +365,7 @@ double WalletManagerImpl::miningHashRate() const
cryptonote::COMMAND_RPC_MINING_STATUS::response mres;
epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/mining_status", mreq, mres, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/mining_status", mreq, mres))
return 0.0;
if (!mres.active)
return 0.0;
@@ -382,7 +385,7 @@ void WalletManagerImpl::hardForkInfo(uint8_t &version, uint64_t &earliest_height
req_t.id = epee::serialization::storage_entry(0);
req_t.method = "hard_fork_info";
req_t.params.version = 0;
- bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/json_rpc", req_t, resp_t, http_client);
+ bool r = connect_and_invoke(m_daemonAddress, "/json_rpc", req_t, resp_t);
if (!r || resp_t.result.status != CORE_RPC_STATUS_OK)
return;
version = resp_t.result.version;
@@ -394,8 +397,7 @@ uint64_t WalletManagerImpl::blockTarget() const
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/getinfo", ireq, ires, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/getinfo", ireq, ires))
return 0;
return ires.target;
}
@@ -405,8 +407,7 @@ bool WalletManagerImpl::isMining() const
cryptonote::COMMAND_RPC_MINING_STATUS::request mreq;
cryptonote::COMMAND_RPC_MINING_STATUS::response mres;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/mining_status", mreq, mres, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/mining_status", mreq, mres))
return false;
return mres.active;
}
@@ -419,8 +420,7 @@ bool WalletManagerImpl::startMining(const std::string &address, uint32_t threads
mreq.miner_address = address;
mreq.threads_count = threads;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/start_mining", mreq, mres, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/start_mining", mreq, mres))
return false;
return mres.status == CORE_RPC_STATUS_OK;
}
@@ -430,8 +430,7 @@ bool WalletManagerImpl::stopMining()
cryptonote::COMMAND_RPC_STOP_MINING::request mreq;
cryptonote::COMMAND_RPC_STOP_MINING::response mres;
- epee::net_utils::http::http_simple_client http_client;
- if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/stop_mining", mreq, mres, http_client))
+ if (!connect_and_invoke(m_daemonAddress, "/stop_mining", mreq, mres))
return false;
return mres.status == CORE_RPC_STATUS_OK;
}