Line data Source code
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 : 22 : /** Generate a new RPC authentication cookie and write it to disk */ 23 : bool GenerateAuthCookie(std::string *cookie_out); 24 : /** Read the RPC authentication cookie from disk */ 25 : bool GetAuthCookie(std::string *cookie_out); 26 : /** Delete RPC authentication cookie from disk */ 27 : void DeleteAuthCookie(); 28 : /** Parse JSON-RPC batch reply into a vector */ 29 : std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in); 30 : 31 355122 : class JSONRPCRequest 32 : { 33 : public: 34 : UniValue id; 35 : std::string strMethod; 36 : UniValue params; 37 : bool fHelp; 38 : std::string URI; 39 : std::string authUser; 40 : std::string peerAddr; 41 : const util::Ref& context; 42 : 43 158246 : JSONRPCRequest(const util::Ref& context) : id(NullUniValue), params(NullUniValue), fHelp(false), context(context) {} 44 : 45 : //! Initializes request information from another request object and the 46 : //! given context. The implementation should be updated if any members are 47 : //! added or removed above. 48 37064 : JSONRPCRequest(const JSONRPCRequest& other, const util::Ref& context) 49 18532 : : id(other.id), strMethod(other.strMethod), params(other.params), fHelp(other.fHelp), URI(other.URI), 50 18532 : authUser(other.authUser), peerAddr(other.peerAddr), context(context) 51 18532 : { 52 37064 : } 53 : 54 : void parse(const UniValue& valRequest); 55 : }; 56 : 57 : #endif // BITCOIN_RPC_REQUEST_H