diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-09-28 08:33:12 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-09-28 08:33:36 +0200 |
commit | c9a4aa8a0e7e0e22f2d8bbf88f58eb749ad83a25 (patch) | |
tree | ee07628ca362621060d28660c71f2abd4d6b051e /src/rpc | |
parent | d90a00eabed0f3f1acea4834ad489484d0012372 (diff) | |
parent | 5e69a430ee260950b69e0c36394671381add2b94 (diff) |
Merge #10871: Handle getinfo in bitcoin-cli w/ -getinfo (revival of #8843)
5e69a43 Add test for bitcoin-cli -getinfo (John Newbery)
3826253 rpc: Handle `getinfo` locally in bitcoin-cli w/ `-getinfo` (Wladimir J. van der Laan)
Pull request description:
Since @laanwj doesn't want to maintain these changes anymore, I will.
This PR is a revival of #8843. I have addressed @jnewbery's comments.
Regarding atomicity, I don't think that is a concern here. This is explicitly a new API and those who use it will know that this is different and that it is not atomic.
Tree-SHA512: 9664ed13a5557bda8c43f34d6527669a641f260b7830e592409b28c845258fc7e0fdd85dd42bfa88c103fea3ecdfede5f81e3d91870e2accba81c6d6de6b21ff
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/protocol.cpp | 21 | ||||
-rw-r--r-- | src/rpc/protocol.h | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp index dc6bcec382..1f4ae75b18 100644 --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -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; +} diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h index 056f93e7db..cb668f3db9 100644 --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -98,5 +98,7 @@ bool GenerateAuthCookie(std::string *cookie_out); bool GetAuthCookie(std::string *cookie_out); /** Delete RPC authentication cookie from disk */ void DeleteAuthCookie(); +/** Parse JSON-RPC batch reply into a vector */ +std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num); #endif // BITCOIN_RPCPROTOCOL_H |