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

Code before:
        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(const std::any& context,
                       HTTPRequest* req,
                       const std::string& uri_part,
                       TxVerbosity tx_verbosity)
{
    if (!CheckWarmup(req))
        return false;
    std::string hashStr;
    const RESTResponseFormat rf = ParseDataFormat(hashStr, uri_part);

    auto hash{uint256::FromHex(hashStr)};
    if (!hash) {
        return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
    }

    FlatFilePos pos{};
    const CBlockIndex* pblockindex = nullptr;
    const CBlockIndex* tip = nullptr;
    ChainstateManager* maybe_chainman = GetChainman(context, req);
    if (!maybe_chainman) return false;
    ChainstateManager& chainman = *maybe_chainman;
    {
        LOCK(cs_main);
        tip = chainman.ActiveChain().Tip();
        pblockindex = chainman.m_blockman.LookupBlockIndex(*hash);
        if (!pblockindex) {
            return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
        }
        if (!(pblockindex->nStatus & BLOCK_HAVE_DATA)) {
            if (chainman.m_blockman.IsBlockPruned(*pblockindex)) {
                return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
            }
            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.ReadRawBlock(block_data, pos)) {
        return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");

Review comment (suggestion):
nit: Consistency
```suggestion
 * - `/blockpart/` via `rest_block_part()` (doesn't support JSON response, so `tx_verbosity` is unset)
```

Code after:
        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() + ")");
    }
    }
}

/**
 * This handler is used by multiple HTTP endpoints:
 * - `/block/` via `rest_block_extended()`
 * - `/block/notxdetails/` via `rest_block_notxdetails()`
 * - `/blockpart/` via `rest_block_part()` (doesn't support JSON response, so `tx_verbosity` is unset)
 */
static bool rest_block(const std::any& context,
                       HTTPRequest* req,
                       const std::string& uri_part,
                       std::optional<TxVerbosity> tx_verbosity,
                       std::optional<std::pair<size_t, size_t>> block_part = std::nullopt)
{
    if (!CheckWarmup(req))
        return false;
    std::string hashStr;
    const RESTResponseFormat rf = ParseDataFormat(hashStr, uri_part);

    auto hash{uint256::FromHex(hashStr)};
    if (!hash) {
        return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
    }

    FlatFilePos pos{};
    const CBlockIndex* pblockindex = nullptr;
    const CBlockIndex* tip = nullptr;
    ChainstateManager* maybe_chainman = GetChainman(context, req);
    if (!maybe_chainman) return false;
    ChainstateManager& chainman = *maybe_chainman;
    {
        LOCK(cs_main);
        tip = chainman.ActiveChain().Tip();
        pblockindex = chainman.m_blockman.LookupBlockIndex(*hash);
        if (!pblockindex) {
            return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
        }
        if (!(pblockindex->nStatus & BLOCK_HAVE_DATA)) {
            if (chainman.m_blockman.IsBlockPruned(*pblockindex)) {
                return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
            }
            return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (not fully downloaded)");