|
1 | 1 | // Copyright (c) 2010 Satoshi Nakamoto |
2 | | -// Copyright (c) 2009-2018 The Bitcoin Core developers |
| 2 | +// Copyright (c) 2009-2019 The Bitcoin Core developers |
3 | 3 | // Distributed under the MIT software license, see the accompanying |
4 | 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | 5 |
|
6 | | -#include <rpc/protocol.h> |
| 6 | +#include <rpc/request.h> |
| 7 | + |
| 8 | +#include <fs.h> |
7 | 9 |
|
8 | 10 | #include <random.h> |
9 | | -#include <tinyformat.h> |
| 11 | +#include <rpc/protocol.h> |
10 | 12 | #include <util/system.h> |
11 | 13 | #include <util/strencodings.h> |
12 | | -#include <util/time.h> |
13 | 14 |
|
14 | 15 | /** |
15 | 16 | * JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility, |
@@ -148,3 +149,36 @@ std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num) |
148 | 149 | } |
149 | 150 | return batch; |
150 | 151 | } |
| 152 | + |
| 153 | +void JSONRPCRequest::parse(const UniValue& valRequest) |
| 154 | +{ |
| 155 | + // Parse request |
| 156 | + if (!valRequest.isObject()) |
| 157 | + throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object"); |
| 158 | + const UniValue& request = valRequest.get_obj(); |
| 159 | + |
| 160 | + // Parse id now so errors from here on will have the id |
| 161 | + id = find_value(request, "id"); |
| 162 | + |
| 163 | + // Parse method |
| 164 | + UniValue valMethod = find_value(request, "method"); |
| 165 | + if (valMethod.isNull()) |
| 166 | + throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method"); |
| 167 | + if (!valMethod.isStr()) |
| 168 | + throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); |
| 169 | + strMethod = valMethod.get_str(); |
| 170 | + if (fLogIPs) |
| 171 | + LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s peeraddr=%s\n", SanitizeString(strMethod), |
| 172 | + this->authUser, this->peerAddr); |
| 173 | + else |
| 174 | + LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s\n", SanitizeString(strMethod), this->authUser); |
| 175 | + |
| 176 | + // Parse params |
| 177 | + UniValue valParams = find_value(request, "params"); |
| 178 | + if (valParams.isArray() || valParams.isObject()) |
| 179 | + params = valParams; |
| 180 | + else if (valParams.isNull()) |
| 181 | + params = UniValue(UniValue::VARR); |
| 182 | + else |
| 183 | + throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object"); |
| 184 | +} |
0 commit comments