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);
99 const size_t COOKIE_SIZE = 32;
100 unsigned char rand_pwd[COOKIE_SIZE];
109 file.open(filepath_tmp);
110 if (!file.is_open()) {
123 std::error_code code;
124 fs::permissions(filepath, cookie_perms.value(), fs::perm_options::replace, code);
136 *cookie_out = cookie;
148 std::getline(file, cookie);
152 *cookie_out = cookie;
163 }
catch (
const fs::filesystem_error& e) {
171 throw std::runtime_error(
"Batch must be an array");
173 const size_t num {in.
size()};
174 std::vector<UniValue> batch(num);
176 if (!rec.isObject()) {
177 throw std::runtime_error(
"Batch member must be an object");
179 size_t id = rec[
"id"].getInt<
int>();
181 throw std::runtime_error(
"Batch member id is larger than batch size");
196 if (request.
exists(
"id")) {
205 if (!jsonrpc_version.
isNull()) {
206 if (!jsonrpc_version.
isStr()) {
212 if (jsonrpc_version.
get_str() ==
"1.0") {
214 }
else if (jsonrpc_version.
get_str() ==
"2.0") {
223 if (valMethod.isNull())
225 if (!valMethod.isStr())
236 if (valParams.isArray() || valParams.isObject())
238 else if (valParams.isNull())
static const char *const COOKIEAUTH_FILE
Default name for auth cookie file.
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.
const std::vector< UniValue > & getValues() const
#define LogPrint(category,...)
const std::string & get_str() const
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
const UniValue & find_value(std::string_view key) const
std::vector< UniValue > JSONRPCProcessBatchReply(const UniValue &in)
Parse JSON-RPC batch reply into a vector.
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
UniValue JSONRPCError(int code, const std::string &message)
static std::string PathToString(const path &path)
Convert path object to a byte string.
bool exists(const std::string &key) const
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional< UniValue > id, JSONRPCVersion jsonrpc_version)
std::string get_filesystem_error_message(const fs::filesystem_error &e)
void parse(const UniValue &valRequest)
static bool g_generated_cookie
JSONRPCVersion m_json_version
void pushKV(std::string key, UniValue val)
bool GenerateAuthCookie(std::string *cookie_out, std::optional< fs::perms > cookie_perms)
Generate a new RPC authentication cookie and write it to disk.
const UniValue & get_obj() const
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, const UniValue &id)
JSON-RPC protocol.
const UniValue NullUniValue
static fs::path GetAuthCookieFile(bool temp=false)
Get name of RPC authentication cookie file.
Standard JSON-RPC 2.0 errors.
void GetRandBytes(Span< unsigned char > bytes) noexcept
Generate random data via the internal PRNG.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool GetAuthCookie(std::string *cookie_out)
Read the 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/...
std::string PermsToSymbolicString(fs::perms p)
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.