aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/node_rpc_proxy.cpp37
-rw-r--r--src/wallet/node_rpc_proxy.h25
-rw-r--r--src/wallet/wallet2.cpp9
-rw-r--r--src/wallet/wallet2.h2
4 files changed, 58 insertions, 15 deletions
diff --git a/src/wallet/node_rpc_proxy.cpp b/src/wallet/node_rpc_proxy.cpp
index 1143a89d7..9f30e4ac5 100644
--- a/src/wallet/node_rpc_proxy.cpp
+++ b/src/wallet/node_rpc_proxy.cpp
@@ -48,6 +48,8 @@ NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::http_simple_client &http_clien
, 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)
{}
void NodeRPCProxy::invalidate()
@@ -60,9 +62,11 @@ void NodeRPCProxy::invalidate()
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;
}
-boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version)
+boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version) const
{
const time_t now = time(NULL);
if (m_rpc_version == 0)
@@ -84,7 +88,7 @@ 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)
+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
@@ -110,7 +114,32 @@ void NodeRPCProxy::set_height(uint64_t h)
m_height = h;
}
-boost::optional<std::string> NodeRPCProxy::get_earliest_height(uint8_t version, uint64_t &earliest_height)
+boost::optional<std::string> NodeRPCProxy::get_target_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
+ {
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_INFO::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_INFO::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
+
+ req_t.jsonrpc = "2.0";
+ req_t.id = epee::serialization::storage_entry(0);
+ req_t.method = "get_info";
+ m_daemon_rpc_mutex.lock();
+ bool r = net_utils::invoke_http_json("/json_rpc", req_t, resp_t, 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(resp_t.result.status != CORE_RPC_STATUS_BUSY, resp_t.result.status, "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(resp_t.result.status == CORE_RPC_STATUS_OK, resp_t.result.status, "Failed to get target blockchain height");
+ m_target_height = resp_t.result.target_height;
+ m_target_height_time = now;
+ }
+ height = m_target_height;
+ 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)
{
@@ -134,7 +163,7 @@ boost::optional<std::string> NodeRPCProxy::get_earliest_height(uint8_t version,
return boost::optional<std::string>();
}
-boost::optional<std::string> NodeRPCProxy::get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee)
+boost::optional<std::string> NodeRPCProxy::get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee) const
{
uint64_t height;
diff --git a/src/wallet/node_rpc_proxy.h b/src/wallet/node_rpc_proxy.h
index 02d1d8d93..fb288189a 100644
--- a/src/wallet/node_rpc_proxy.h
+++ b/src/wallet/node_rpc_proxy.h
@@ -43,23 +43,26 @@ public:
void invalidate();
- boost::optional<std::string> get_rpc_version(uint32_t &version);
- boost::optional<std::string> get_height(uint64_t &height);
+ boost::optional<std::string> get_rpc_version(uint32_t &version) const;
+ boost::optional<std::string> get_height(uint64_t &height) const;
void set_height(uint64_t h);
- boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height);
- boost::optional<std::string> get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee);
+ boost::optional<std::string> get_target_height(uint64_t &height) const;
+ boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height) const;
+ boost::optional<std::string> get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee) const;
private:
epee::net_utils::http::http_simple_client &m_http_client;
boost::mutex &m_daemon_rpc_mutex;
- uint64_t m_height;
- time_t m_height_time;
- uint64_t m_earliest_height[256];
- uint64_t m_dynamic_per_kb_fee_estimate;
- uint64_t m_dynamic_per_kb_fee_estimate_cached_height;
- uint64_t m_dynamic_per_kb_fee_estimate_grace_blocks;
- uint32_t m_rpc_version;
+ mutable uint64_t m_height;
+ mutable time_t m_height_time;
+ mutable uint64_t m_earliest_height[256];
+ mutable uint64_t m_dynamic_per_kb_fee_estimate;
+ mutable uint64_t m_dynamic_per_kb_fee_estimate_cached_height;
+ mutable uint64_t m_dynamic_per_kb_fee_estimate_grace_blocks;
+ mutable uint32_t m_rpc_version;
+ mutable uint64_t m_target_height;
+ mutable time_t m_target_height_time;
};
}
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index dfd45ce96..51c772d29 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -5711,6 +5711,15 @@ uint64_t wallet2::get_blockchain_height_by_date(uint16_t year, uint8_t month, ui
}
}
//----------------------------------------------------------------------------------------------------
+bool wallet2::is_synced() const
+{
+ uint64_t height;
+ boost::optional<std::string> result = m_node_rpc_proxy.get_target_height(height);
+ if (result && *result != CORE_RPC_STATUS_OK)
+ return false;
+ return get_blockchain_current_height() >= height;
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::generate_genesis(cryptonote::block& b) {
if (m_testnet)
{
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 62ab9c0b1..ba9abacf5 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -600,6 +600,8 @@ namespace tools
uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
+ bool is_synced() const;
+
private:
/*!
* \brief Stores wallet information to wallet file.