mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
rest: clean-up for mempool
endpoints
This commit is contained in:
parent
1d89fc695a
commit
acbea66589
1 changed files with 16 additions and 31 deletions
47
src/rest.cpp
47
src/rest.cpp
|
@ -590,45 +590,31 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rest_mempool_info(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
|
static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
|
||||||
{
|
{
|
||||||
if (!CheckWarmup(req))
|
if (!CheckWarmup(req))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
std::string param;
|
||||||
|
const RESTResponseFormat rf = ParseDataFormat(param, str_uri_part);
|
||||||
|
if (param != "contents" && param != "info") {
|
||||||
|
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/mempool/<info|contents>.json");
|
||||||
|
}
|
||||||
|
|
||||||
const CTxMemPool* mempool = GetMemPool(context, req);
|
const CTxMemPool* mempool = GetMemPool(context, req);
|
||||||
if (!mempool) return false;
|
if (!mempool) return false;
|
||||||
std::string param;
|
|
||||||
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
|
|
||||||
|
|
||||||
switch (rf) {
|
switch (rf) {
|
||||||
case RESTResponseFormat::JSON: {
|
case RESTResponseFormat::JSON: {
|
||||||
UniValue mempoolInfoObject = MempoolInfoToJSON(*mempool);
|
std::string str_json;
|
||||||
|
if (param == "contents") {
|
||||||
|
str_json = MempoolToJSON(*mempool, true).write() + "\n";
|
||||||
|
} else {
|
||||||
|
str_json = MempoolInfoToJSON(*mempool).write() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
std::string strJSON = mempoolInfoObject.write() + "\n";
|
|
||||||
req->WriteHeader("Content-Type", "application/json");
|
req->WriteHeader("Content-Type", "application/json");
|
||||||
req->WriteReply(HTTP_OK, strJSON);
|
req->WriteReply(HTTP_OK, str_json);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rest_mempool_contents(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
|
|
||||||
{
|
|
||||||
if (!CheckWarmup(req)) return false;
|
|
||||||
const CTxMemPool* mempool = GetMemPool(context, req);
|
|
||||||
if (!mempool) return false;
|
|
||||||
std::string param;
|
|
||||||
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
|
|
||||||
|
|
||||||
switch (rf) {
|
|
||||||
case RESTResponseFormat::JSON: {
|
|
||||||
UniValue mempoolObject = MempoolToJSON(*mempool, true);
|
|
||||||
|
|
||||||
std::string strJSON = mempoolObject.write() + "\n";
|
|
||||||
req->WriteHeader("Content-Type", "application/json");
|
|
||||||
req->WriteReply(HTTP_OK, strJSON);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -946,8 +932,7 @@ static const struct {
|
||||||
{"/rest/blockfilter/", rest_block_filter},
|
{"/rest/blockfilter/", rest_block_filter},
|
||||||
{"/rest/blockfilterheaders/", rest_filter_header},
|
{"/rest/blockfilterheaders/", rest_filter_header},
|
||||||
{"/rest/chaininfo", rest_chaininfo},
|
{"/rest/chaininfo", rest_chaininfo},
|
||||||
{"/rest/mempool/info", rest_mempool_info},
|
{"/rest/mempool/", rest_mempool},
|
||||||
{"/rest/mempool/contents", rest_mempool_contents},
|
|
||||||
{"/rest/headers/", rest_headers},
|
{"/rest/headers/", rest_headers},
|
||||||
{"/rest/getutxos", rest_getutxos},
|
{"/rest/getutxos", rest_getutxos},
|
||||||
{"/rest/blockhashbyheight/", rest_blockhash_by_height},
|
{"/rest/blockhashbyheight/", rest_blockhash_by_height},
|
||||||
|
|
Loading…
Add table
Reference in a new issue