Bitcoin Core 28.99.0
P2P Digital Currency
request.h
Go to the documentation of this file.
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
16enum class JSONRPCVersion {
18 V2
19};
20
22UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
23UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version);
24UniValue JSONRPCError(int code, const std::string& message);
25
27bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie_perms=std::nullopt);
29bool GetAuthCookie(std::string *cookie_out);
31void DeleteAuthCookie();
33std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in);
34
36{
37public:
38 std::optional<UniValue> id = UniValue::VNULL;
39 std::string strMethod;
42 std::string URI;
43 std::string authUser;
44 std::string peerAddr;
45 std::any context;
47
48 void parse(const UniValue& valRequest);
49 [[nodiscard]] bool IsNotification() const { return !id.has_value() && m_json_version == JSONRPCVersion::V2; };
50};
51
52#endif // BITCOIN_RPC_REQUEST_H
UniValue params
Definition: request.h:40
std::string strMethod
Definition: request.h:39
JSONRPCVersion m_json_version
Definition: request.h:46
enum JSONRPCRequest::Mode mode
bool IsNotification() const
Definition: request.h:49
std::string peerAddr
Definition: request.h:44
void parse(const UniValue &valRequest)
Definition: request.cpp:197
std::string URI
Definition: request.h:42
std::string authUser
Definition: request.h:43
std::any context
Definition: request.h:45
@ VNULL
Definition: univalue.h:24
@ V2
BIP324 protocol.
std::vector< UniValue > JSONRPCProcessBatchReply(const UniValue &in)
Parse JSON-RPC batch reply into a vector.
Definition: request.cpp:177
bool GetAuthCookie(std::string *cookie_out)
Read the RPC authentication cookie from disk.
Definition: request.cpp:146
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue &params, const UniValue &id)
JSON-RPC 2.0 request, only used in bitcoin-cli.
Definition: request.cpp:41
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:70
JSONRPCVersion
Definition: request.h:16
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional< UniValue > id, JSONRPCVersion jsonrpc_version)
Definition: request.cpp:51
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
Definition: request.cpp:165
bool GenerateAuthCookie(std::string *cookie_out, std::optional< fs::perms > cookie_perms=std::nullopt)
Generate a new RPC authentication cookie and write it to disk.
Definition: request.cpp:100