aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/node_rpc_proxy.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-06-30 22:06:09 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-07-02 17:59:44 +0100
commit8c4db68ff71537759aac5dca50d5d8d1c6032d37 (patch)
treed6b5c3abfad688b72500b0de7f6f48d761eb362a /src/wallet/node_rpc_proxy.cpp
parentMerge pull request #4067 (diff)
downloadmonero-8c4db68ff71537759aac5dca50d5d8d1c6032d37.tar.xz
node_rpc_proxy: factor a few RPC calls using get_info
Takes advantage of caching
Diffstat (limited to '')
-rw-r--r--src/wallet/node_rpc_proxy.cpp72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/wallet/node_rpc_proxy.cpp b/src/wallet/node_rpc_proxy.cpp
index c5d869354..401ada61b 100644
--- a/src/wallet/node_rpc_proxy.cpp
+++ b/src/wallet/node_rpc_proxy.cpp
@@ -41,21 +41,13 @@ static const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::c
NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::http_simple_client &http_client, boost::mutex &mutex)
: m_http_client(http_client)
, m_daemon_rpc_mutex(mutex)
- , m_height(0)
- , m_height_time(0)
- , m_earliest_height()
- , m_dynamic_per_kb_fee_estimate(0)
- , m_dynamic_per_kb_fee_estimate_cached_height(0)
- , m_dynamic_per_kb_fee_estimate_grace_blocks(0)
- , m_rpc_version(0)
- , m_target_height(0)
- , m_target_height_time(0)
-{}
+{
+ invalidate();
+}
void NodeRPCProxy::invalidate()
{
m_height = 0;
- m_height_time = 0;
for (size_t n = 0; n < 256; ++n)
m_earliest_height[n] = 0;
m_dynamic_per_kb_fee_estimate = 0;
@@ -63,7 +55,8 @@ void NodeRPCProxy::invalidate()
m_dynamic_per_kb_fee_estimate_grace_blocks = 0;
m_rpc_version = 0;
m_target_height = 0;
- m_target_height_time = 0;
+ m_block_size_limit = 0;
+ m_get_info_time = 0;
}
boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version) const
@@ -84,36 +77,15 @@ boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version
return boost::optional<std::string>();
}
-boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height) const
-{
- const time_t now = time(NULL);
- if (m_height == 0 || now >= m_height_time + 30) // re-cache every 30 seconds
- {
- cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req);
- cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res);
-
- m_daemon_rpc_mutex.lock();
- bool r = net_utils::invoke_http_json("/getheight", req, res, m_http_client, rpc_timeout);
- m_daemon_rpc_mutex.unlock();
- CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
- CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, res.status, "Failed to connect to daemon");
- CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, res.status, "Failed to get current blockchain height");
- m_height = res.height;
- m_height_time = now;
- }
- height = m_height;
- return boost::optional<std::string>();
-}
-
void NodeRPCProxy::set_height(uint64_t h)
{
m_height = h;
}
-boost::optional<std::string> NodeRPCProxy::get_target_height(uint64_t &height) const
+boost::optional<std::string> NodeRPCProxy::get_info() const
{
const time_t now = time(NULL);
- if (m_target_height == 0 || now >= m_target_height_time + 30) // re-cache every 30 seconds
+ if (now >= m_get_info_time + 30) // re-cache every 30 seconds
{
cryptonote::COMMAND_RPC_GET_INFO::request req_t = AUTO_VAL_INIT(req_t);
cryptonote::COMMAND_RPC_GET_INFO::response resp_t = AUTO_VAL_INIT(resp_t);
@@ -125,13 +97,41 @@ boost::optional<std::string> NodeRPCProxy::get_target_height(uint64_t &height) c
CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
CHECK_AND_ASSERT_MES(resp_t.status != CORE_RPC_STATUS_BUSY, resp_t.status, "Failed to connect to daemon");
CHECK_AND_ASSERT_MES(resp_t.status == CORE_RPC_STATUS_OK, resp_t.status, "Failed to get target blockchain height");
+ m_height = resp_t.height;
m_target_height = resp_t.target_height;
- m_target_height_time = now;
+ m_block_size_limit = resp_t.block_size_limit;
+ m_get_info_time = now;
}
+ return boost::optional<std::string>();
+}
+
+boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height) const
+{
+ auto res = get_info();
+ if (res)
+ return res;
+ height = m_height;
+ return boost::optional<std::string>();
+}
+
+boost::optional<std::string> NodeRPCProxy::get_target_height(uint64_t &height) const
+{
+ auto res = get_info();
+ if (res)
+ return res;
height = m_target_height;
return boost::optional<std::string>();
}
+boost::optional<std::string> NodeRPCProxy::get_block_size_limit(uint64_t &block_size_limit) const
+{
+ auto res = get_info();
+ if (res)
+ return res;
+ block_size_limit = m_block_size_limit;
+ return boost::optional<std::string>();
+}
+
boost::optional<std::string> NodeRPCProxy::get_earliest_height(uint8_t version, uint64_t &earliest_height) const
{
if (m_earliest_height[version] == 0)