mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
Remove interactive console commands
This commit is contained in:
parent
80bd4594f4
commit
c1038f7e3e
@ -1,67 +1,58 @@
|
||||
#include "cryptonote_core/cryptonote_basic_impl.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
#include "daemon/interactive_command_executor.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_peer_list(const std::vector<std::string>& args)
|
||||
t_command_parser_executor::t_command_parser_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
)
|
||||
: m_executor(ip, port)
|
||||
{}
|
||||
|
||||
bool t_command_parser_executor::print_peer_list(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_peer_list();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
save_blockchain(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::save_blockchain(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.save_blockchain();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
show_hash_rate(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::show_hash_rate(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.show_hash_rate();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
hide_hash_rate(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::hide_hash_rate(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.hide_hash_rate();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
show_difficulty(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::show_difficulty(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.show_difficulty();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_connections(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::print_connections(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_connections();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_blockchain_info(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::print_blockchain_info(const std::vector<std::string>& args)
|
||||
{
|
||||
if(!args.size())
|
||||
{
|
||||
@ -84,9 +75,7 @@ print_blockchain_info(const std::vector<std::string>& args)
|
||||
return m_executor.print_blockchain_info(start_index, end_index);
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
set_log_level(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::set_log_level(const std::vector<std::string>& args)
|
||||
{
|
||||
if(args.size() != 1)
|
||||
{
|
||||
@ -110,9 +99,7 @@ set_log_level(const std::vector<std::string>& args)
|
||||
return m_executor.set_log_level(l);
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_block(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::print_block(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
@ -138,9 +125,7 @@ print_block(const std::vector<std::string>& args)
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_transaction(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::print_transaction(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
@ -158,27 +143,21 @@ print_transaction(const std::vector<std::string>& args)
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_transaction_pool_long(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::print_transaction_pool_long(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_transaction_pool_long();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
print_transaction_pool_short(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::print_transaction_pool_short(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_transaction_pool_short();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
start_mining(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::start_mining(const std::vector<std::string>& args)
|
||||
{
|
||||
if(!args.size())
|
||||
{
|
||||
@ -208,25 +187,18 @@ start_mining(const std::vector<std::string>& args)
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
stop_mining(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::stop_mining(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.stop_mining();
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_parser_executor<T_command_executor>::
|
||||
stop_daemon(const std::vector<std::string>& args)
|
||||
bool t_command_parser_executor::stop_daemon(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.stop_daemon();
|
||||
}
|
||||
|
||||
template class t_command_parser_executor<t_interactive_command_executor>;
|
||||
template class t_command_parser_executor<t_rpc_command_executor>;
|
||||
|
||||
} // namespace daemonize
|
||||
|
@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
template <typename T_command_executor>
|
||||
class t_command_parser_executor final
|
||||
{
|
||||
private:
|
||||
T_command_executor m_executor;
|
||||
t_rpc_command_executor m_executor;
|
||||
public:
|
||||
t_command_parser_executor(T_command_executor && executor) :
|
||||
t_command_parser_executor(t_rpc_command_executor && executor) :
|
||||
m_executor(std::move(executor))
|
||||
{}
|
||||
|
||||
|
@ -1,123 +1,117 @@
|
||||
#include "cryptonote_config.h"
|
||||
#include "version.h"
|
||||
#include "daemon/command_server.h"
|
||||
#include "daemon/interactive_command_executor.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
namespace p = std::placeholders;
|
||||
|
||||
template <typename T_command_executor>
|
||||
t_command_server<T_command_executor>::t_command_server(
|
||||
T_command_executor && executor
|
||||
t_command_server::t_command_server(
|
||||
t_rpc_command_executor && executor
|
||||
) :
|
||||
m_parser(std::move(executor))
|
||||
, m_command_lookup()
|
||||
{
|
||||
m_command_lookup.set_handler(
|
||||
"help"
|
||||
, std::bind(&t_command_server<T_command_executor>::help, this, p::_1)
|
||||
, 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<T_command_executor>::print_peer_list, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::print_connections, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::print_blockchain_info, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::print_block, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::print_transaction, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::start_mining, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::stop_mining, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::print_transaction_pool_long, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::print_transaction_pool_short, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::show_hash_rate, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::hide_hash_rate, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::save_blockchain, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::set_log_level, &m_parser, p::_1)
|
||||
, 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<T_command_executor>::show_difficulty, &m_parser, p::_1)
|
||||
, std::bind(&t_command_parser_executor::show_difficulty, &m_parser, p::_1)
|
||||
, "Show difficulty"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"stop_daemon"
|
||||
, std::bind(&t_command_parser_executor<T_command_executor>::stop_daemon, &m_parser, p::_1)
|
||||
, std::bind(&t_command_parser_executor::stop_daemon, &m_parser, p::_1)
|
||||
, "Stop the daemon"
|
||||
);
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_server<T_command_executor>::process_command_str(const std::string& cmd)
|
||||
bool t_command_server::process_command_str(const std::string& cmd)
|
||||
{
|
||||
return m_command_lookup.process_command_str(cmd);
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_server<T_command_executor>::process_command_vec(const std::vector<std::string>& cmd)
|
||||
bool t_command_server::process_command_vec(const std::vector<std::string>& cmd)
|
||||
{
|
||||
return m_command_lookup.process_command_vec(cmd);
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
bool t_command_server<T_command_executor>::help(const std::vector<std::string>& args)
|
||||
bool t_command_server::help(const std::vector<std::string>& args)
|
||||
{
|
||||
std::cout << get_commands_str() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T_command_executor>
|
||||
std::string t_command_server<T_command_executor>::get_commands_str()
|
||||
std::string t_command_server::get_commands_str()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << std::endl;
|
||||
@ -129,7 +123,4 @@ std::string t_command_server<T_command_executor>::get_commands_str()
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template class t_command_server<t_interactive_command_executor>;
|
||||
template class t_command_server<t_rpc_command_executor>;
|
||||
|
||||
} // namespace daemonize
|
||||
|
@ -1,19 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "console_handler.h"
|
||||
#include "daemon/interactive_command_executor.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
template <typename T_command_executor>
|
||||
class t_command_server {
|
||||
private:
|
||||
t_command_parser_executor<T_command_executor> m_parser;
|
||||
t_command_parser_executor m_parser;
|
||||
epee::command_handler m_command_lookup;
|
||||
public:
|
||||
t_command_server(
|
||||
T_command_executor && executor
|
||||
t_rpc_command_executor && executor
|
||||
);
|
||||
|
||||
bool process_command_str(const std::string& cmd);
|
||||
|
@ -1,66 +0,0 @@
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "console_handler.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "daemon/command_server.h"
|
||||
#include "p2p/net_node.h"
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
class t_console_command_thread
|
||||
{
|
||||
public:
|
||||
typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> > t_server;
|
||||
private:
|
||||
t_command_server<t_interactive_command_executor> m_server;
|
||||
t_server & m_srv;
|
||||
epee::async_console_handler m_console_handler;
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool m_finished = false;
|
||||
public:
|
||||
t_console_command_thread(t_server & srv) :
|
||||
m_server(t_interactive_command_executor(srv))
|
||||
, m_srv(srv)
|
||||
{}
|
||||
|
||||
void start()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
|
||||
auto process_command_callback = [this](t_server* /*psrv*/, const std::string& cmd) {
|
||||
return m_server.process_command_str(cmd);
|
||||
};
|
||||
|
||||
auto loop = [this, process_command_callback]() {
|
||||
m_console_handler.run(&m_srv, process_command_callback, "", "");
|
||||
|
||||
// notify the control thread that this thread has finished
|
||||
std::unique_lock<std::mutex> lck(mtx);
|
||||
m_finished = true;
|
||||
cv.notify_all();
|
||||
};
|
||||
std::thread(loop).detach();
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
m_console_handler.stop();
|
||||
|
||||
// wait until we're sure the thread is finished since it uses a shared
|
||||
// node_server
|
||||
std::unique_lock<std::mutex> lck(mtx);
|
||||
while (!m_finished) cv.wait(lck);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
@ -9,7 +9,6 @@
|
||||
#include "version.h"
|
||||
#include "daemon/command_server.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
#include "daemon/console_command_thread.h"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <initializer_list>
|
||||
@ -41,7 +40,6 @@ namespace
|
||||
const command_line::arg_descriptor<bool> arg_os_version = {"os-version", "OS for which this executable was compiled"};
|
||||
const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", "Specify log file. This can either be an absolute path or a path relative to the data directory"};
|
||||
const command_line::arg_descriptor<int> arg_log_level = {"log-level", "", LOG_LEVEL_0};
|
||||
const command_line::arg_descriptor<bool> arg_console = {"no-console", "Disable daemon console commands"};
|
||||
#ifndef WIN32
|
||||
const command_line::arg_descriptor<bool> arg_detach = {"detach", "Run as daemon"};
|
||||
#endif
|
||||
@ -78,7 +76,6 @@ int main(int argc, char* argv[])
|
||||
#endif
|
||||
command_line::add_arg(core_settings, arg_log_file, std::string(CRYPTONOTE_NAME ".log"));
|
||||
command_line::add_arg(core_settings, arg_log_level);
|
||||
command_line::add_arg(core_settings, arg_console);
|
||||
// Add component-specific settings
|
||||
cryptonote::core::init_options(core_settings);
|
||||
cryptonote::core_rpc_server::init_options(core_settings);
|
||||
@ -247,7 +244,6 @@ int main(int argc, char* argv[])
|
||||
cryptonote::core_rpc_server rpc_server(ccore, p2psrv);
|
||||
cprotocol.set_p2p_endpoint(&p2psrv);
|
||||
ccore.set_cryptonote_protocol(&cprotocol);
|
||||
t_console_command_thread console_command_thread(p2psrv);
|
||||
|
||||
//initialize objects
|
||||
LOG_PRINT_L0("Initializing p2p server...");
|
||||
@ -271,20 +267,12 @@ int main(int argc, char* argv[])
|
||||
CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core");
|
||||
LOG_PRINT_L0("Core initialized OK");
|
||||
|
||||
// Start handling console input if requested and not detached
|
||||
if(!command_line::arg_present(vm, arg_console) && !command_line::arg_present(vm, arg_detach))
|
||||
{
|
||||
LOG_PRINT_L0("Begin handling console input");
|
||||
console_command_thread.start();
|
||||
}
|
||||
|
||||
LOG_PRINT_L0("Starting core rpc server...");
|
||||
res = rpc_server.run(2, false);
|
||||
CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core rpc server.");
|
||||
LOG_PRINT_L0("Core rpc server started ok");
|
||||
|
||||
tools::signal_handler::install([&console_command_thread, &p2psrv] {
|
||||
console_command_thread.stop();
|
||||
tools::signal_handler::install([&p2psrv] {
|
||||
p2psrv.send_stop_signal();
|
||||
});
|
||||
|
||||
|
@ -1,168 +0,0 @@
|
||||
#include "daemon/interactive_command_executor.h"
|
||||
|
||||
using namespace daemonize;
|
||||
|
||||
t_interactive_command_executor::t_interactive_command_executor(t_node_server & srv) :
|
||||
m_srv(srv)
|
||||
{}
|
||||
|
||||
t_interactive_command_executor::t_interactive_command_executor(t_interactive_command_executor && other) = default;
|
||||
|
||||
bool t_interactive_command_executor::print_peer_list() {
|
||||
m_srv.log_peerlist();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::save_blockchain() {
|
||||
m_srv.get_payload_object().get_core().get_blockchain_storage().store_blockchain();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::show_hash_rate() {
|
||||
if(!m_srv.get_payload_object().get_core().get_miner().is_mining())
|
||||
{
|
||||
std::cout << "Mining is not started. You need start mining before you can see hash rate." << std::endl;
|
||||
} else
|
||||
{
|
||||
m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::hide_hash_rate() {
|
||||
m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::show_difficulty() {
|
||||
cryptonote::difficulty_type difficulty = m_srv.get_payload_object().get_core().get_blockchain_storage().get_difficulty_for_next_block();
|
||||
uint64_t height = m_srv.get_payload_object().get_core().get_blockchain_storage().get_current_blockchain_height();
|
||||
|
||||
std::cout << "BH: " << height << ", DIFF: " << difficulty
|
||||
<< ", HR: " << (int) difficulty / 60L << " H/s" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_connections() {
|
||||
m_srv.get_payload_object().log_connections();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index) {
|
||||
uint64_t end_block_parametr = m_srv.get_payload_object().get_core().get_current_blockchain_height();
|
||||
if (end_block_index == 0)
|
||||
{
|
||||
end_block_index = end_block_parametr;
|
||||
}
|
||||
if (end_block_index > end_block_parametr)
|
||||
{
|
||||
std::cout << "end block index parameter shouldn't be greater than " << end_block_parametr << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (end_block_index <= start_block_index)
|
||||
{
|
||||
std::cout << "end block index should be greater than starter block index" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_srv.get_payload_object().get_core().print_blockchain(start_block_index, end_block_index);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::set_log_level(int8_t level) {
|
||||
epee::log_space::log_singletone::get_set_log_detalisation_level(true, level);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_block_by_hash(crypto::hash block_hash) {
|
||||
std::list<crypto::hash> block_ids;
|
||||
block_ids.push_back(block_hash);
|
||||
std::list<cryptonote::block> blocks;
|
||||
std::list<crypto::hash> missed_ids;
|
||||
m_srv.get_payload_object().get_core().get_blocks(block_ids, blocks, missed_ids);
|
||||
|
||||
if (1 == blocks.size())
|
||||
{
|
||||
cryptonote::block block = blocks.front();
|
||||
std::cout << cryptonote::obj_to_json_str(block) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "block wasn't found: " << block_hash << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_block_by_height(uint64_t height) {
|
||||
std::list<cryptonote::block> blocks;
|
||||
m_srv.get_payload_object().get_core().get_blocks(height, 1, blocks);
|
||||
|
||||
if (1 == blocks.size())
|
||||
{
|
||||
cryptonote::block& block = blocks.front();
|
||||
std::cout << "block_id: " << get_block_hash(block) << std::endl;
|
||||
std::cout << cryptonote::obj_to_json_str(block) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t current_height;
|
||||
crypto::hash top_id;
|
||||
m_srv.get_payload_object().get_core().get_blockchain_top(current_height, top_id);
|
||||
std::cout << "block wasn't found. Current block chain height: " << current_height << ", requested: " << height << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_transaction(crypto::hash transaction_hash) {
|
||||
std::vector<crypto::hash> tx_ids;
|
||||
tx_ids.push_back(transaction_hash);
|
||||
std::list<cryptonote::transaction> txs;
|
||||
std::list<crypto::hash> missed_ids;
|
||||
m_srv.get_payload_object().get_core().get_transactions(tx_ids, txs, missed_ids);
|
||||
|
||||
if (1 == txs.size())
|
||||
{
|
||||
cryptonote::transaction tx = txs.front();
|
||||
std::cout << cryptonote::obj_to_json_str(tx) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "transaction wasn't found: <" << transaction_hash << '>' << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_transaction_pool_long() {
|
||||
std::cout << "Pool state: " << std::endl << m_srv.get_payload_object().get_core().print_pool(false) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::print_transaction_pool_short() {
|
||||
std::cout << "Pool state: " << std::endl << m_srv.get_payload_object().get_core().print_pool(true) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads) {
|
||||
boost::thread::attributes attrs;
|
||||
attrs.set_stack_size(THREAD_STACK_SIZE);
|
||||
|
||||
m_srv.get_payload_object().get_core().get_miner().start(address, num_threads, attrs);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::stop_mining() {
|
||||
m_srv.get_payload_object().get_core().get_miner().stop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_interactive_command_executor::stop_daemon() {
|
||||
std::cout << "This is a stub! The old interactive commands should go away once testing is complete!" << std::endl;
|
||||
return true;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "misc_log_ex.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "p2p/net_node.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
class t_interactive_command_executor final {
|
||||
public:
|
||||
typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> > t_node_server;
|
||||
private:
|
||||
t_node_server & m_srv;
|
||||
public:
|
||||
t_interactive_command_executor(t_node_server & srv);
|
||||
|
||||
t_interactive_command_executor(t_interactive_command_executor && other);
|
||||
|
||||
bool print_peer_list();
|
||||
|
||||
bool save_blockchain();
|
||||
|
||||
bool show_hash_rate();
|
||||
|
||||
bool hide_hash_rate();
|
||||
|
||||
bool show_difficulty();
|
||||
|
||||
bool print_connections();
|
||||
|
||||
bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index);
|
||||
|
||||
bool set_log_level(int8_t level);
|
||||
|
||||
bool print_block_by_hash(crypto::hash block_hash);
|
||||
|
||||
bool print_block_by_height(uint64_t height);
|
||||
|
||||
bool print_transaction(crypto::hash transaction_hash);
|
||||
|
||||
bool print_transaction_pool_long();
|
||||
|
||||
bool print_transaction_pool_short();
|
||||
|
||||
bool start_mining(cryptonote::account_public_address address, uint64_t num_threads);
|
||||
|
||||
bool stop_mining();
|
||||
|
||||
bool stop_daemon();
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
Loading…
Reference in New Issue
Block a user