| 49 | } |
| 50 | |
| 51 | UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version) |
| 52 | { |
| 53 | UniValue reply(UniValue::VOBJ); |
| 54 | // Add JSON-RPC version number field in v2 only. |
| 55 | if (jsonrpc_version == JSONRPCVersion::V2) reply.pushKV("jsonrpc", "2.0"); |
| 56 | |
| 57 | // Add both result and error fields in v1, even though one will be null. |
| 58 | // Omit the null field in v2. |
| 59 | if (error.isNull()) { |
| 60 | reply.pushKV("result", std::move(result)); |
| 61 | if (jsonrpc_version == JSONRPCVersion::V1_LEGACY) reply.pushKV("error", NullUniValue); |
| 62 | } else { |
| 63 | if (jsonrpc_version == JSONRPCVersion::V1_LEGACY) reply.pushKV("result", NullUniValue); |
| 64 | reply.pushKV("error", std::move(error)); |
| 65 | } |
| 66 | if (id.has_value()) reply.pushKV("id", std::move(id.value())); |
| 67 | return reply; |
| 68 | } |
| 69 | |
| 70 | UniValue JSONRPCError(int code, const std::string& message) |
| 71 | { |
no test coverage detected