mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-23 11:48:52 +00:00
Core RPC: optionally add POW hash to block_header_response
This commit is contained in:
parent
8361d60aef
commit
353e9c0c90
@ -74,6 +74,7 @@ namespace {
|
|||||||
<< "depth: " << boost::lexical_cast<std::string>(header.depth) << std::endl
|
<< "depth: " << boost::lexical_cast<std::string>(header.depth) << std::endl
|
||||||
<< "hash: " << header.hash << std::endl
|
<< "hash: " << header.hash << std::endl
|
||||||
<< "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl
|
<< "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl
|
||||||
|
<< "POW hash: " << header.pow_hash << std::endl
|
||||||
<< "reward: " << boost::lexical_cast<std::string>(header.reward);
|
<< "reward: " << boost::lexical_cast<std::string>(header.reward);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,6 +655,7 @@ bool t_rpc_command_executor::print_block_by_hash(crypto::hash block_hash) {
|
|||||||
epee::json_rpc::error error_resp;
|
epee::json_rpc::error error_resp;
|
||||||
|
|
||||||
req.hash = epee::string_tools::pod_to_hex(block_hash);
|
req.hash = epee::string_tools::pod_to_hex(block_hash);
|
||||||
|
req.fill_pow_hash = true;
|
||||||
|
|
||||||
std::string fail_message = "Unsuccessful";
|
std::string fail_message = "Unsuccessful";
|
||||||
|
|
||||||
@ -685,6 +687,7 @@ bool t_rpc_command_executor::print_block_by_height(uint64_t height) {
|
|||||||
epee::json_rpc::error error_resp;
|
epee::json_rpc::error error_resp;
|
||||||
|
|
||||||
req.height = height;
|
req.height = height;
|
||||||
|
req.fill_pow_hash = true;
|
||||||
|
|
||||||
std::string fail_message = "Unsuccessful";
|
std::string fail_message = "Unsuccessful";
|
||||||
|
|
||||||
|
@ -1229,7 +1229,7 @@ namespace cryptonote
|
|||||||
return reward;
|
return reward;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response)
|
bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response, bool fill_pow_hash)
|
||||||
{
|
{
|
||||||
PERF_TIMER(fill_block_header_response);
|
PERF_TIMER(fill_block_header_response);
|
||||||
response.major_version = blk.major_version;
|
response.major_version = blk.major_version;
|
||||||
@ -1245,6 +1245,7 @@ namespace cryptonote
|
|||||||
response.reward = get_block_reward(blk);
|
response.reward = get_block_reward(blk);
|
||||||
response.block_size = m_core.get_blockchain_storage().get_db().get_block_size(height);
|
response.block_size = m_core.get_blockchain_storage().get_db().get_block_size(height);
|
||||||
response.num_txes = blk.tx_hashes.size();
|
response.num_txes = blk.tx_hashes.size();
|
||||||
|
response.pow_hash = fill_pow_hash ? string_tools::pod_to_hex(get_block_longhash(blk, height)) : "";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -1334,7 +1335,7 @@ namespace cryptonote
|
|||||||
error_resp.message = "Internal error: can't get last block.";
|
error_resp.message = "Internal error: can't get last block.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool response_filled = fill_block_header_response(last_block, false, last_block_height, last_block_hash, res.block_header);
|
bool response_filled = fill_block_header_response(last_block, false, last_block_height, last_block_hash, res.block_header, req.fill_pow_hash);
|
||||||
if (!response_filled)
|
if (!response_filled)
|
||||||
{
|
{
|
||||||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
@ -1375,7 +1376,7 @@ namespace cryptonote
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
|
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
|
||||||
bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header);
|
bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header, req.fill_pow_hash);
|
||||||
if (!response_filled)
|
if (!response_filled)
|
||||||
{
|
{
|
||||||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
@ -1424,7 +1425,7 @@ namespace cryptonote
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
res.headers.push_back(block_header_response());
|
res.headers.push_back(block_header_response());
|
||||||
bool response_filled = fill_block_header_response(blk, false, block_height, block_hash, res.headers.back());
|
bool response_filled = fill_block_header_response(blk, false, block_height, block_hash, res.headers.back(), req.fill_pow_hash);
|
||||||
if (!response_filled)
|
if (!response_filled)
|
||||||
{
|
{
|
||||||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
@ -1457,7 +1458,7 @@ namespace cryptonote
|
|||||||
error_resp.message = "Internal error: can't get block by height. Height = " + std::to_string(req.height) + '.';
|
error_resp.message = "Internal error: can't get block by height. Height = " + std::to_string(req.height) + '.';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool response_filled = fill_block_header_response(blk, false, req.height, block_hash, res.block_header);
|
bool response_filled = fill_block_header_response(blk, false, req.height, block_hash, res.block_header, req.fill_pow_hash);
|
||||||
if (!response_filled)
|
if (!response_filled)
|
||||||
{
|
{
|
||||||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
@ -1511,7 +1512,7 @@ namespace cryptonote
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
|
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
|
||||||
bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header);
|
bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header, req.fill_pow_hash);
|
||||||
if (!response_filled)
|
if (!response_filled)
|
||||||
{
|
{
|
||||||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||||
|
@ -224,7 +224,7 @@ private:
|
|||||||
|
|
||||||
//utils
|
//utils
|
||||||
uint64_t get_block_reward(const block& blk);
|
uint64_t get_block_reward(const block& blk);
|
||||||
bool fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response);
|
bool fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response, bool fill_pow_hash);
|
||||||
enum invoke_http_mode { JON, BIN, JON_RPC };
|
enum invoke_http_mode { JON, BIN, JON_RPC };
|
||||||
template <typename COMMAND_TYPE>
|
template <typename COMMAND_TYPE>
|
||||||
bool use_bootstrap_daemon_if_necessary(const invoke_http_mode &mode, const std::string &command_name, const typename COMMAND_TYPE::request& req, typename COMMAND_TYPE::response& res, bool &r);
|
bool use_bootstrap_daemon_if_necessary(const invoke_http_mode &mode, const std::string &command_name, const typename COMMAND_TYPE::request& req, typename COMMAND_TYPE::response& res, bool &r);
|
||||||
|
@ -49,7 +49,7 @@ namespace cryptonote
|
|||||||
// advance which version they will stop working with
|
// advance which version they will stop working with
|
||||||
// Don't go over 32767 for any of these
|
// Don't go over 32767 for any of these
|
||||||
#define CORE_RPC_VERSION_MAJOR 1
|
#define CORE_RPC_VERSION_MAJOR 1
|
||||||
#define CORE_RPC_VERSION_MINOR 19
|
#define CORE_RPC_VERSION_MINOR 20
|
||||||
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
||||||
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
|
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
|
||||||
|
|
||||||
@ -1163,6 +1163,7 @@ namespace cryptonote
|
|||||||
uint64_t reward;
|
uint64_t reward;
|
||||||
uint64_t block_size;
|
uint64_t block_size;
|
||||||
uint64_t num_txes;
|
uint64_t num_txes;
|
||||||
|
std::string pow_hash;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(major_version)
|
KV_SERIALIZE(major_version)
|
||||||
@ -1178,6 +1179,7 @@ namespace cryptonote
|
|||||||
KV_SERIALIZE(reward)
|
KV_SERIALIZE(reward)
|
||||||
KV_SERIALIZE(block_size)
|
KV_SERIALIZE(block_size)
|
||||||
KV_SERIALIZE(num_txes)
|
KV_SERIALIZE(num_txes)
|
||||||
|
KV_SERIALIZE(pow_hash)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1185,7 +1187,10 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
struct request
|
struct request
|
||||||
{
|
{
|
||||||
|
bool fill_pow_hash;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE_OPT(fill_pow_hash, false);
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1209,9 +1214,11 @@ namespace cryptonote
|
|||||||
struct request
|
struct request
|
||||||
{
|
{
|
||||||
std::string hash;
|
std::string hash;
|
||||||
|
bool fill_pow_hash;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(hash)
|
KV_SERIALIZE(hash)
|
||||||
|
KV_SERIALIZE_OPT(fill_pow_hash, false);
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1235,9 +1242,11 @@ namespace cryptonote
|
|||||||
struct request
|
struct request
|
||||||
{
|
{
|
||||||
uint64_t height;
|
uint64_t height;
|
||||||
|
bool fill_pow_hash;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(height)
|
KV_SERIALIZE(height)
|
||||||
|
KV_SERIALIZE_OPT(fill_pow_hash, false);
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1262,10 +1271,12 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
std::string hash;
|
std::string hash;
|
||||||
uint64_t height;
|
uint64_t height;
|
||||||
|
bool fill_pow_hash;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(hash)
|
KV_SERIALIZE(hash)
|
||||||
KV_SERIALIZE(height)
|
KV_SERIALIZE(height)
|
||||||
|
KV_SERIALIZE_OPT(fill_pow_hash, false);
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1618,10 +1629,12 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
uint64_t start_height;
|
uint64_t start_height;
|
||||||
uint64_t end_height;
|
uint64_t end_height;
|
||||||
|
bool fill_pow_hash;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(start_height)
|
KV_SERIALIZE(start_height)
|
||||||
KV_SERIALIZE(end_height)
|
KV_SERIALIZE(end_height)
|
||||||
|
KV_SERIALIZE_OPT(fill_pow_hash, false);
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user