diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -320,8 +320,7 @@ /** Collect values from the batch and form a simulated `getinfo` reply. */ UniValue ProcessReply(const UniValue &batch_in) override { UniValue result(UniValue::VOBJ); - std::vector batch = - JSONRPCProcessBatchReply(batch_in, batch_in.size()); + const std::vector batch = JSONRPCProcessBatchReply(batch_in); // Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass // them on; getwalletinfo() and getbalances are allowed to fail if there // is no wallet. diff --git a/src/rpc/request.h b/src/rpc/request.h --- a/src/rpc/request.h +++ b/src/rpc/request.h @@ -28,7 +28,7 @@ /** Delete RPC authentication cookie from disk */ void DeleteAuthCookie(); /** Parse JSON-RPC batch reply into a vector */ -std::vector JSONRPCProcessBatchReply(const UniValue &in, size_t num); +std::vector JSONRPCProcessBatchReply(const UniValue &in); class JSONRPCRequest { public: diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp --- a/src/rpc/request.cpp +++ b/src/rpc/request.cpp @@ -134,19 +134,20 @@ } } -std::vector JSONRPCProcessBatchReply(const UniValue &in, size_t num) { +std::vector JSONRPCProcessBatchReply(const UniValue &in) { if (!in.isArray()) { throw std::runtime_error("Batch must be an array"); } + const size_t num{in.size()}; std::vector batch(num); - for (size_t i = 0; i < in.size(); ++i) { - const UniValue &rec = in[i]; + for (const UniValue &rec : in.getValues()) { if (!rec.isObject()) { - throw std::runtime_error("Batch member must be object"); + throw std::runtime_error("Batch member must be an object"); } size_t id = rec["id"].get_int(); if (id >= num) { - throw std::runtime_error("Batch member id larger than size"); + throw std::runtime_error( + "Batch member id is larger than batch size"); } batch[id] = rec; }