29 request.
pushKV(
"method", strMethod);
30 request.
pushKV(
"params", params);
41 reply.
pushKV(
"result", result);
50 return reply.
write() +
"\n";
56 error.pushKV(
"code", code);
57 error.pushKV(
"message", message);
64 static const std::string COOKIEAUTH_USER =
"__cookie__";
66 static const std::string COOKIEAUTH_FILE =
".cookie";
70 fs::path path(
gArgs.
GetArg(
"-rpccookiefile", COOKIEAUTH_FILE));
76 const size_t COOKIE_SIZE = 32;
77 unsigned char rand_pwd[COOKIE_SIZE];
79 std::string cookie = COOKIEAUTH_USER +
":" +
HexStr(rand_pwd);
86 file.open(filepath_tmp);
87 if (!file.is_open()) {
88 LogPrintf(
"Unable to open cookie authentication file %s for writing\n", filepath_tmp.string());
93 LogPrintf(
"Generated RPC authentication cookie %s\n", filepath_tmp.string());
108 std::getline(file, cookie);
112 *cookie_out = cookie;
120 }
catch (
const fs::filesystem_error& e) {
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool pushKV(const std::string &key, const UniValue &val)
std::string get_filesystem_error_message(const fs::filesystem_error &e)
void GetRandBytes(unsigned char *buf, int num) noexcept
Overall design of the RNG and entropy sources.
bool GetAuthCookie(std::string *cookie_out)
Read the RPC authentication cookie from disk.
fs::path GetAuthCookieFile()
Get name of RPC authentication cookie file.
std::string JSONRPCReply(const UniValue &result, const UniValue &error, const UniValue &id)
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, const UniValue &id)
JSON-RPC protocol.
UniValue JSONRPCError(int code, const std::string &message)
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
bool GenerateAuthCookie(std::string *cookie_out)
Generate a new RPC authentication cookie and write it to disk.
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific)
bool error(const char *fmt, const Args &... args)
const UniValue NullUniValue
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.