30 #include <boost/algorithm/string.hpp>
36 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
37 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon"
41 namespace p = std::placeholders;
46 ,
const boost::optional<tools::login>& login
51 : m_parser(
ip,
port, login, ssl_options, is_rpc, rpc_server)
57 , std::bind(&t_command_server::help,
this, p::_1)
59 ,
"Show the help section or the documentation about a <command>."
64 ,
"Print the local blockchain height."
69 ,
"print_pl [white] [gray] [<limit>]"
70 ,
"Print the current peer list."
75 ,
"Print the peer list statistics."
80 ,
"Print the current connections."
85 ,
"Print network statistics."
90 ,
"print_bc <begin_height> [<end_height>]"
91 ,
"Print the blockchain info in a given blocks range."
96 ,
"print_block <block_hash> | <block_height>"
97 ,
"Print a given block."
102 ,
"print_tx <transaction_hash> [+hex] [+json]"
103 ,
"Print a given transaction."
108 ,
"is_key_image_spent <key_image>"
109 ,
"Print whether a given key image is in the spent key images set."
114 ,
"start_mining <addr> [<threads>|auto] [do_background_mining] [ignore_battery]"
115 ,
"Start mining for specified address. Defaults to 1 thread and no background mining. Use \"auto\" to autodetect optimal number of threads."
125 ,
"Show current mining status."
130 ,
"Print the transaction pool using a long format."
135 ,
"Print transaction pool using a short format."
140 ,
"Print the transaction pool's statistics."
145 ,
"Start showing the current hash rate."
150 ,
"Stop showing the hash rate."
155 ,
"Save the blockchain."
160 ,
"set_log <level>|<{+,-,}categories>"
161 ,
"Change the current log level/categories where <level> is a number 0-4."
166 ,
"Show the current difficulty."
171 ,
"Show the current status."
186 ,
"Print the current daemon status."
192 ,
"Get or set the download and upload limit."
197 ,
"limit_up [<kB/s>]"
198 ,
"Get or set the upload limit."
203 ,
"limit_down [<kB/s>]"
204 ,
"Get or set the download limit."
209 ,
"out_peers <max_number>"
210 ,
"Set the <max_number> of out peers."
215 ,
"in_peers <max_number>"
216 ,
"Set the <max_number> of in peers."
221 ,
"Start save data for dr electroneum"
226 ,
"Stop save data for dr electroneum"
231 ,
"Print the hard fork voting information."
236 ,
"Show the currently banned IPs."
241 ,
"ban <IP> [<seconds>]"
242 ,
"Ban a given <IP> for a given amount of <seconds>. Seconds = (-1) will result in a perm ban"
248 ,
"Unban a given <IP>."
253 ,
"flush_txpool [<txid>]"
254 ,
"Flush a transaction from the tx pool by its <txid>, or the whole tx pool."
259 ,
"output_histogram [@<amount>] <min_count> [<max_count>]"
260 ,
"Print the output histogram of outputs."
263 "print_coinbase_tx_sum"
265 ,
"print_coinbase_tx_sum <start_height> [<block_count>]"
266 ,
"Print the sum of coinbase transactions."
271 ,
"alt_chain_info [blockhash]"
272 ,
"Print the information about alternative chains."
277 ,
"bc_dyn_stats <last_block_count>"
278 ,
"Print the information about current blockchain dynamic state."
283 ,
"update (check|download)"
284 ,
"Check if an update is available, optionally downloads it if there is. Updating is not yet implemented."
290 ,
"Relay a given transaction by its <txid>."
295 ,
"Print information about the blockchain sync state."
300 ,
"pop_blocks <nblocks>"
301 ,
"Remove blocks from end of blockchain"
306 ,
"Print version information."
311 ,
"Prune the blockchain."
314 "check_blockchain_pruning"
316 ,
"Check the blockchain pruning."
321 ,
"Set validator private key to be used when signing mined blocks. <validator_key>"
324 "generate_ed25519_keypair"
326 ,
"Generate ED25519-Donna keypair."
331 ,
"Sign a message using ED25519-Donna private key. Usage: <private_key> <message>"
345 help(std::vector<std::string>());
352 if (m_is_rpc)
return false;
354 m_command_lookup.
start_handling(
"", get_commands_str(), exit_handler);
361 if (m_is_rpc)
return;
366 bool t_command_server::help(
const std::vector<std::string>& args)
370 std::cout << get_commands_str() << std::endl;
374 std::cout << get_command_usage(args) << std::endl;
381 std::stringstream ss;
383 ss <<
"Commands: " << std::endl;
385 boost::replace_all(usage,
"\n",
"\n ");
386 usage.insert(0,
" ");
387 ss << usage << std::endl;
391 std::string t_command_server::get_command_usage(
const std::vector<std::string> &args)
393 std::pair<std::string, std::string> documentation = m_command_lookup.
get_documentation(args);
394 std::stringstream ss;
395 if(documentation.first.empty())
397 ss <<
"Unknown command: " << args.front() << std::endl;
401 std::string usage = documentation.second.empty() ? args.front() : documentation.first;
402 std::string description = documentation.second.empty() ? documentation.first : documentation.second;
403 usage.insert(0,
" ");
404 ss <<
"Command usage: " << std::endl << usage << std::endl << std::endl;
405 boost::replace_all(description,
"\n",
"\n ");
406 description.insert(0,
" ");
407 ss <<
"Command description: " << std::endl << description << std::endl;
bool show_bans(const std::vector< std::string > &args)
bool alt_chain_info(const std::vector< std::string > &args)
bool print_transaction_pool_long(const std::vector< std::string > &args)
bool version(const std::vector< std::string > &args)
bool print_peer_list(const std::vector< std::string > &args)
bool prune_blockchain(const std::vector< std::string > &args)
bool update(const std::vector< std::string > &args)
bool print_blockchain_info(const std::vector< std::string > &args)
bool generate_ed25519_keypair(const std::vector< std::string > &args)
bool set_validator_key(const std::vector< std::string > &args)
bool print_height(const std::vector< std::string > &args)
bool relay_tx(const std::vector< std::string > &args)
bool sync_info(const std::vector< std::string > &args)
bool print_peer_list_stats(const std::vector< std::string > &args)
bool stop_save_graph(const std::vector< std::string > &args)
bool set_limit_up(const std::vector< std::string > &args)
bool pop_blocks(const std::vector< std::string > &args)
bool ban(const std::vector< std::string > &args)
bool flush_txpool(const std::vector< std::string > &args)
bool out_peers(const std::vector< std::string > &args)
bool print_coinbase_tx_sum(const std::vector< std::string > &args)
bool check_blockchain_pruning(const std::vector< std::string > &args)
bool start_save_graph(const std::vector< std::string > &args)
bool show_difficulty(const std::vector< std::string > &args)
bool print_transaction_pool_short(const std::vector< std::string > &args)
bool output_histogram(const std::vector< std::string > &args)
bool print_transaction(const std::vector< std::string > &args)
bool is_key_image_spent(const std::vector< std::string > &args)
bool in_peers(const std::vector< std::string > &args)
bool hide_hash_rate(const std::vector< std::string > &args)
bool print_net_stats(const std::vector< std::string > &args)
bool print_blockchain_dynamic_stats(const std::vector< std::string > &args)
bool set_limit(const std::vector< std::string > &args)
bool mining_status(const std::vector< std::string > &args)
bool show_hash_rate(const std::vector< std::string > &args)
bool unban(const std::vector< std::string > &args)
bool print_connections(const std::vector< std::string > &args)
bool stop_daemon(const std::vector< std::string > &args)
bool stop_mining(const std::vector< std::string > &args)
bool sign_message(const std::vector< std::string > &args)
bool print_status(const std::vector< std::string > &args)
bool print_transaction_pool_stats(const std::vector< std::string > &args)
bool save_blockchain(const std::vector< std::string > &args)
bool show_status(const std::vector< std::string > &args)
bool set_log_level(const std::vector< std::string > &args)
bool set_limit_down(const std::vector< std::string > &args)
bool hard_fork_info(const std::vector< std::string > &args)
bool print_block(const std::vector< std::string > &args)
bool start_mining(const std::vector< std::string > &args)
bool process_command_vec(const std::vector< std::string > &cmd)
bool process_command_str(const std::string &cmd)
bool start_handling(std::function< void(void)> exit_handler=NULL)
t_command_server(uint32_t ip, uint16_t port, const boost::optional< tools::login > &login, const epee::net_utils::ssl_options_t &ssl_options, bool is_rpc=true, cryptonote::core_rpc_server *rpc_server=NULL)
bool process_command_str(const std::string &cmd)
std::pair< std::string, std::string > get_documentation(const std::vector< std::string > &cmd)
bool process_command_vec(const std::vector< std::string > &cmd)
void set_handler(const std::string &cmd, const callback &hndlr, const std::string &usage="", const std::string &description="")
bool start_handling(std::function< std::string(void)> prompt, const std::string &usage_string="", std::function< void(void)> exit_handler=NULL)
boost::endian::big_uint16_t port
boost::endian::big_uint32_t ip
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL