aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/daemon/command_parser_executor.cpp7
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp5
-rw-r--r--src/daemon/rpc_command_executor.cpp55
-rw-r--r--src/daemon/rpc_command_executor.h2
5 files changed, 71 insertions, 0 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 7b0f4a66b..51e3231e5 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -75,6 +75,13 @@ bool t_command_parser_executor::show_difficulty(const std::vector<std::string>&
return m_executor.show_difficulty();
}
+bool t_command_parser_executor::show_status(const std::vector<std::string>& args)
+{
+ if (!args.empty()) return false;
+
+ return m_executor.show_status();
+}
+
bool t_command_parser_executor::print_connections(const std::vector<std::string>& args)
{
if (!args.empty()) return false;
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index f900c72bd..f00fbd77e 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -63,6 +63,8 @@ public:
bool show_difficulty(const std::vector<std::string>& args);
+ bool show_status(const std::vector<std::string>& args);
+
bool print_connections(const std::vector<std::string>& args);
bool print_blockchain_info(const std::vector<std::string>& args);
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 446379558..8714b2569 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -135,6 +135,11 @@ t_command_server::t_command_server(
, "Show difficulty"
);
m_command_lookup.set_handler(
+ "status"
+ , std::bind(&t_command_parser_executor::show_status, &m_parser, p::_1)
+ , "Show status"
+ );
+ m_command_lookup.set_handler(
"stop_daemon"
, std::bind(&t_command_parser_executor::stop_daemon, &m_parser, p::_1)
, "Stop the daemon"
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index b0fe5945b..2ded96d81 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -33,6 +33,7 @@
#include "daemon/rpc_command_executor.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "cryptonote_core/cryptonote_core.h"
+#include "cryptonote_core/hardfork.h"
#include <boost/format.hpp>
#include <ctime>
#include <string>
@@ -246,6 +247,60 @@ bool t_rpc_command_executor::show_difficulty() {
return true;
}
+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;
+ epee::json_rpc::error error_resp;
+
+ std::string fail_message = "Problem fetching info";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
+ {
+ return true;
+ }
+ if (!m_rpc_client->rpc_request(hfreq, hfres, "/hard_fork_info", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_info(ireq, ires))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ if (!m_rpc_server->on_hard_fork_info(hfreq, hfres, error_resp))
+ {
+ 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")
+ % (unsigned long long)ires.height
+ % (unsigned long long)(ires.target_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))
+ % (m_rpc_server->is_testnet() ? "testnet" : "mainnet")
+ % [&ires]()->std::string {
+ float hr = ires.difficulty / 60.0f;
+ 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
+ % (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
+ ;
+
+ return true;
+}
+
bool t_rpc_command_executor::print_connections() {
cryptonote::COMMAND_RPC_GET_CONNECTIONS::request req;
cryptonote::COMMAND_RPC_GET_CONNECTIONS::response res;
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index 9ad849434..5df089be2 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -73,6 +73,8 @@ public:
bool show_difficulty();
+ bool show_status();
+
bool print_connections();
bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index);