2019-06-20 02:39:38 +09:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2009-2021 The Bitcoin Core developers
|
2019-06-20 02:39:38 +09:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_RPC_REQUEST_H
|
|
|
|
#define BITCOIN_RPC_REQUEST_H
|
|
|
|
|
2020-12-01 00:36:36 +01:00
|
|
|
#include <any>
|
2023-07-07 15:06:35 -04:00
|
|
|
#include <optional>
|
2019-06-20 02:39:38 +09:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <univalue.h>
|
2024-01-08 15:02:44 +00:00
|
|
|
#include <util/fs.h>
|
2019-06-20 02:39:38 +09:00
|
|
|
|
2023-07-07 14:31:18 -04:00
|
|
|
enum class JSONRPCVersion {
|
|
|
|
V1_LEGACY,
|
|
|
|
V2
|
|
|
|
};
|
|
|
|
|
2024-06-06 10:25:48 -04:00
|
|
|
/** JSON-RPC 2.0 request, only used in bitcoin-cli **/
|
2019-06-20 02:39:38 +09:00
|
|
|
UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
|
2023-07-07 15:06:35 -04:00
|
|
|
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version);
|
2019-06-20 02:39:38 +09:00
|
|
|
UniValue JSONRPCError(int code, const std::string& message);
|
|
|
|
|
|
|
|
/** Generate a new RPC authentication cookie and write it to disk */
|
2024-01-08 15:02:44 +00:00
|
|
|
bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie_perms=std::nullopt);
|
2019-06-20 02:39:38 +09:00
|
|
|
/** Read the RPC authentication cookie from disk */
|
|
|
|
bool GetAuthCookie(std::string *cookie_out);
|
|
|
|
/** Delete RPC authentication cookie from disk */
|
|
|
|
void DeleteAuthCookie();
|
|
|
|
/** Parse JSON-RPC batch reply into a vector */
|
2020-04-12 21:46:16 +02:00
|
|
|
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in);
|
2019-06-20 02:39:38 +09:00
|
|
|
|
|
|
|
class JSONRPCRequest
|
|
|
|
{
|
|
|
|
public:
|
2023-07-07 15:06:35 -04:00
|
|
|
std::optional<UniValue> id = UniValue::VNULL;
|
2019-06-20 02:39:38 +09:00
|
|
|
std::string strMethod;
|
|
|
|
UniValue params;
|
2021-01-29 18:15:48 -05:00
|
|
|
enum Mode { EXECUTE, GET_HELP, GET_ARGS } mode = EXECUTE;
|
2019-06-20 02:39:38 +09:00
|
|
|
std::string URI;
|
|
|
|
std::string authUser;
|
|
|
|
std::string peerAddr;
|
2021-04-02 13:35:01 -04:00
|
|
|
std::any context;
|
2023-07-07 14:31:18 -04:00
|
|
|
JSONRPCVersion m_json_version = JSONRPCVersion::V1_LEGACY;
|
2020-05-28 02:13:19 -04:00
|
|
|
|
2019-06-20 02:39:38 +09:00
|
|
|
void parse(const UniValue& valRequest);
|
2023-07-07 15:06:35 -04:00
|
|
|
[[nodiscard]] bool IsNotification() const { return !id.has_value() && m_json_version == JSONRPCVersion::V2; };
|
2019-06-20 02:39:38 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_RPC_REQUEST_H
|