diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-12-07 19:40:12 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-12-07 19:40:12 +0000 |
commit | f7464343ea880fb071ccd39da821b1b80ec8a6cf (patch) | |
tree | f7c29118fe95b44a1edc037e169022428dc21eea /src/daemon | |
parent | Merge pull request #518 (diff) | |
download | monero-f7464343ea880fb071ccd39da821b1b80ec8a6cf.tar.xz |
daemon: add mining status to the status command
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 74dbc0012..686af69c2 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -247,11 +247,21 @@ bool t_rpc_command_executor::show_difficulty() { return true; } +static std::string get_mining_speed(uint64_t hr) +{ + if (hr>1e9) return (boost::format("%.2f GH/s") % (hr/1e9)).str(); + if (hr>1e6) return (boost::format("%.2f MH/s") % (hr/1e6)).str(); + if (hr>1e3) return (boost::format("%.2f kH/s") % (hr/1e3)).str(); + return (boost::format("%.0f H/s") % hr).str(); +} + bool t_rpc_command_executor::show_status() { cryptonote::COMMAND_RPC_GET_INFO::request ireq; cryptonote::COMMAND_RPC_GET_INFO::response ires; cryptonote::COMMAND_RPC_HARD_FORK_INFO::request hfreq; cryptonote::COMMAND_RPC_HARD_FORK_INFO::response hfres; + cryptonote::COMMAND_RPC_MINING_STATUS::request mreq; + cryptonote::COMMAND_RPC_MINING_STATUS::response mres; epee::json_rpc::error error_resp; std::string fail_message = "Problem fetching info"; @@ -266,6 +276,10 @@ bool t_rpc_command_executor::show_status() { { return true; } + if (!m_rpc_client->rpc_request(mreq, mres, "mining_status", fail_message.c_str())) + { + return true; + } } else { @@ -279,20 +293,20 @@ bool t_rpc_command_executor::show_status() { tools::fail_msg_writer() << fail_message.c_str(); return true; } + if (!m_rpc_server->on_mining_status(mreq, mres)) + { + tools::fail_msg_writer() << fail_message.c_str(); + return true; + } } - tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, net hash %s, v%u, %s, %u+%u connections") + tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, %s, net hash %s, v%u, %s, %u+%u connections") % (unsigned long long)ires.height % (unsigned long long)(ires.target_height >= ires.height ? ires.target_height : ires.height) % (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height)) % (ires.testnet ? "testnet" : "mainnet") - % [&ires]()->std::string { - float hr = ires.difficulty / ires.target; - if (hr>1e9) return (boost::format("%.2f GH/s") % (hr/1e9)).str(); - if (hr>1e6) return (boost::format("%.2f MH/s") % (hr/1e6)).str(); - if (hr>1e3) return (boost::format("%.2f kH/s") % (hr/1e3)).str(); - return (boost::format("%.0f H/s") % hr).str(); - }() + % (mres.active ? "mining at " + get_mining_speed(mres.speed) : "not mining") + % get_mining_speed(ires.difficulty / ires.target) % (unsigned)hfres.version % (hfres.state == cryptonote::HardFork::Ready ? "up to date" : hfres.state == cryptonote::HardFork::UpdateNeeded ? "update needed" : "out of date, likely forked") % (unsigned)ires.outgoing_connections_count % (unsigned)ires.incoming_connections_count |