mirror of
https://github.com/monero-project/monero.git
synced 2026-08-03 01:15:55 -07:00
@@ -674,6 +674,31 @@ bool t_command_parser_executor::sync_info(const std::vector<std::string>& args)
|
||||
return m_executor.sync_info();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::pop_blocks(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.size() != 1)
|
||||
{
|
||||
std::cout << "Exactly one parameter is needed" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
uint64_t nblocks = boost::lexical_cast<uint64_t>(args[0]);
|
||||
if (nblocks < 1)
|
||||
{
|
||||
std::cout << "number of blocks must be greater than 0" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return m_executor.pop_blocks(nblocks);
|
||||
}
|
||||
catch (const boost::bad_lexical_cast&)
|
||||
{
|
||||
std::cout << "number of blocks must be a number greater than 0" << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::version(const std::vector<std::string>& args)
|
||||
{
|
||||
std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << std::endl;
|
||||
|
||||
@@ -139,6 +139,8 @@ public:
|
||||
|
||||
bool sync_info(const std::vector<std::string>& args);
|
||||
|
||||
bool pop_blocks(const std::vector<std::string>& args);
|
||||
|
||||
bool version(const std::vector<std::string>& args);
|
||||
};
|
||||
|
||||
|
||||
@@ -281,6 +281,12 @@ t_command_server::t_command_server(
|
||||
, std::bind(&t_command_parser_executor::sync_info, &m_parser, p::_1)
|
||||
, "Print information about the blockchain sync state."
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"pop_blocks"
|
||||
, std::bind(&t_command_parser_executor::pop_blocks, &m_parser, p::_1)
|
||||
, "pop_blocks <nblocks>"
|
||||
, "Remove blocks from end of blockchain"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"version"
|
||||
, std::bind(&t_command_parser_executor::version, &m_parser, p::_1)
|
||||
|
||||
@@ -1967,4 +1967,31 @@ bool t_rpc_command_executor::sync_info()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::pop_blocks(uint64_t num_blocks)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_POP_BLOCKS::request req;
|
||||
cryptonote::COMMAND_RPC_POP_BLOCKS::response res;
|
||||
std::string fail_message = "pop_blocks failed";
|
||||
|
||||
req.nblocks = num_blocks;
|
||||
if (m_is_rpc)
|
||||
{
|
||||
if (!m_rpc_client->rpc_request(req, res, "/pop_blocks", fail_message.c_str()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_rpc_server->on_pop_blocks(req, res) || res.status != CORE_RPC_STATUS_OK)
|
||||
{
|
||||
tools::fail_msg_writer() << make_error(fail_message, res.status);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
tools::success_msg_writer() << "new height: " << res.height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}// namespace daemonize
|
||||
|
||||
@@ -152,6 +152,8 @@ public:
|
||||
bool relay_tx(const std::string &txid);
|
||||
|
||||
bool sync_info();
|
||||
|
||||
bool pop_blocks(uint64_t num_blocks);
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
||||
|
||||
Reference in New Issue
Block a user