mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 14:08:40 +01:00
Merge bitcoin/bitcoin#25412: rest: add /deploymentinfo endpoint
a8250e30f1doc: add release note about `/rest/deploymentinfo` (brunoerg)5c96020024doc: add `/deploymentinfo` in REST-interface (brunoerg)3e44bee08etest: add coverage for `/rest/deploymentinfo` (brunoerg)91497031cbrest: add `/deploymentinfo` (brunoerg) Pull request description: #23508 added a new RPC named `getdeploymentinfo`, it moved the softfork section from `getblockchaininfo` into this new one. In the REST interface, we have an endpoint named`/rest/chaininfo.json` (which refers to `getblockchaininfo`), so, this PR adds a new REST endpoint named `/deploymentinfo` which refers to `getdeploymentinfo`. You can use it by passing a block hash, e.g: '/rest/deploymentinfo/<BLOCKHASH>.json' or you can use it without passing a block hash to get the 'deploymentinfo' for the last block. ACKs for top commit: jonatack: re-ACKa8250e30f1rebase-only since my last review at c65f82bb achow101: ACKa8250e30f1stickies-v: re-ACKa8250e30f1Tree-SHA512: 0735183b6828d51a72ed0e2be5a09b314ac4693f548982c6e9adaa0ef07a55aa428d3b2d1b1de70b83169811a663a8624b686166e5797f624dcc00178b9796e6
This commit is contained in:
44
src/rest.cpp
44
src/rest.cpp
@@ -590,6 +590,48 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RPCHelpMan getdeploymentinfo();
|
||||
|
||||
static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
|
||||
{
|
||||
if (!CheckWarmup(req)) return false;
|
||||
|
||||
std::string hash_str;
|
||||
const RESTResponseFormat rf = ParseDataFormat(hash_str, str_uri_part);
|
||||
|
||||
switch (rf) {
|
||||
case RESTResponseFormat::JSON: {
|
||||
JSONRPCRequest jsonRequest;
|
||||
jsonRequest.context = context;
|
||||
jsonRequest.params = UniValue(UniValue::VARR);
|
||||
|
||||
if (!hash_str.empty()) {
|
||||
uint256 hash;
|
||||
if (!ParseHashStr(hash_str, hash)) {
|
||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hash_str);
|
||||
}
|
||||
|
||||
const ChainstateManager* chainman = GetChainman(context, req);
|
||||
if (!chainman) return false;
|
||||
if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hash_str, "blockhash")))) {
|
||||
return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
|
||||
}
|
||||
|
||||
jsonRequest.params.pushKV("blockhash", hash_str);
|
||||
}
|
||||
|
||||
req->WriteHeader("Content-Type", "application/json");
|
||||
req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n");
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
|
||||
{
|
||||
if (!CheckWarmup(req))
|
||||
@@ -939,6 +981,8 @@ static const struct {
|
||||
{"/rest/mempool/", rest_mempool},
|
||||
{"/rest/headers/", rest_headers},
|
||||
{"/rest/getutxos", rest_getutxos},
|
||||
{"/rest/deploymentinfo/", rest_deploymentinfo},
|
||||
{"/rest/deploymentinfo", rest_deploymentinfo},
|
||||
{"/rest/blockhashbyheight/", rest_blockhash_by_height},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user