aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/rpc_command_executor.cpp
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-02-06 00:31:50 -0800
committerAlexander Blair <snipa@jagtech.io>2020-02-06 00:31:50 -0800
commit8136bf37e2c0a76851c0bb6482b6e4c2b653f5d7 (patch)
tree701ae6b1f1e16455e88daf53fe0d930e4822d126 /src/daemon/rpc_command_executor.cpp
parentMerge pull request #6095 (diff)
parentdaemon: allow printing N blocks from the end of the chain (diff)
downloadmonero-8136bf37e2c0a76851c0bb6482b6e4c2b653f5d7.tar.xz
Merge pull request #6096
a633f85d daemon: allow printing N blocks from the end of the chain (moneromooo-monero)
Diffstat (limited to 'src/daemon/rpc_command_executor.cpp')
-rw-r--r--src/daemon/rpc_command_executor.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index d4462aa38..1ca728e39 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -744,17 +744,46 @@ bool t_rpc_command_executor::print_net_stats()
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::response res;
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.end_height = end_block_index;
req.fill_pow_hash = false;
- std::string fail_message = "Unsuccessful";
-
+ fail_message = "Failed calling getblockheadersrange";
if (m_is_rpc)
{
if (!m_rpc_client->json_rpc_request(req, res, "getblockheadersrange", fail_message.c_str()))