aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-12-04 22:17:48 +0200
committerRiccardo Spagni <ric@spagni.net>2016-12-04 22:17:48 +0200
commit836c7483661ed108e76e770fb6f52d8a2b7cc39e (patch)
treeb9a0efed63ee0b819ed293e49b539cc16824072c /src
parentMerge pull request #1386 (diff)
parentwallet_api: add a few daemon related getters (diff)
downloadmonero-836c7483661ed108e76e770fb6f52d8a2b7cc39e.tar.xz
Merge pull request #1388
fcd178ef wallet_api: add a few daemon related getters (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/wallet/api/wallet_manager.cpp65
-rw-r--r--src/wallet/api/wallet_manager.h8
-rw-r--r--src/wallet/wallet2_api.h17
3 files changed, 88 insertions, 2 deletions
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index 2d1c44d0e..25b081921 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -130,9 +130,26 @@ std::string WalletManagerImpl::errorString() const
return m_errorString;
}
-void WalletManagerImpl::setDaemonHost(const std::string &hostname)
+void WalletManagerImpl::setDaemonAddress(const std::string &address)
{
+ m_daemonAddress = address;
+}
+bool WalletManagerImpl::connected(uint32_t *version = NULL) const
+{
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_VERSION::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_VERSION::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_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)
+ return false;
+
+ if (version)
+ *version = resp_t.result.version;
+ return true;
}
bool WalletManagerImpl::checkPayment(const std::string &address_text, const std::string &txid_text, const std::string &txkey_text, const std::string &daemon_address, uint64_t &received, uint64_t &height, std::string &error) const
@@ -287,6 +304,52 @@ bool WalletManagerImpl::checkPayment(const std::string &address_text, const std:
return true;
}
+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))
+ return 0;
+ return ires.height;
+}
+
+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))
+ return 0;
+ return ires.target_height >= ires.height ? ires.target_height : ires.height;
+}
+
+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))
+ return 0;
+ return ires.difficulty;
+}
+
+double WalletManagerImpl::miningHashRate() 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 + "/getinfo", mreq, mres, http_client))
+ return 0.0;
+ if (!mres.active)
+ return 0.0;
+ return mres.speed;
+}
+
///////////////////// WalletManagerFactory implementation //////////////////////
WalletManager *WalletManagerFactory::getWalletManager()
diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h
index 489abe764..d454548f8 100644
--- a/src/wallet/api/wallet_manager.h
+++ b/src/wallet/api/wallet_manager.h
@@ -45,12 +45,18 @@ public:
bool walletExists(const std::string &path);
std::vector<std::string> findWallets(const std::string &path);
std::string errorString() const;
- void setDaemonHost(const std::string &hostname);
+ void setDaemonAddress(const std::string &address);
+ bool connected(uint32_t *version) const;
bool checkPayment(const std::string &address, const std::string &txid, const std::string &txkey, const std::string &daemon_address, uint64_t &received, uint64_t &height, std::string &error) const;
+ uint64_t blockchainHeight() const;
+ uint64_t blockchainTargetHeight() const;
+ uint64_t networkDifficulty() const;
+ double miningHashRate() const;
private:
WalletManagerImpl() {}
friend struct WalletManagerFactory;
+ std::string m_daemonAddress;
std::string m_errorString;
};
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index cc6c5a337..60907b436 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -487,6 +487,23 @@ struct WalletManager
//! returns verbose error string regarding last error;
virtual std::string errorString() const = 0;
+ //! set the daemon address (hostname and port)
+ virtual void setDaemonAddress(const std::string &address) = 0;
+
+ //! returns whether the daemon can be reached, and its version number
+ virtual bool connected(uint32_t *version = NULL) const = 0;
+
+ //! returns current blockchain height
+ virtual uint64_t blockchainHeight() const = 0;
+
+ //! returns current blockchain target height
+ virtual uint64_t blockchainTargetHeight() const = 0;
+
+ //! returns current network difficulty
+ virtual uint64_t networkDifficulty() const = 0;
+
+ //! returns current mining hash rate (0 if not mining)
+ virtual double miningHashRate() const = 0;
};