diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-01-13 13:24:45 -0500 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-01-13 13:24:45 -0500 |
commit | 71c7577370d447f7aab7cda4afcdb3be6d7e5c53 (patch) | |
tree | dcf2a4870334fd2966d307e0ec61997fb6a77baf /src | |
parent | Merge pull request #1492 (diff) | |
parent | wallet2_api: add solo mining API (diff) | |
download | monero-71c7577370d447f7aab7cda4afcdb3be6d7e5c53.tar.xz |
Merge pull request #1513
a813ab50 wallet2_api: add solo mining API (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/api/wallet_manager.cpp | 38 | ||||
-rw-r--r-- | src/wallet/api/wallet_manager.h | 3 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 9 |
3 files changed, 49 insertions, 1 deletions
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index 6b48caf1d..48faa3183 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -346,7 +346,7 @@ double WalletManagerImpl::miningHashRate() const 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)) + if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/mining_status", mreq, mres, http_client)) return 0.0; if (!mres.active) return 0.0; @@ -384,6 +384,42 @@ uint64_t WalletManagerImpl::blockTarget() const return ires.target; } +bool WalletManagerImpl::isMining() 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 + "/mining_status", mreq, mres, http_client)) + return false; + return mres.active; +} + +bool WalletManagerImpl::startMining(const std::string &address, uint32_t threads) +{ + cryptonote::COMMAND_RPC_START_MINING::request mreq; + cryptonote::COMMAND_RPC_START_MINING::response mres; + + mreq.miner_address = address; + mreq.threads_count = threads; + + epee::net_utils::http::http_simple_client http_client; + if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/start_mining", mreq, mres, http_client)) + return false; + return mres.status == CORE_RPC_STATUS_OK; +} + +bool WalletManagerImpl::stopMining() +{ + cryptonote::COMMAND_RPC_STOP_MINING::request mreq; + cryptonote::COMMAND_RPC_STOP_MINING::response mres; + + epee::net_utils::http::http_simple_client http_client; + if (!epee::net_utils::invoke_http_json_remote_command2(m_daemonAddress + "/stop_mining", mreq, mres, http_client)) + return false; + return mres.status == CORE_RPC_STATUS_OK; +} + std::string WalletManagerImpl::resolveOpenAlias(const std::string &address, bool &dnssec_valid) const { std::vector<std::string> addresses = tools::dns_utils::addresses_from_url(address, dnssec_valid); diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h index 01752f69b..ca9570254 100644 --- a/src/wallet/api/wallet_manager.h +++ b/src/wallet/api/wallet_manager.h @@ -54,6 +54,9 @@ public: double miningHashRate() const; void hardForkInfo(uint8_t &version, uint64_t &earliest_height) const; uint64_t blockTarget() const; + bool isMining() const; + bool startMining(const std::string &address, uint32_t threads = 1); + bool stopMining(); std::string resolveOpenAlias(const std::string &address, bool &dnssec_valid) const; private: diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index fcb4ef2e8..9ad8c41ca 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -571,6 +571,15 @@ struct WalletManager //! returns current block target virtual uint64_t blockTarget() const = 0; + //! returns true iff mining + virtual bool isMining() const = 0; + + //! starts mining with the set number of threads + virtual bool startMining(const std::string &address, uint32_t threads = 1) = 0; + + //! stops mining + virtual bool stopMining() = 0; + //! resolves an OpenAlias address to a monero address virtual std::string resolveOpenAlias(const std::string &address, bool &dnssec_valid) const = 0; }; |