Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_RPC_REQUEST_H7#define BITCOIN_RPC_REQUEST_H9#include <univalue.h>10#include <util/fs.h>12#include <any>13#include <cstdint>14#include <optional>15#include <string>16#include <vector>18enum class JSONRPCVersion {19V1_LEGACY,20V221};23/** JSON-RPC 2.0 request, only used in bitcoin-cli **/24UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);25UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version);26UniValue JSONRPCError(int code, const std::string& message);28enum class AuthCookieResult : uint8_t {29Disabled, // -norpccookiefile30Error,31Ok,32};34/**35* Generate a new RPC authentication cookie and write it to disk36* @param[in] cookie_perms Filesystem permissions to use for the cookie file.37* @param[out] user Generated username, only set if `OK` is returned.38* @param[out] pass Generated password, only set if `OK` is returned.39* @retval AuthCookieResult::Disabled Authentication via cookie is disabled.40* @retval AuthCookieResult::Error Error occurred, auth data could not be saved to disk.41* @retval AuthCookieResult::Ok Auth data was generated, saved to disk and in `user` and `pass`.42*/43AuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cookie_perms,44std::string& user,45std::string& pass);47/** Read the RPC authentication cookie from disk */48AuthCookieResult GetAuthCookie(std::string& cookie_out);49/** Delete RPC authentication cookie from disk */50void DeleteAuthCookie();51/** Parse JSON-RPC batch reply into a vector */52std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in);54class JSONRPCRequest55{56public:57std::optional<UniValue> id = UniValue::VNULL;58std::string strMethod;59UniValue params;60enum Mode { EXECUTE, GET_HELP, GET_ARGS } mode = EXECUTE;61std::string URI;62std::string authUser;63std::string peerAddr;64std::any context;65JSONRPCVersion m_json_version = JSONRPCVersion::V1_LEGACY;67void parse(const UniValue& valRequest);68[[nodiscard]] bool IsNotification() const { return !id.has_value() && m_json_version == JSONRPCVersion::V2; };69};71#endif // BITCOIN_RPC_REQUEST_H