mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-26 21:03:28 +01:00
daemon: implement missing print_bc and matching RPC
This commit is contained in:
parent
8f94fcf6a3
commit
179b1f43af
@ -440,11 +440,6 @@ 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) {
|
||||||
|
|
||||||
// this function appears to not exist in the json rpc api, and so is commented
|
|
||||||
// until such a time as it does.
|
|
||||||
|
|
||||||
/*
|
|
||||||
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;
|
||||||
@ -463,25 +458,26 @@ bool t_rpc_command_executor::print_blockchain_info(uint64_t start_block_index, u
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!m_rpc_server->on_getblockheadersrange(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
|
if (!m_rpc_server->on_get_block_headers_range(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << fail_message.c_str();
|
tools::fail_msg_writer() << fail_message.c_str();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
for (auto & header : res.headers)
|
for (auto & header : res.headers)
|
||||||
{
|
{
|
||||||
|
if (!first)
|
||||||
|
std::cout << std::endl;
|
||||||
std::cout
|
std::cout
|
||||||
<< "major version: " << header.major_version << std::endl
|
<< "major version: " << (unsigned)header.major_version << ", minor version: " << (unsigned)header.minor_version << std::endl
|
||||||
<< "minor version: " << header.minor_version << std::endl
|
|
||||||
<< "height: " << header.height << ", timestamp: " << header.timestamp << ", difficulty: " << header.difficulty << std::endl
|
<< "height: " << header.height << ", timestamp: " << header.timestamp << ", difficulty: " << header.difficulty << std::endl
|
||||||
<< "block id: " << header.hash << std::endl
|
<< "block id: " << header.hash << ", previous block id: " << header.prev_hash << std::endl
|
||||||
<< "previous block id: " << header.prev_hash << std::endl
|
<< "difficulty: " << header.difficulty << ", nonce " << header.nonce << ", reward " << cryptonote::print_money(header.reward) << std::endl;
|
||||||
<< "difficulty: " << header.difficulty << ", nonce " << header.nonce << std::endl;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,6 +923,57 @@ 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){
|
||||||
|
if(!check_core_busy())
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
|
||||||
|
error_resp.message = "Core is busy.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const uint64_t bc_height = m_core.get_current_blockchain_height();
|
||||||
|
if (req.start_height >= bc_height || req.end_height >= bc_height || req.start_height > req.end_height)
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
|
||||||
|
error_resp.message = "Invalid start/end heights.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (uint64_t h = req.start_height; h <= req.end_height; ++h)
|
||||||
|
{
|
||||||
|
crypto::hash block_hash = m_core.get_block_id_by_height(h);
|
||||||
|
block blk;
|
||||||
|
bool have_block = m_core.get_block_by_hash(block_hash, blk);
|
||||||
|
if (!have_block)
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
|
error_resp.message = "Internal error: can't get block by height. Height = " + boost::lexical_cast<std::string>(h) + ". Hash = " + epee::string_tools::pod_to_hex(block_hash) + '.';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (blk.miner_tx.vin.front().type() != typeid(txin_gen))
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
|
error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
|
||||||
|
if (block_height != h)
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
|
error_resp.message = "Internal error: coinbase transaction in the block has the wrong height";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
res.headers.push_back(block_header_responce());
|
||||||
|
bool responce_filled = fill_block_header_responce(blk, false, block_height, block_hash, res.headers.back());
|
||||||
|
if (!responce_filled)
|
||||||
|
{
|
||||||
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
|
error_resp.message = "Internal error: can't produce valid response.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.status = CORE_RPC_STATUS_OK;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::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){
|
bool core_rpc_server::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){
|
||||||
if(!check_core_busy())
|
if(!check_core_busy())
|
||||||
{
|
{
|
||||||
|
@ -106,6 +106,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)
|
||||||
MAP_JON_RPC_WE("getblock", on_get_block, COMMAND_RPC_GET_BLOCK)
|
MAP_JON_RPC_WE("getblock", on_get_block, COMMAND_RPC_GET_BLOCK)
|
||||||
MAP_JON_RPC_WE_IF("get_connections", on_get_connections, COMMAND_RPC_GET_CONNECTIONS, !m_restricted)
|
MAP_JON_RPC_WE_IF("get_connections", on_get_connections, COMMAND_RPC_GET_CONNECTIONS, !m_restricted)
|
||||||
MAP_JON_RPC_WE("get_info", on_get_info_json, COMMAND_RPC_GET_INFO)
|
MAP_JON_RPC_WE("get_info", on_get_info_json, COMMAND_RPC_GET_INFO)
|
||||||
@ -151,6 +152,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);
|
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);
|
||||||
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);
|
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);
|
||||||
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);
|
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);
|
||||||
|
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);
|
||||||
bool on_get_block(const COMMAND_RPC_GET_BLOCK::request& req, COMMAND_RPC_GET_BLOCK::response& res, epee::json_rpc::error& error_resp);
|
bool on_get_block(const COMMAND_RPC_GET_BLOCK::request& req, COMMAND_RPC_GET_BLOCK::response& res, epee::json_rpc::error& error_resp);
|
||||||
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp);
|
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp);
|
||||||
bool on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp);
|
bool on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp);
|
||||||
|
Loading…
Reference in New Issue
Block a user