32 request.
pushKV(
"method", strMethod);
33 request.
pushKV(
"params", params);
41 if (!
error.isNull()) {
44 reply.
pushKV(
"result", result);
54 return reply.
write() +
"\n";
59 error.pushKV(
"code", code);
60 error.pushKV(
"message", message);
82 const size_t COOKIE_SIZE = 32;
83 uint8_t rand_pwd[COOKIE_SIZE];
93 file.open(filepath_tmp);
94 if (!file.is_open()) {
95 LogPrintf(
"Unable to open cookie authentication file %s for writing\n",
104 LogPrintf(
"Unable to rename cookie authentication file %s to %s\n",
108 LogPrintf(
"Generated RPC authentication cookie %s\n",
112 *cookie_out = cookie;
122 if (!file.is_open()) {
125 std::getline(file, cookie);
129 *cookie_out = cookie;
137 }
catch (
const fs::filesystem_error &e) {
138 LogPrintf(
"%s: Unable to remove random auth cookie file: %s\n",
145 throw std::runtime_error(
"Batch must be an array");
147 const size_t num{in.
size()};
148 std::vector<UniValue> batch(num);
150 if (!rec.isObject()) {
151 throw std::runtime_error(
"Batch member must be an object");
153 size_t id = rec[
"id"].get_int();
155 throw std::runtime_error(
156 "Batch member id is larger than batch size");
176 if (valMethod.isNull()) {
179 if (!valMethod.isStr()) {
193 if (valParams.isArray() || valParams.isObject()) {
195 }
else if (valParams.isNull()) {
199 "Params must be an array or object");
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void parse(const UniValue &valRequest)
const UniValue & find_value(std::string_view key) const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const UniValue & get_obj() const
const std::vector< UniValue > & getValues() const
bool pushKV(const std::string &key, const UniValue &val)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
#define LogPrint(category,...)
static std::string PathToString(const path &path)
Convert path object to byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
std::string get_filesystem_error_message(const fs::filesystem_error &e)
void GetRandBytes(Span< uint8_t > bytes) noexcept
Overall design of the RNG and entropy sources.
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.
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.
static const std::string COOKIEAUTH_FILE
Default name for auth cookie file.
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)
static const std::string COOKIEAUTH_USER
Username used when cookie authentication is in use (arbitrary, only for recognizability in debugging/...
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
bool RenameOver(fs::path src, fs::path dest)
bool error(const char *fmt, const Args &...args)
const UniValue NullUniValue