Bitcoin Core  0.20.99
P2P Digital Currency
request.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <string>
10 
11 #include <univalue.h>
12 
13 namespace util {
14 class Ref;
15 } // namespace util
16 
17 UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
18 UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id);
19 std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id);
20 UniValue JSONRPCError(int code, const std::string& message);
21 
23 bool GenerateAuthCookie(std::string *cookie_out);
25 bool GetAuthCookie(std::string *cookie_out);
27 void DeleteAuthCookie();
29 std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in);
30 
32 {
33 public:
35  std::string strMethod;
37  bool fHelp;
38  std::string URI;
39  std::string authUser;
40  std::string peerAddr;
42 
43  JSONRPCRequest(const util::Ref& context) : id(NullUniValue), params(NullUniValue), fHelp(false), context(context) {}
44 
48  JSONRPCRequest(const JSONRPCRequest& other, const util::Ref& context)
49  : id(other.id), strMethod(other.strMethod), params(other.params), fHelp(other.fHelp), URI(other.URI),
50  authUser(other.authUser), peerAddr(other.peerAddr), context(context)
51  {
52  }
53 
54  void parse(const UniValue& valRequest);
55 };
56 
57 #endif // BITCOIN_RPC_REQUEST_H
const util::Ref & context
Definition: request.h:41
Definition: httprpc.h:8
std::vector< UniValue > JSONRPCProcessBatchReply(const UniValue &in)
Parse JSON-RPC batch reply into a vector.
Definition: request.cpp:133
std::string JSONRPCReply(const UniValue &result, const UniValue &error, const UniValue &id)
Definition: request.cpp:45
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
Definition: request.cpp:124
std::string strMethod
Definition: request.h:35
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue &params, const UniValue &id)
JSON-RPC protocol.
Definition: request.cpp:24
std::string peerAddr
Definition: request.h:40
bool GetAuthCookie(std::string *cookie_out)
Read the RPC authentication cookie from disk.
Definition: request.cpp:108
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:51
UniValue params
Definition: request.h:36
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
Definition: request.cpp:33
UniValue id
Definition: request.h:34
JSONRPCRequest(const util::Ref &context)
Definition: request.h:43
Type-safe dynamic reference.
Definition: ref.h:21
bool fHelp
Definition: request.h:37
bool GenerateAuthCookie(std::string *cookie_out)
Generate a new RPC authentication cookie and write it to disk.
Definition: request.cpp:76
std::string URI
Definition: request.h:38
std::string authUser
Definition: request.h:39
const UniValue NullUniValue
Definition: univalue.cpp:13
JSONRPCRequest(const JSONRPCRequest &other, const util::Ref &context)
Initializes request information from another request object and the given context.
Definition: request.h:48
bool error(const char *fmt, const Args &... args)
Definition: system.h:50