diff options
author | Andrew Toth <andrewstoth@gmail.com> | 2022-10-03 23:28:56 -0400 |
---|---|---|
committer | Andrew Toth <andrewstoth@gmail.com> | 2022-10-05 09:25:07 -0400 |
commit | a518fff0f2e479064dd4cff6c29fb54c72c1407b (patch) | |
tree | 7e379e945a4d45d4b51841fc8cfa011b04cbd0ee | |
parent | b2e6d37b51f99d7af8d9a1396b1c9d207db59e58 (diff) | |
download | bitcoin-a518fff0f2e479064dd4cff6c29fb54c72c1407b.tar.xz |
rest: add verbose and mempool_sequence query params for mempool/contents
-rw-r--r-- | src/rest.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/rest.cpp b/src/rest.cpp index 7f00db2222..c3c7943369 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -608,7 +608,20 @@ static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::s case RESTResponseFormat::JSON: { std::string str_json; if (param == "contents") { - str_json = MempoolToJSON(*mempool, true).write() + "\n"; + const std::string raw_verbose{req->GetQueryParameter("verbose").value_or("true")}; + if (raw_verbose != "true" && raw_verbose != "false") { + return RESTERR(req, HTTP_BAD_REQUEST, "The \"verbose\" query parameter must be either \"true\" or \"false\"."); + } + const std::string raw_mempool_sequence{req->GetQueryParameter("mempool_sequence").value_or("false")}; + if (raw_mempool_sequence != "true" && raw_mempool_sequence != "false") { + return RESTERR(req, HTTP_BAD_REQUEST, "The \"mempool_sequence\" query parameter must be either \"true\" or \"false\"."); + } + const bool verbose{raw_verbose == "true"}; + const bool mempool_sequence{raw_mempool_sequence == "true"}; + if (verbose && mempool_sequence) { + return RESTERR(req, HTTP_BAD_REQUEST, "Verbose results cannot contain mempool sequence values. (hint: set \"verbose=false\")"); + } + str_json = MempoolToJSON(*mempool, verbose, mempool_sequence).write() + "\n"; } else { str_json = MempoolInfoToJSON(*mempool).write() + "\n"; } |