diff options
author | Andrew Chow <github@achow101.com> | 2023-03-15 19:33:21 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-03-15 19:39:30 -0400 |
commit | ebb15ea75ad1e9c270ecf52e4a0cb67dc0199366 (patch) | |
tree | c4c95bde2fd406f6bfa853be3087dc0576687cd7 /src/rest.cpp | |
parent | 609c95d4a8171544b946037b67b47106ea8c4065 (diff) | |
parent | 1ff5d61dfdaf8987e5619162662e4c760af76a43 (diff) | |
download | bitcoin-ebb15ea75ad1e9c270ecf52e4a0cb67dc0199366.tar.xz |
Merge bitcoin/bitcoin#26207: rest: add verbose and mempool_sequence query params for mempool/contents
1ff5d61dfdaf8987e5619162662e4c760af76a43 doc: add mempool/contents rest verbose and mempool_sequence args (Andrew Toth)
52a31dccc92366efb36db3b94920bdf8b05b264c tests: mempool/contents verbose and mempool_sequence query params tests (Andrew Toth)
a518fff0f2e479064dd4cff6c29fb54c72c1407b rest: add verbose and mempool_sequence query params for mempool/contents (Andrew Toth)
Pull request description:
The verbose mempool json response can get very large. This adds an option to return the non-verbose response of just the txids. It is identical to the rpc response so the diff here is minimal. This also adds the mempool_sequence parameter for rpc consistency. Verbose defaults to true to remain backwards compatible.
It uses query parameters to be compatible with the efforts in https://github.com/bitcoin/bitcoin/issues/25752.
ACKs for top commit:
achow101:
ACK 1ff5d61dfdaf8987e5619162662e4c760af76a43
stickies-v:
re-ACK [1ff5d61](https://github.com/bitcoin/bitcoin/pull/26207/commits/1ff5d61dfdaf8987e5619162662e4c760af76a43)
pablomartin4btc:
tested ACK 1ff5d61dfdaf8987e5619162662e4c760af76a43.
Tree-SHA512: 1bf08a7ffde2e7db14dc746e421feedf17d84c4b3f1141e79e36feb6014811dfde80e1d8dbc476c15ff705de2d3c967b3081dcd80536d76b7edf888f1a92e9d1
Diffstat (limited to 'src/rest.cpp')
-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 a874f4eb6d..fa119ddfb7 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -652,7 +652,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"; } |