Skip to content

Commit acbea66

Browse files
committed
rest: clean-up for mempool endpoints
1 parent 1d89fc6 commit acbea66

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/rest.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -590,45 +590,31 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
590590
}
591591
}
592592

593-
static bool rest_mempool_info(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
593+
static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
594594
{
595595
if (!CheckWarmup(req))
596596
return false;
597-
const CTxMemPool* mempool = GetMemPool(context, req);
598-
if (!mempool) return false;
599-
std::string param;
600-
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
601-
602-
switch (rf) {
603-
case RESTResponseFormat::JSON: {
604-
UniValue mempoolInfoObject = MempoolInfoToJSON(*mempool);
605597

606-
std::string strJSON = mempoolInfoObject.write() + "\n";
607-
req->WriteHeader("Content-Type", "application/json");
608-
req->WriteReply(HTTP_OK, strJSON);
609-
return true;
610-
}
611-
default: {
612-
return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
613-
}
598+
std::string param;
599+
const RESTResponseFormat rf = ParseDataFormat(param, str_uri_part);
600+
if (param != "contents" && param != "info") {
601+
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/mempool/<info|contents>.json");
614602
}
615-
}
616603

617-
static bool rest_mempool_contents(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
618-
{
619-
if (!CheckWarmup(req)) return false;
620604
const CTxMemPool* mempool = GetMemPool(context, req);
621605
if (!mempool) return false;
622-
std::string param;
623-
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
624606

625607
switch (rf) {
626608
case RESTResponseFormat::JSON: {
627-
UniValue mempoolObject = MempoolToJSON(*mempool, true);
609+
std::string str_json;
610+
if (param == "contents") {
611+
str_json = MempoolToJSON(*mempool, true).write() + "\n";
612+
} else {
613+
str_json = MempoolInfoToJSON(*mempool).write() + "\n";
614+
}
628615

629-
std::string strJSON = mempoolObject.write() + "\n";
630616
req->WriteHeader("Content-Type", "application/json");
631-
req->WriteReply(HTTP_OK, strJSON);
617+
req->WriteReply(HTTP_OK, str_json);
632618
return true;
633619
}
634620
default: {
@@ -946,8 +932,7 @@ static const struct {
946932
{"/rest/blockfilter/", rest_block_filter},
947933
{"/rest/blockfilterheaders/", rest_filter_header},
948934
{"/rest/chaininfo", rest_chaininfo},
949-
{"/rest/mempool/info", rest_mempool_info},
950-
{"/rest/mempool/contents", rest_mempool_contents},
935+
{"/rest/mempool/", rest_mempool},
951936
{"/rest/headers/", rest_headers},
952937
{"/rest/getutxos", rest_getutxos},
953938
{"/rest/blockhashbyheight/", rest_blockhash_by_height},

0 commit comments

Comments
 (0)