fuzz coverage

Coverage Report

Created: 2025-06-01 19:34

/Users/eugenesiegel/btc/bitcoin/src/rpc/request.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2021 The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_RPC_REQUEST_H
7
#define BITCOIN_RPC_REQUEST_H
8
9
#include <any>
10
#include <optional>
11
#include <string>
12
13
#include <univalue.h>
14
#include <util/fs.h>
15
16
enum class JSONRPCVersion {
17
    V1_LEGACY,
18
    V2
19
};
20
21
/** JSON-RPC 2.0 request, only used in bitcoin-cli **/
22
UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
23
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version);
24
UniValue JSONRPCError(int code, const std::string& message);
25
26
/** Generate a new RPC authentication cookie and write it to disk */
27
bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie_perms=std::nullopt);
28
/** Read the RPC authentication cookie from disk */
29
bool GetAuthCookie(std::string *cookie_out);
30
/** Delete RPC authentication cookie from disk */
31
void DeleteAuthCookie();
32
/** Parse JSON-RPC batch reply into a vector */
33
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in);
34
35
class JSONRPCRequest
36
{
37
public:
38
    std::optional<UniValue> id = UniValue::VNULL;
39
    std::string strMethod;
40
    UniValue params;
41
    enum Mode { EXECUTE, GET_HELP, GET_ARGS } mode = EXECUTE;
42
    std::string URI;
43
    std::string authUser;
44
    std::string peerAddr;
45
    std::any context;
46
    JSONRPCVersion m_json_version = JSONRPCVersion::V1_LEGACY;
47
48
    void parse(const UniValue& valRequest);
49
0
    [[nodiscard]] bool IsNotification() const { return !id.has_value() && m_json_version == JSONRPCVersion::V2; };
50
};
51
52
#endif // BITCOIN_RPC_REQUEST_H