Skip to content

Commit 9149703

Browse files
committed
rest: add /deploymentinfo
1 parent a5d5569 commit 9149703

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/rest.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,48 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
590590
}
591591
}
592592

593+
594+
RPCHelpMan getdeploymentinfo();
595+
596+
static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
597+
{
598+
if (!CheckWarmup(req)) return false;
599+
600+
std::string hash_str;
601+
const RESTResponseFormat rf = ParseDataFormat(hash_str, str_uri_part);
602+
603+
switch (rf) {
604+
case RESTResponseFormat::JSON: {
605+
JSONRPCRequest jsonRequest;
606+
jsonRequest.context = context;
607+
jsonRequest.params = UniValue(UniValue::VARR);
608+
609+
if (!hash_str.empty()) {
610+
uint256 hash;
611+
if (!ParseHashStr(hash_str, hash)) {
612+
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hash_str);
613+
}
614+
615+
const ChainstateManager* chainman = GetChainman(context, req);
616+
if (!chainman) return false;
617+
if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hash_str, "blockhash")))) {
618+
return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
619+
}
620+
621+
jsonRequest.params.pushKV("blockhash", hash_str);
622+
}
623+
624+
req->WriteHeader("Content-Type", "application/json");
625+
req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n");
626+
return true;
627+
}
628+
default: {
629+
return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
630+
}
631+
}
632+
633+
}
634+
593635
static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
594636
{
595637
if (!CheckWarmup(req))
@@ -935,6 +977,8 @@ static const struct {
935977
{"/rest/mempool/", rest_mempool},
936978
{"/rest/headers/", rest_headers},
937979
{"/rest/getutxos", rest_getutxos},
980+
{"/rest/deploymentinfo/", rest_deploymentinfo},
981+
{"/rest/deploymentinfo", rest_deploymentinfo},
938982
{"/rest/blockhashbyheight/", rest_blockhash_by_height},
939983
};
940984

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ UniValue DeploymentInfo(const CBlockIndex* blockindex, const ChainstateManager&
13071307
}
13081308
} // anon namespace
13091309

1310-
static RPCHelpMan getdeploymentinfo()
1310+
RPCHelpMan getdeploymentinfo()
13111311
{
13121312
return RPCHelpMan{"getdeploymentinfo",
13131313
"Returns an object containing various state info regarding deployments of consensus changes.",

0 commit comments

Comments
 (0)