| 437 | } |
| 438 | |
| 439 | void JSONRequest::parse(const UniValue& valRequest) |
| 440 | { |
| 441 | // Parse request |
| 442 | if (!valRequest.isObject()) |
| 443 | throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object"); |
| 444 | const UniValue& request = valRequest.get_obj(); |
| 445 | |
| 446 | // Parse id now so errors from here on will have the id |
| 447 | id = find_value(request, "id"); |
| 448 | |
| 449 | // Parse method |
| 450 | UniValue valMethod = find_value(request, "method"); |
| 451 | if (valMethod.isNull()) |
| 452 | throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method"); |
| 453 | if (!valMethod.isStr()) |
| 454 | throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); |
| 455 | strMethod = valMethod.get_str(); |
| 456 | if (strMethod != "getblocktemplate") |
| 457 | LogPrint("rpc", "ThreadRPCServer method=%s\n", SanitizeString(strMethod)); |
| 458 | |
| 459 | // Parse params |
| 460 | UniValue valParams = find_value(request, "params"); |
| 461 | if (valParams.isArray()) |
| 462 | params = valParams.get_array(); |
| 463 | else if (valParams.isNull()) |
| 464 | params = UniValue(UniValue::VARR); |
| 465 | else |
| 466 | throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array"); |
| 467 | } |
| 468 | |
| 469 | static UniValue JSONRPCExecOne(const UniValue& req) |
| 470 | { |
no test coverage detected