mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #6096
a633f85d
daemon: allow printing N blocks from the end of the chain (moneromooo-monero)
This commit is contained in:
commit
8136bf37e2
3 changed files with 43 additions and 4 deletions
|
@ -153,6 +153,16 @@ bool t_command_parser_executor::print_blockchain_info(const std::vector<std::str
|
||||||
}
|
}
|
||||||
uint64_t start_index = 0;
|
uint64_t start_index = 0;
|
||||||
uint64_t end_index = 0;
|
uint64_t end_index = 0;
|
||||||
|
if (args[0][0] == '-')
|
||||||
|
{
|
||||||
|
int64_t nblocks;
|
||||||
|
if(!epee::string_tools::get_xtype_from_string(nblocks, args[0]))
|
||||||
|
{
|
||||||
|
std::cout << "wrong number of blocks" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return m_executor.print_blockchain_info(nblocks, (uint64_t)-nblocks);
|
||||||
|
}
|
||||||
if(!epee::string_tools::get_xtype_from_string(start_index, args[0]))
|
if(!epee::string_tools::get_xtype_from_string(start_index, args[0]))
|
||||||
{
|
{
|
||||||
std::cout << "wrong starter block index parameter" << std::endl;
|
std::cout << "wrong starter block index parameter" << std::endl;
|
||||||
|
|
|
@ -744,17 +744,46 @@ bool t_rpc_command_executor::print_net_stats()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool t_rpc_command_executor::print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index) {
|
bool t_rpc_command_executor::print_blockchain_info(int64_t start_block_index, uint64_t end_block_index) {
|
||||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request req;
|
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request req;
|
||||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response res;
|
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response res;
|
||||||
epee::json_rpc::error error_resp;
|
epee::json_rpc::error error_resp;
|
||||||
|
std::string fail_message = "Problem fetching info";
|
||||||
|
|
||||||
|
// negative: relative to the end
|
||||||
|
if (start_block_index < 0)
|
||||||
|
{
|
||||||
|
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
|
||||||
|
cryptonote::COMMAND_RPC_GET_INFO::response ires;
|
||||||
|
if (m_is_rpc)
|
||||||
|
{
|
||||||
|
if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
|
||||||
|
{
|
||||||
|
tools::fail_msg_writer() << make_error(fail_message, ires.status);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start_block_index < 0 && (uint64_t)-start_block_index >= ires.height)
|
||||||
|
{
|
||||||
|
tools::fail_msg_writer() << "start offset is larger than blockchain height";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
start_block_index = ires.height + start_block_index;
|
||||||
|
end_block_index = start_block_index + end_block_index - 1;
|
||||||
|
}
|
||||||
|
|
||||||
req.start_height = start_block_index;
|
req.start_height = start_block_index;
|
||||||
req.end_height = end_block_index;
|
req.end_height = end_block_index;
|
||||||
req.fill_pow_hash = false;
|
req.fill_pow_hash = false;
|
||||||
|
|
||||||
std::string fail_message = "Unsuccessful";
|
fail_message = "Failed calling getblockheadersrange";
|
||||||
|
|
||||||
if (m_is_rpc)
|
if (m_is_rpc)
|
||||||
{
|
{
|
||||||
if (!m_rpc_client->json_rpc_request(req, res, "getblockheadersrange", fail_message.c_str()))
|
if (!m_rpc_client->json_rpc_request(req, res, "getblockheadersrange", fail_message.c_str()))
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
|
|
||||||
bool print_connections();
|
bool print_connections();
|
||||||
|
|
||||||
bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index);
|
bool print_blockchain_info(int64_t start_block_index, uint64_t end_block_index);
|
||||||
|
|
||||||
bool set_log_level(int8_t level);
|
bool set_log_level(int8_t level);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue