diff options
author | Riccardo Spagni <ric@spagni.net> | 2015-12-08 20:11:27 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2015-12-08 20:11:30 +0200 |
commit | 45191c3b303c966db2ccbea0a50bc00e82a5e995 (patch) | |
tree | 2f06902f5db1869d99753e359a137ddf82be267b /src | |
parent | Merge pull request #524 (diff) | |
parent | daemon: add mining status to the status command (diff) | |
download | monero-45191c3b303c966db2ccbea0a50bc00e82a5e995.tar.xz |
Merge pull request #525
f746434 daemon: add mining status to the status command (moneromooo-monero)
Diffstat (limited to 'src')
-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 |