| 201 | } |
| 202 | |
| 203 | void JSONRPCRequest::parse(const UniValue& valRequest) |
| 204 | { |
| 205 | // Parse request |
| 206 | if (!valRequest.isObject()) |
| 207 | throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object"); |
| 208 | const UniValue& request = valRequest.get_obj(); |
| 209 | |
| 210 | // Parse id now so errors from here on will have the id |
| 211 | id = find_value(request, "id"); |
| 212 | |
| 213 | // Parse method |
| 214 | UniValue valMethod = find_value(request, "method"); |
| 215 | if (valMethod.isNull()) |
| 216 | throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method"); |
| 217 | if (!valMethod.isStr()) |
| 218 | throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); |
| 219 | strMethod = valMethod.get_str(); |
| 220 | if (fLogIPs) |
| 221 | LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s peeraddr=%s\n", SanitizeString(strMethod), |
| 222 | this->authUser, this->peerAddr); |
| 223 | else |
| 224 | LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s\n", SanitizeString(strMethod), this->authUser); |
| 225 | |
| 226 | // Parse params |
| 227 | UniValue valParams = find_value(request, "params"); |
| 228 | if (valParams.isArray() || valParams.isObject()) |
| 229 | params = valParams; |
| 230 | else if (valParams.isNull()) |
| 231 | params = UniValue(UniValue::VARR); |
| 232 | else |
| 233 | throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object"); |
| 234 | } |