aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Brydolf <jacob@brydolf.net>2016-10-03 20:47:41 +0200
committerJacob Brydolf <jacob@brydolf.net>2016-10-03 20:47:41 +0200
commit65ea8364f894929be24e5753388296f14d9704c8 (patch)
tree5518fdd227ae281c83fa28268bbec85a3038ed4e /src
parentMerge pull request #1124 (diff)
downloadmonero-65ea8364f894929be24e5753388296f14d9704c8.tar.xz
wallet2_api: added Wallet::daemonBlockChainTargetHeight()
libwallet_api: Wallet::blockChainTargetHeight Signed-off-by: Jacob Brydolf <jacob@brydolf.net>
Diffstat (limited to 'src')
-rw-r--r--src/wallet/api/wallet.cpp17
-rw-r--r--src/wallet/api/wallet.h1
-rw-r--r--src/wallet/wallet2.cpp32
-rw-r--r--src/wallet/wallet2.h1
-rw-r--r--src/wallet/wallet2_api.h6
5 files changed, 57 insertions, 0 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index eefb49e95..5afad15c7 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -441,6 +441,23 @@ uint64_t WalletImpl::daemonBlockChainHeight() const
return result;
}
+uint64_t WalletImpl::daemonBlockChainTargetHeight() const
+{
+ std::string err;
+ uint64_t result = m_wallet->get_daemon_blockchain_target_height(err);
+ if (!err.empty()) {
+ LOG_ERROR(__FUNCTION__ << ": " << err);
+ result = 0;
+ m_errorString = err;
+ m_status = Status_Error;
+
+ } else {
+ m_status = Status_Ok;
+ m_errorString = "";
+ }
+ return result;
+}
+
bool WalletImpl::refresh()
{
clearStatus();
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index d97a8f3b3..3d27fbc4d 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -77,6 +77,7 @@ public:
uint64_t unlockedBalance() const;
uint64_t blockChainHeight() const;
uint64_t daemonBlockChainHeight() const;
+ uint64_t daemonBlockChainTargetHeight() const;
bool refresh();
void refreshAsync();
void setAutoRefreshInterval(int millis);
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index ed4ab93de..6d977b538 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -4085,6 +4085,38 @@ uint64_t wallet2::get_daemon_blockchain_height(string &err)
return res.height;
}
+uint64_t wallet2::get_daemon_blockchain_target_height(string &err)
+{
+ 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);
+ m_daemon_rpc_mutex.lock();
+ req_t.jsonrpc = "2.0";
+ req_t.id = epee::serialization::storage_entry(0);
+ req_t.method = "get_info";
+ bool ok = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
+ m_daemon_rpc_mutex.unlock();
+ if (ok)
+ {
+ if (resp_t.result.status == CORE_RPC_STATUS_BUSY)
+ {
+ err = "daemon is busy. Please try again later.";
+ }
+ else if (resp_t.result.status != CORE_RPC_STATUS_OK)
+ {
+ err = resp_t.result.status;
+ }
+ else // success, cleaning up error message
+ {
+ err = "";
+ }
+ }
+ else
+ {
+ err = "possibly lost connection to daemon";
+ }
+ return resp_t.result.target_height;
+}
+
void wallet2::set_tx_note(const crypto::hash &txid, const std::string &note)
{
m_tx_notes[txid] = note;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index dd7cd19dc..737a5a9ec 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -401,6 +401,7 @@ namespace tools
std::string get_keys_file() const;
std::string get_daemon_address() const;
uint64_t get_daemon_blockchain_height(std::string& err);
+ uint64_t get_daemon_blockchain_target_height(std::string& err);
std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool trusted_daemon);
std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index 08e2ae16b..8d5223006 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -248,6 +248,12 @@ struct Wallet
*/
virtual uint64_t daemonBlockChainHeight() const = 0;
+ /**
+ * @brief daemonBlockChainTargetHeight - returns daemon blockchain target height
+ * @return 0 - in case error communicating with the daemon.
+ * status() will return Status_Error and errorString() will return verbose error description
+ */
+ virtual uint64_t daemonBlockChainTargetHeight() const = 0;
static std::string displayAmount(uint64_t amount);
static uint64_t amountFromString(const std::string &amount);