Add calcpow RPC

Calculate PoW hash for a block candidate
This commit is contained in:
Howard Chu 2021-11-19 23:22:43 +00:00
parent 6d94953be2
commit 0221b01519
No known key found for this signature in database
GPG key ID: FD2A70B44AB11BA7
5 changed files with 73 additions and 5 deletions

View file

@ -1912,6 +1912,43 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_calcpow(const COMMAND_RPC_CALCPOW::request& req, COMMAND_RPC_CALCPOW::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx)
{
RPC_TRACKER(calcpow);
blobdata blockblob;
if(!string_tools::parse_hexstr_to_binbuff(req.block_blob, blockblob))
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB;
error_resp.message = "Wrong block blob";
return false;
}
if(!m_core.check_incoming_block_size(blockblob))
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE;
error_resp.message = "Block blob size is too big, rejecting block";
return false;
}
crypto::hash seed_hash, pow_hash;
std::string buf;
if(req.seed_hash.size())
{
if (!string_tools::parse_hexstr_to_binbuff(req.seed_hash, buf) ||
buf.size() != sizeof(crypto::hash))
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
error_resp.message = "Wrong seed hash";
return false;
}
buf.copy(reinterpret_cast<char *>(&seed_hash), sizeof(crypto::hash));
}
cryptonote::get_block_longhash(&(m_core.get_blockchain_storage()), blockblob, pow_hash, req.height,
req.major_version, req.seed_hash.size() ? &seed_hash : NULL, 0);
res = string_tools::pod_to_hex(pow_hash);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_add_aux_pow(const COMMAND_RPC_ADD_AUX_POW::request& req, COMMAND_RPC_ADD_AUX_POW::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx)
{
RPC_TRACKER(add_aux_pow);