Repository: bitcoin/bitcoin
File: src/rest.cpp (C++)

Code before:
            return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (not fully downloaded)");
        }
        pos = pblockindex->GetBlockPos();
    }

    std::vector<std::byte> block_data{};
    if (!chainman.m_blockman.ReadRawBlockPart(block_data, pos, part_offset, part_size)) {
        return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
    }

    switch (rf) {
    case RESTResponseFormat::BINARY: {
        req->WriteHeader("Content-Type", "application/octet-stream");
        req->WriteReply(HTTP_OK, block_data);
        return true;
    }

    case RESTResponseFormat::HEX: {
        const std::string strHex{HexStr(block_data) + "\n"};
        req->WriteHeader("Content-Type", "text/plain");
        req->WriteReply(HTTP_OK, strHex);
        return true;
    }

    case RESTResponseFormat::JSON: {
        if (!tx_verbosity.has_value()) {
            return RESTERR(req, HTTP_BAD_REQUEST, "JSON output is not supported for this request type");
        }
        CBlock block{};
        DataStream block_stream{block_data};
        block_stream >> TX_WITH_WITNESS(block);
        UniValue objBlock = blockToJSON(chainman.m_blockman, block, *tip, *pblockindex, *tx_verbosity, chainman.GetConsensus().powLimit);
        std::string strJSON = objBlock.write() + "\n";
        req->WriteHeader("Content-Type", "application/json");
        req->WriteReply(HTTP_OK, strJSON);
        return true;
    }

    default: {
        return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
    }
    }
}

static bool rest_block_extended(const std::any& context, HTTPRequest* req, const std::string& uri_part)
{
    return rest_block(context, req, uri_part, TxVerbosity::SHOW_DETAILS_AND_PREVOUT, /*part_offset=*/std::nullopt, /*part_size=*/std::nullopt);
}

static bool rest_block_notxdetails(const std::any& context, HTTPRequest* req, const std::string& uri_part)
{

Review comment (suggestion):
```suggestion
        if (!tx_verbosity.has_value()) [[unlikely]] { 
```


Code after:
            return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Bad block part offset/size %d/%d for %s", block_part->first, block_part->second, hashStr));
        } // no default case, so the compiler can warn about missing cases
        assert(false);
    }

    switch (rf) {
    case RESTResponseFormat::BINARY: {
        req->WriteHeader("Content-Type", "application/octet-stream");
        req->WriteReply(HTTP_OK, *block_data);
        return true;
    }

    case RESTResponseFormat::HEX: {
        const std::string strHex{HexStr(*block_data) + "\n"};
        req->WriteHeader("Content-Type", "text/plain");
        req->WriteReply(HTTP_OK, strHex);
        return true;
    }

    case RESTResponseFormat::JSON: {
        if (tx_verbosity) {
            CBlock block{};
            DataStream block_stream{*block_data};
            block_stream >> TX_WITH_WITNESS(block);
            UniValue objBlock = blockToJSON(chainman.m_blockman, block, *tip, *pblockindex, *tx_verbosity, chainman.GetConsensus().powLimit);
            std::string strJSON = objBlock.write() + "\n";
            req->WriteHeader("Content-Type", "application/json");
            req->WriteReply(HTTP_OK, strJSON);
            return true;
        }
        return RESTERR(req, HTTP_BAD_REQUEST, "JSON output is not supported for this request type");
    }

    default: {
        return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
    }
    }
}

static bool rest_block_extended(const std::any& context, HTTPRequest* req, const std::string& uri_part)
{
    return rest_block(context, req, uri_part, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
}

static bool rest_block_notxdetails(const std::any& context, HTTPRequest* req, const std::string& uri_part)
{
    return rest_block(context, req, uri_part, TxVerbosity::SHOW_TXID);
}

static bool rest_block_part(const std::any& context, HTTPRequest* req, const std::string& uri_part)
{