From 4a4e3cde947ea416a40e0be5fd5828275ad1f826 Mon Sep 17 00:00:00 2001 From: Neozaru Date: Sat, 5 Jul 2014 15:05:01 +0200 Subject: [PATCH] Added 'print_height' daemon command --- src/daemon/command_parser_executor.cpp | 7 +++++++ src/daemon/command_parser_executor.h | 2 ++ src/daemon/command_server.cpp | 5 +++++ src/daemon/rpc_command_executor.cpp | 12 ++++++++++++ src/daemon/rpc_command_executor.h | 3 +++ 5 files changed, 29 insertions(+) diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 130e253a6..a80469fa0 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -99,6 +99,13 @@ bool t_command_parser_executor::set_log_level(const std::vector& ar return m_executor.set_log_level(l); } +bool t_command_parser_executor::print_height(const std::vector& args) +{ + if (!args.empty()) return false; + + return m_executor.print_height(); +} + bool t_command_parser_executor::print_block(const std::vector& args) { if (args.empty()) diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index ae0c46090..1b7572dee 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -30,6 +30,8 @@ public: bool set_log_level(const std::vector& args); + bool print_height(const std::vector& args); + bool print_block(const std::vector& args); bool print_transaction(const std::vector& args); diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index 0c8203d19..3b94333f3 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -18,6 +18,11 @@ t_command_server::t_command_server( , std::bind(&t_command_server::help, this, p::_1) , "Show this help" ); + m_command_lookup.set_handler( + "print_height" + , std::bind(&t_command_parser_executor::print_height, &m_parser, p::_1) + , "Print local blockchain height" + ); m_command_lookup.set_handler( "print_pl" , std::bind(&t_command_parser_executor::print_peer_list, &m_parser, p::_1) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index b8a792289..cac7c324a 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -189,6 +189,18 @@ bool t_rpc_command_executor::set_log_level(int8_t level) { return true; } +bool t_rpc_command_executor::print_height() { + cryptonote::COMMAND_RPC_GET_HEIGHT::request req; + cryptonote::COMMAND_RPC_GET_HEIGHT::response res; + + if (rpc_request(req, res, "/getheight", "Unsuccessful")) + { + tools::success_msg_writer() << boost::lexical_cast(res.height); + } + + return true; +} + bool t_rpc_command_executor::print_block_by_hash(crypto::hash block_hash) { cryptonote::COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request req; cryptonote::COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response res; diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index eec2499f8..acb4c0075 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -34,6 +34,8 @@ public: bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index); bool set_log_level(int8_t level); + + bool print_height(); bool print_block_by_hash(crypto::hash block_hash); @@ -51,6 +53,7 @@ public: bool stop_daemon(); + private: template bool json_rpc_request(