daemon: add mining status to the status command

This commit is contained in:
moneromooo-monero 2015-12-07 19:40:12 +00:00
parent 0252ffc37b
commit f7464343ea
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

View File

@ -247,11 +247,21 @@ bool t_rpc_command_executor::show_difficulty() {
return true; 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() { bool t_rpc_command_executor::show_status() {
cryptonote::COMMAND_RPC_GET_INFO::request ireq; cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires; cryptonote::COMMAND_RPC_GET_INFO::response ires;
cryptonote::COMMAND_RPC_HARD_FORK_INFO::request hfreq; cryptonote::COMMAND_RPC_HARD_FORK_INFO::request hfreq;
cryptonote::COMMAND_RPC_HARD_FORK_INFO::response hfres; 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; epee::json_rpc::error error_resp;
std::string fail_message = "Problem fetching info"; std::string fail_message = "Problem fetching info";
@ -266,6 +276,10 @@ bool t_rpc_command_executor::show_status() {
{ {
return true; return true;
} }
if (!m_rpc_client->rpc_request(mreq, mres, "mining_status", fail_message.c_str()))
{
return true;
}
} }
else else
{ {
@ -279,20 +293,20 @@ bool t_rpc_command_executor::show_status() {
tools::fail_msg_writer() << fail_message.c_str(); tools::fail_msg_writer() << fail_message.c_str();
return true; 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.height
% (unsigned long long)(ires.target_height >= ires.height ? ires.target_height : 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)) % (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height))
% (ires.testnet ? "testnet" : "mainnet") % (ires.testnet ? "testnet" : "mainnet")
% [&ires]()->std::string { % (mres.active ? "mining at " + get_mining_speed(mres.speed) : "not mining")
float hr = ires.difficulty / ires.target; % get_mining_speed(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();
}()
% (unsigned)hfres.version % (unsigned)hfres.version
% (hfres.state == cryptonote::HardFork::Ready ? "up to date" : hfres.state == cryptonote::HardFork::UpdateNeeded ? "update needed" : "out of date, likely forked") % (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 % (unsigned)ires.outgoing_connections_count % (unsigned)ires.incoming_connections_count