diff options
Diffstat (limited to 'src/rest.cpp')
-rw-r--r-- | src/rest.cpp | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/rest.cpp b/src/rest.cpp index a10d8a433f..fa119ddfb7 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2021 The Bitcoin Core developers +// Copyright (c) 2009-2022 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -236,7 +236,7 @@ static bool rest_headers(const std::any& context, switch (rf) { case RESTResponseFormat::BINARY: { - CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION); + DataStream ssHeader{}; for (const CBlockIndex *pindex : headers) { ssHeader << pindex->GetBlockHeader(); } @@ -248,7 +248,7 @@ static bool rest_headers(const std::any& context, } case RESTResponseFormat::HEX: { - CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION); + DataStream ssHeader{}; for (const CBlockIndex *pindex : headers) { ssHeader << pindex->GetBlockHeader(); } @@ -305,8 +305,10 @@ static bool rest_block(const std::any& context, if (chainman.m_blockman.IsBlockPruned(pblockindex)) return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)"); - if (!ReadBlockFromDisk(block, pblockindex, chainman.GetParams().GetConsensus())) - return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); + } + + if (!ReadBlockFromDisk(block, pblockindex, chainman.GetParams().GetConsensus())) { + return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } switch (rf) { @@ -433,7 +435,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const switch (rf) { case RESTResponseFormat::BINARY: { - CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION}; + DataStream ssHeader{}; for (const uint256& header : filter_headers) { ssHeader << header; } @@ -444,7 +446,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const return true; } case RESTResponseFormat::HEX: { - CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION}; + DataStream ssHeader{}; for (const uint256& header : filter_headers) { ssHeader << header; } @@ -532,7 +534,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s switch (rf) { case RESTResponseFormat::BINARY: { - CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION}; + DataStream ssResp{}; ssResp << filter; std::string binaryResp = ssResp.str(); @@ -541,7 +543,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s return true; } case RESTResponseFormat::HEX: { - CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION}; + DataStream ssResp{}; ssResp << filter; std::string strHex = HexStr(ssResp) + "\n"; @@ -650,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"; } @@ -791,7 +806,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std:: if (fInputParsed) //don't allow sending input over URI and HTTP RAW DATA return RESTERR(req, HTTP_BAD_REQUEST, "Combination of URI scheme inputs and raw post data is not allowed"); - CDataStream oss(SER_NETWORK, PROTOCOL_VERSION); + DataStream oss{}; oss << strRequestMutable; oss >> fCheckMemPool; oss >> vOutPoints; @@ -864,7 +879,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std:: case RESTResponseFormat::BINARY: { // serialize data // use exact same output as mentioned in Bip64 - CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); + DataStream ssGetUTXOResponse{}; ssGetUTXOResponse << active_height << active_hash << bitmap << outs; std::string ssGetUTXOResponseString = ssGetUTXOResponse.str(); @@ -874,7 +889,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std:: } case RESTResponseFormat::HEX: { - CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); + DataStream ssGetUTXOResponse{}; ssGetUTXOResponse << active_height << active_hash << bitmap << outs; std::string strHex = HexStr(ssGetUTXOResponse) + "\n"; @@ -944,7 +959,7 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req, } switch (rf) { case RESTResponseFormat::BINARY: { - CDataStream ss_blockhash(SER_NETWORK, PROTOCOL_VERSION); + DataStream ss_blockhash{}; ss_blockhash << pblockindex->GetBlockHash(); req->WriteHeader("Content-Type", "application/octet-stream"); req->WriteReply(HTTP_OK, ss_blockhash.str()); |