mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-25 06:55:32 +01:00
rpc: Handle getinfo locally in bitcoin-cli w/ -getinfo
This adds the infrastructure `BaseRequestHandler` class that takes care of converting bitcoin-cli arguments into a JSON-RPC request object, and converting the reply into a JSON object that can be shown as result. This is subsequently used to handle the `-getinfo` option, which sends a JSON-RPC batch request to the RPC server with `["getnetworkinfo", "getblockchaininfo", "getwalletinfo"]`, and after reply combines the result into what looks like a `getinfo` result. There have been some requests for a client-side `getinfo` and this is my PoC of how to do it. If this is considered a good idea some of the logic could be moved up to rpcclient.cpp and used in the GUI console as well. Extra-Author: Andrew Chow <achow101@gmail.com>
This commit is contained in:
committed by
Andrew Chow
parent
ea729d55b4
commit
382625318d
@@ -19,7 +19,7 @@
|
||||
* JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility,
|
||||
* but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were
|
||||
* unspecified (HTTP errors and contents of 'error').
|
||||
*
|
||||
*
|
||||
* 1.0 spec: http://json-rpc.org/wiki/specification
|
||||
* 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html
|
||||
*/
|
||||
@@ -135,3 +135,22 @@ void DeleteAuthCookie()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num)
|
||||
{
|
||||
if (!in.isArray()) {
|
||||
throw std::runtime_error("Batch must be an array");
|
||||
}
|
||||
std::vector<UniValue> batch(num);
|
||||
for (size_t i=0; i<in.size(); ++i) {
|
||||
const UniValue &rec = in[i];
|
||||
if (!rec.isObject()) {
|
||||
throw std::runtime_error("Batch member must be object");
|
||||
}
|
||||
size_t id = rec["id"].get_int();
|
||||
if (id >= num) {
|
||||
throw std::runtime_error("Batch member id larger than size");
|
||||
}
|
||||
batch[id] = rec;
|
||||
}
|
||||
return batch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user