Skip to content

Commit 903b6c1

Browse files
committed
rpc: drop unused JSONRPCProcessBatchReply size arg, refactor
1 parent afce85e commit 903b6c1

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
251251
UniValue ProcessReply(const UniValue &batch_in) override
252252
{
253253
UniValue result(UniValue::VOBJ);
254-
std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, batch_in.size());
254+
const std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in);
255255
// Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on;
256256
// getwalletinfo() and getbalances() are allowed to fail if there is no wallet.
257257
if (!batch[ID_NETWORKINFO]["error"].isNull()) {

src/rpc/request.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,20 @@ void DeleteAuthCookie()
130130
}
131131
}
132132

133-
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num)
133+
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in)
134134
{
135135
if (!in.isArray()) {
136136
throw std::runtime_error("Batch must be an array");
137137
}
138+
const size_t num {in.size()};
138139
std::vector<UniValue> batch(num);
139-
for (size_t i=0; i<in.size(); ++i) {
140-
const UniValue &rec = in[i];
140+
for (const UniValue& rec : in.getValues()) {
141141
if (!rec.isObject()) {
142-
throw std::runtime_error("Batch member must be object");
142+
throw std::runtime_error("Batch member must be an object");
143143
}
144144
size_t id = rec["id"].get_int();
145145
if (id >= num) {
146-
throw std::runtime_error("Batch member id larger than size");
146+
throw std::runtime_error("Batch member id is larger than batch size");
147147
}
148148
batch[id] = rec;
149149
}

src/rpc/request.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool GetAuthCookie(std::string *cookie_out);
2222
/** Delete RPC authentication cookie from disk */
2323
void DeleteAuthCookie();
2424
/** Parse JSON-RPC batch reply into a vector */
25-
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num);
25+
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in);
2626

2727
class JSONRPCRequest
2828
{

0 commit comments

Comments
 (0)