2014-03-04 00:07:58 +02:00
# pragma once
2014-06-20 02:02:22 +03:00
//#include "cryptonote_core/cryptonote_core.h"
//#include "cryptonote_protocol/cryptonote_protocol_handler.h"
//#include "p2p/net_node.h"
//#include <functional>
//#include <boost/algorithm/string.hpp>
# include "misc_log_ex.h"
2014-06-13 17:47:57 +03:00
# include "cryptonote_core/cryptonote_core.h"
2014-03-04 00:07:58 +02:00
# include "cryptonote_protocol/cryptonote_protocol_handler.h"
2014-06-20 21:49:43 +03:00
# include "daemon/interactive_command_executor.h"
2014-06-20 02:02:22 +03:00
# include "daemon/command_parser_executor.h"
2014-06-17 23:46:41 +03:00
# include "p2p/net_node.h"
namespace daemonize {
2014-03-04 00:07:58 +02:00
2014-06-17 23:46:41 +03:00
namespace p = std : : placeholders ;
using namespace epee ;
2014-03-04 00:07:58 +02:00
2014-06-17 23:46:41 +03:00
class t_command_server {
private :
2014-06-20 02:02:22 +03:00
t_command_parser_executor m_parser ;
2014-06-20 21:49:43 +03:00
command_handler m_command_lookup ;
2014-06-17 23:46:41 +03:00
public :
2014-06-20 02:02:22 +03:00
typedef nodetool : : node_server < cryptonote : : t_cryptonote_protocol_handler < cryptonote : : core > > t_node_server ;
t_command_server (
t_node_server & node_server
) :
2014-06-20 21:49:43 +03:00
m_parser ( new t_interactive_command_executor ( node_server ) )
, m_command_lookup ( )
2014-06-17 23:46:41 +03:00
{
2014-06-20 21:49:43 +03:00
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 <begin_height> [<end_height>] " ) ;
m_command_lookup . set_handler ( " print_block " , std : : bind ( & t_command_parser_executor : : print_block , & m_parser , p : : _1 ) , " Print block, print_block <block_hash> | <block_height> " ) ;
m_command_lookup . set_handler ( " print_tx " , std : : bind ( & t_command_parser_executor : : print_transaction , & m_parser , p : : _1 ) , " Print transaction, print_tx <transaction_hash> " ) ;
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 <addr> [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 <level> - Change current log detalization level, <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 " ) ;
2014-06-17 23:46:41 +03:00
}
bool process_command ( const std : : string & cmd )
{
2014-06-20 21:49:43 +03:00
return m_command_lookup . process_command_str ( cmd ) ;
2014-06-17 23:46:41 +03:00
}
private :
bool help ( const std : : vector < std : : string > & args )
{
2014-06-18 00:36:07 +03:00
std : : cout < < get_commands_str ( ) < < std : : endl ;
2014-06-17 23:46:41 +03:00
return true ;
}
std : : string get_commands_str ( )
{
std : : stringstream ss ;
2014-06-18 00:36:07 +03:00
ss < < CRYPTONOTE_NAME < < " v " < < PROJECT_VERSION_LONG < < std : : endl ;
ss < < " Commands: " < < std : : endl ;
2014-06-20 21:49:43 +03:00
std : : string usage = m_command_lookup . get_usage ( ) ;
2014-06-17 23:46:41 +03:00
boost : : replace_all ( usage , " \n " , " \n " ) ;
usage . insert ( 0 , " " ) ;
2014-06-18 00:36:07 +03:00
ss < < usage < < std : : endl ;
2014-06-17 23:46:41 +03:00
return ss . str ( ) ;
}
} ;
} // namespace daemonize