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

Code before:
        return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
    }
    }
}


RPCHelpMan getdeploymentinfo();

static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
{
    if (!CheckWarmup(req)) return false;

    std::string hash_str;
    const RESTResponseFormat rf = ParseDataFormat(hash_str, str_uri_part);

    switch (rf) {
    case RESTResponseFormat::JSON: {
        JSONRPCRequest jsonRequest;
        jsonRequest.context = context;
        jsonRequest.params = UniValue(UniValue::VARR);

        if (!hash_str.empty()) {
            uint256 hash;
            if (!ParseHashStr(hash_str, hash)) {
                return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hash_str);
            }

            const ChainstateManager* chainman = GetChainman(context, req);
            if (!chainman) return false;
            if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hash_str, "blockhash")))) {
                return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
            }

            jsonRequest.params.push_back(hash_str);
        }

        req->WriteHeader("Content-Type", "application/json");
        req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n");
        return true;
    }
    default: {
        return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
    }
    }

}

static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
{
    if (!CheckWarmup(req))
        return false;

Review comment (suggestion):
Noticed `ParseHashV(hash_str, ...)` is needlessly called a few lines below instead of using the already verified `hash` value.

Code after:
    }
    default: {
        return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
    }
    }
}


RPCHelpMan getdeploymentinfo();

static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
{
    if (!CheckWarmup(req)) return false;

    std::string hash_str;
    const RESTResponseFormat rf = ParseDataFormat(hash_str, str_uri_part);

    switch (rf) {
    case RESTResponseFormat::JSON: {
        JSONRPCRequest jsonRequest;
        jsonRequest.context = context;
        jsonRequest.params = UniValue(UniValue::VARR);

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

            const ChainstateManager* chainman = GetChainman(context, req);
            if (!chainman) return false;
            if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(*hash))) {
                return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
            }

            jsonRequest.params.push_back(hash_str);
        }

        req->WriteHeader("Content-Type", "application/json");
        req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n");
        return true;
    }
    default: {
        return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
    }
    }

}

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