diff options
author | Ilya Kitaev <mbg033@gmail.com> | 2016-09-26 21:35:00 +0300 |
---|---|---|
committer | Ilya Kitaev <mbg033@gmail.com> | 2016-09-26 23:19:25 +0300 |
commit | 7b4a85b309aa0fb864d63a2fd6f1ae062aaa71dd (patch) | |
tree | bd7c073734e9de7b2326ded18bfda73557aaa9eb /src/wallet | |
parent | libwallet_api: Wallet::blockChainHeight, WalletListener::newBlock (diff) | |
download | monero-7b4a85b309aa0fb864d63a2fd6f1ae062aaa71dd.tar.xz |
wallet2_api: added Wallet::daemonBlockChainHeight()
Diffstat (limited to '')
-rw-r--r-- | src/wallet/api/wallet.cpp | 15 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 5 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 30 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 1 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 10 |
5 files changed, 57 insertions, 4 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index eef956e80..986deca1f 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -422,6 +422,21 @@ uint64_t WalletImpl::blockChainHeight() const return m_wallet->get_blockchain_current_height(); } +uint64_t WalletImpl::daemonBlockChainHeight() const +{ + std::string err; + uint64_t result = m_wallet->get_daemon_blockchain_height(err); + if (!err.empty()) { + LOG_ERROR(__FUNCTION__ << ": " << err); + 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 1a34a04fd..03801edac 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -76,6 +76,7 @@ public: uint64_t balance() const; uint64_t unlockedBalance() const; uint64_t blockChainHeight() const; + uint64_t daemonBlockChainHeight() const; bool refresh(); void refreshAsync(); void setAutoRefreshInterval(int seconds); @@ -106,8 +107,8 @@ private: friend class TransactionHistoryImpl; tools::wallet2 * m_wallet; - std::atomic<int> m_status; - std::string m_errorString; + mutable std::atomic<int> m_status; + mutable std::string m_errorString; std::string m_password; TransactionHistoryImpl * m_history; bool m_trustedDaemon; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 3d4f93aff..07b305b4c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4050,7 +4050,35 @@ std::string wallet2::get_keys_file() const std::string wallet2::get_daemon_address() const { - return m_daemon_address; + return m_daemon_address; +} + +uint64_t wallet2::get_daemon_blockchain_height(string &err) +{ + // XXX: DRY violation. copy-pasted from simplewallet.cpp:get_daemon_blockchain_height() + // consider to move it from simplewallet to wallet2 ? + COMMAND_RPC_GET_HEIGHT::request req; + COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>(); + m_daemon_rpc_mutex.lock(); + bool ok = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, m_http_client); + m_daemon_rpc_mutex.unlock(); + // XXX: DRY violation. copy-pasted from simplewallet.cpp:interpret_rpc_response() + if (ok) + { + if (res.status == CORE_RPC_STATUS_BUSY) + { + err = "daemon is busy. Please try again later."; + } + else if (res.status != CORE_RPC_STATUS_OK) + { + err = res.status; + } + } + else + { + err = "possibly lost connection to daemon"; + } + return res.height; } void wallet2::set_tx_note(const crypto::hash &txid, const std::string ¬e) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 89b613d34..dd7cd19dc 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -400,6 +400,7 @@ namespace tools std::string get_wallet_file() const; std::string get_keys_file() const; std::string get_daemon_address() const; + uint64_t get_daemon_blockchain_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 08f010b32..f424f7258 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -236,11 +236,19 @@ struct Wallet virtual uint64_t unlockedBalance() const = 0; /** - * @brief getBlockChainHeight - returns current blockchain height + * @brief blockChainHeight - returns current blockchain height * @return */ virtual uint64_t blockChainHeight() const = 0; + /** + * @brief daemonBlockChainHeight - returns daemon blockchain 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 daemonBlockChainHeight() const = 0; + + static std::string displayAmount(uint64_t amount); static uint64_t amountFromString(const std::string &amount); static uint64_t amountFromDouble(double amount); |