44 request.
pushKV(
"method", strMethod);
45 request.
pushKV(
"params", params);
47 request.
pushKV(
"jsonrpc",
"2.0");
60 reply.
pushKV(
"result", std::move(result));
64 reply.
pushKV(
"error", std::move(error));
66 if (
id.has_value()) reply.
pushKV(
"id", std::move(
id.value()));
73 error.
pushKV(
"code", code);
74 error.
pushKV(
"message", message);
104 const size_t COOKIE_SIZE = 32;
105 unsigned char rand_pwd[COOKIE_SIZE];
107 const std::string rand_pwd_hex{
HexStr(rand_pwd)};
114 if (filepath_tmp.empty()) {
117 file.open(filepath_tmp);
118 if (!file.is_open()) {
131 std::error_code code;
132 fs::permissions(filepath, cookie_perms.value(), fs::perm_options::replace, code);
153 if (filepath.empty()) {
159 std::getline(file, cookie);
163 *cookie_out = cookie;
174 }
catch (
const fs::filesystem_error& e) {
182 throw std::runtime_error(
"Batch must be an array");
184 const size_t num {in.
size()};
185 std::vector<UniValue> batch(num);
187 if (!rec.isObject()) {
188 throw std::runtime_error(
"Batch member must be an object");
190 size_t id = rec[
"id"].getInt<
int>();
192 throw std::runtime_error(
"Batch member id is larger than batch size");
207 if (request.
exists(
"id")) {
216 if (!jsonrpc_version.
isNull()) {
217 if (!jsonrpc_version.
isStr()) {
223 if (jsonrpc_version.
get_str() ==
"1.0") {
225 }
else if (jsonrpc_version.
get_str() ==
"2.0") {
234 if (valMethod.isNull())
236 if (!valMethod.isStr())
247 if (valParams.isArray() || valParams.isObject())
249 else if (valParams.isNull())
fs::path AbsPathForConfigVal(const ArgsManager &args, const fs::path &path, bool net_specific=true)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
JSONRPCVersion m_json_version
void parse(const UniValue &valRequest)
const std::string & get_str() const
const UniValue & find_value(std::string_view key) const
const UniValue & get_obj() const
const std::vector< UniValue > & getValues() const
bool exists(const std::string &key) const
void pushKV(std::string key, UniValue val)
static std::string PathToString(const path &path)
Convert path object to a byte string.
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
std::string PermsToSymbolicString(fs::perms p)
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
#define LogDebug(category,...)
void GetRandBytes(std::span< unsigned char > bytes) noexcept
Generate random data via the internal PRNG.
GenerateAuthCookieResult GenerateAuthCookie(const std::optional< fs::perms > &cookie_perms, std::string &user, std::string &pass)
Generate a new RPC authentication cookie and write it to disk.
static fs::path GetAuthCookieFile(bool temp=false)
Get name of RPC authentication cookie file.
std::vector< UniValue > JSONRPCProcessBatchReply(const UniValue &in)
Parse JSON-RPC batch reply into a vector.
bool GetAuthCookie(std::string *cookie_out)
Read the RPC authentication cookie from disk.
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, const UniValue &id)
JSON-RPC protocol.
UniValue JSONRPCError(int code, const std::string &message)
static const char *const COOKIEAUTH_FILE
Default name for auth cookie file.
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional< UniValue > id, JSONRPCVersion jsonrpc_version)
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
static const std::string COOKIEAUTH_USER
Username used when cookie authentication is in use (arbitrary, only for recognizability in debugging/...
static bool g_generated_cookie
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
const UniValue NullUniValue
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.