@@ -590,45 +590,31 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
590
590
}
591
591
}
592
592
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 )
594
594
{
595
595
if (!CheckWarmup (req))
596
596
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);
605
597
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" );
614
602
}
615
- }
616
603
617
- static bool rest_mempool_contents (const std::any& context, HTTPRequest* req, const std::string& strURIPart)
618
- {
619
- if (!CheckWarmup (req)) return false ;
620
604
const CTxMemPool* mempool = GetMemPool (context, req);
621
605
if (!mempool) return false ;
622
- std::string param;
623
- const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
624
606
625
607
switch (rf) {
626
608
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
+ }
628
615
629
- std::string strJSON = mempoolObject.write () + " \n " ;
630
616
req->WriteHeader (" Content-Type" , " application/json" );
631
- req->WriteReply (HTTP_OK, strJSON );
617
+ req->WriteReply (HTTP_OK, str_json );
632
618
return true ;
633
619
}
634
620
default : {
@@ -946,8 +932,7 @@ static const struct {
946
932
{" /rest/blockfilter/" , rest_block_filter},
947
933
{" /rest/blockfilterheaders/" , rest_filter_header},
948
934
{" /rest/chaininfo" , rest_chaininfo},
949
- {" /rest/mempool/info" , rest_mempool_info},
950
- {" /rest/mempool/contents" , rest_mempool_contents},
935
+ {" /rest/mempool/" , rest_mempool},
951
936
{" /rest/headers/" , rest_headers},
952
937
{" /rest/getutxos" , rest_getutxos},
953
938
{" /rest/blockhashbyheight/" , rest_blockhash_by_height},
0 commit comments