mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
Add get block headers range command over RPC
This commit is contained in:
parent
746af71727
commit
46e85b1fd7
@ -155,8 +155,26 @@ bool t_rpc_command_executor::print_connections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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(uint64_t start_block_index, uint64_t end_block_index) {
|
||||||
std::cout << "print blockchain info" << std::endl;
|
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request req;
|
||||||
return true;
|
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response res;
|
||||||
|
|
||||||
|
if (rpc_request(req, res, "/json_rpc/getblockheadersrange", "Unsuccessful"))
|
||||||
|
{
|
||||||
|
for (auto & header : res.headers)
|
||||||
|
{
|
||||||
|
std::cout << "height " << header.height
|
||||||
|
<< ", timestamp " << header.timestamp
|
||||||
|
<< ", cumul_dif " << header.cumulative_difficulty
|
||||||
|
<< ", cumul_size " << header.cumulative_size << std::endl
|
||||||
|
<< "id " << header.hash << std::endl
|
||||||
|
<< "difficulty" << header.difficulty
|
||||||
|
<< ", nonce " << header.nonce
|
||||||
|
<< ", tx_count " << header.tx_count << std::endl;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool t_rpc_command_executor::set_log_level(int8_t level) {
|
bool t_rpc_command_executor::set_log_level(int8_t level) {
|
||||||
|
@ -686,4 +686,30 @@ namespace cryptonote
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool core_rpc_server::on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request& req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response& res, epee::json_rpc::error& error_resp, connection_context& cntx){
|
||||||
|
if(!check_core_busy())
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
|
||||||
|
error_resp.message = "Core is busy.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(m_core.get_current_blockchain_height() <= req.start_height)
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
|
||||||
|
error_resp.message = std::string("To big height: ") + std::to_string(req.start_height) + ", current blockchain height = " + std::to_string(m_core.get_current_blockchain_height());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(m_core.get_current_blockchain_height() <= req.end_height)
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
|
||||||
|
error_resp.message = std::string("To big height: ") + std::to_string(req.end_height) + ", current blockchain height = " + std::to_string(m_core.get_current_blockchain_height());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.headers = m_core.get_blockchain_storage().get_block_headers(req.start_height, req.end_height);
|
||||||
|
|
||||||
|
res.status = CORE_RPC_STATUS_OK;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ namespace cryptonote
|
|||||||
MAP_JON_RPC_WE("getlastblockheader", on_get_last_block_header, COMMAND_RPC_GET_LAST_BLOCK_HEADER)
|
MAP_JON_RPC_WE("getlastblockheader", on_get_last_block_header, COMMAND_RPC_GET_LAST_BLOCK_HEADER)
|
||||||
MAP_JON_RPC_WE("getblockheaderbyhash", on_get_block_header_by_hash, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH)
|
MAP_JON_RPC_WE("getblockheaderbyhash", on_get_block_header_by_hash, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH)
|
||||||
MAP_JON_RPC_WE("getblockheaderbyheight", on_get_block_header_by_height, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT)
|
MAP_JON_RPC_WE("getblockheaderbyheight", on_get_block_header_by_height, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT)
|
||||||
|
MAP_JON_RPC_WE("getblockheadersrange", on_get_block_headers_range, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE)
|
||||||
END_JSON_RPC_MAP()
|
END_JSON_RPC_MAP()
|
||||||
END_URI_MAP2()
|
END_URI_MAP2()
|
||||||
|
|
||||||
@ -87,6 +88,7 @@ namespace cryptonote
|
|||||||
bool on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request& req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
bool on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request& req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||||
bool on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
bool on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||||
bool on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
bool on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||||
|
bool on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request& req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||||
//-----------------------
|
//-----------------------
|
||||||
bool handle_command_line(const boost::program_options::variables_map& vm);
|
bool handle_command_line(const boost::program_options::variables_map& vm);
|
||||||
bool check_core_busy();
|
bool check_core_busy();
|
||||||
|
@ -616,5 +616,30 @@ namespace cryptonote
|
|||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct COMMAND_RPC_GET_BLOCK_HEADERS_RANGE
|
||||||
|
{
|
||||||
|
struct request
|
||||||
|
{
|
||||||
|
uint64_t start_height;
|
||||||
|
uint64_t end_height;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(start_height)
|
||||||
|
KV_SERIALIZE(end_height)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct response
|
||||||
|
{
|
||||||
|
std::string status;
|
||||||
|
std::vector<block_header_responce> headers;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(status)
|
||||||
|
KV_SERIALIZE(headers)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user