Skip to content

Commit

Permalink
Implement simple block info by height
Browse files Browse the repository at this point in the history
  • Loading branch information
aivve committed Jul 4, 2022
1 parent d915703 commit de5e370
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/Rpc/RpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,31 +469,39 @@ void RpcServer::processRequest(const httplib::Request& request, httplib::Respons

if (Common::starts_with(url, block_method)) {
std::string hash_str = url.substr(block_method.size());
if (hash_str.size() < 64) { // assume it's height
//on_get_explorer_block_by_height
if (hash_str.size() < 64) {
// assume it's height
uint32_t height = static_cast<uint32_t>(std::stoul(hash_str));
if (m_core.getCurrentBlockchainHeight() <= height) {
throw JsonRpc::JsonRpcError{ CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT,
std::string("To big height: ") + std::to_string(height) +
", current blockchain height = " + std::to_string(m_core.getCurrentBlockchainHeight() - 1) };
}
Crypto::Hash block_hash = m_core.getBlockIdByHeight(height);
hash_str = Common::podToHex(block_hash);
}

COMMAND_EXPLORER_GET_BLOCK_DETAILS_BY_HASH::request req;
req.hash = hash_str;
COMMAND_EXPLORER_GET_BLOCK_DETAILS_BY_HASH::response rsp;
bool r = on_get_explorer_block_by_hash(req, rsp);
if (r) {
response.status = 200;
response.set_content(rsp, "text/html");
}
else {
COMMAND_EXPLORER_GET_BLOCK_DETAILS_BY_HASH::request req;
req.hash = hash_str;
COMMAND_EXPLORER_GET_BLOCK_DETAILS_BY_HASH::response rsp;
bool r = on_get_explorer_block_by_hash(req, rsp);
if (r) {
response.status = 200;
response.set_content(rsp, "text/html");
}
else {
response.status = 500;
response.set_content("Internal error", "text/html");
}
return;
response.status = 500;
response.set_content("Internal error", "text/html");
}
return;


return;
}

if (Common::starts_with(url, tx_method)) {


return;
}

Expand Down

0 comments on commit de5e370

Please sign in to comment.