#pragma once //#include "cryptonote_core/cryptonote_core.h" //#include "cryptonote_protocol/cryptonote_protocol_handler.h" //#include "p2p/net_node.h" //#include //#include #include "misc_log_ex.h" #include "cryptonote_core/cryptonote_core.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h" #include "daemon/interactive_command_executor.h" #include "daemon/command_parser_executor.h" #include "p2p/net_node.h" namespace daemonize { namespace p = std::placeholders; using namespace epee; class t_command_server { private: t_command_parser_executor m_parser; command_handler m_command_lookup; public: typedef nodetool::node_server > t_node_server; t_command_server( t_node_server & node_server ) : m_parser(new t_interactive_command_executor(node_server)) , m_command_lookup() { m_command_lookup.set_handler("help", std::bind(&t_command_server::help, this, p::_1), "Show this help"); m_command_lookup.set_handler("print_pl", std::bind(&t_command_parser_executor::print_peer_list, &m_parser, p::_1), "Print peer list"); m_command_lookup.set_handler("print_cn", std::bind(&t_command_parser_executor::print_connections, &m_parser, p::_1), "Print connections"); m_command_lookup.set_handler("print_bc", std::bind(&t_command_parser_executor::print_blockchain_info, &m_parser, p::_1), "Print blockchain info in a given blocks range, print_bc []"); m_command_lookup.set_handler("print_block", std::bind(&t_command_parser_executor::print_block, &m_parser, p::_1), "Print block, print_block | "); m_command_lookup.set_handler("print_tx", std::bind(&t_command_parser_executor::print_transaction, &m_parser, p::_1), "Print transaction, print_tx "); m_command_lookup.set_handler("start_mining", std::bind(&t_command_parser_executor::start_mining, &m_parser, p::_1), "Start mining for specified address, start_mining [threads=1]"); m_command_lookup.set_handler("stop_mining", std::bind(&t_command_parser_executor::stop_mining, &m_parser, p::_1), "Stop mining"); m_command_lookup.set_handler("print_pool", std::bind(&t_command_parser_executor::print_transaction_pool_long, &m_parser, p::_1), "Print transaction pool (long format)"); m_command_lookup.set_handler("print_pool_sh", std::bind(&t_command_parser_executor::print_transaction_pool_short, &m_parser, p::_1), "Print transaction pool (short format)"); m_command_lookup.set_handler("show_hr", std::bind(&t_command_parser_executor::show_hash_rate, &m_parser, p::_1), "Start showing hash rate"); m_command_lookup.set_handler("hide_hr", std::bind(&t_command_parser_executor::hide_hash_rate, &m_parser, p::_1), "Stop showing hash rate"); m_command_lookup.set_handler("save", std::bind(&t_command_parser_executor::save_blockchain, &m_parser, p::_1), "Save blockchain"); m_command_lookup.set_handler("set_log", std::bind(&t_command_parser_executor::set_log_level, &m_parser, p::_1), "set_log - Change current log detalization level, is a number 0-4"); m_command_lookup.set_handler("diff", std::bind(&t_command_parser_executor::show_difficulty, &m_parser, p::_1), "Show difficulty"); } bool process_command(const std::string& cmd) { return m_command_lookup.process_command_str(cmd); } private: bool help(const std::vector& args) { std::cout << get_commands_str() << std::endl; return true; } std::string get_commands_str() { std::stringstream ss; ss << CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << std::endl; ss << "Commands: " << std::endl; std::string usage = m_command_lookup.get_usage(); boost::replace_all(usage, "\n", "\n "); usage.insert(0, " "); ss << usage << std::endl; return ss.str(); } }; } // namespace daemonize