Skip to content

Commit 14f3d9b

Browse files
committed
refactor: Add RPC server ExecuteCommands function
No change in behavior. New function is split from CRPCTable::execute and used in the next commit.
1 parent 6158a6d commit 14f3d9b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/rpc/server.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
437437
return out;
438438
}
439439

440+
static bool ExecuteCommands(const std::vector<const CRPCCommand*>& commands, const JSONRPCRequest& request, UniValue& result)
441+
{
442+
for (const auto& command : commands) {
443+
if (ExecuteCommand(*command, request, result, &command == &commands.back())) {
444+
return true;
445+
}
446+
}
447+
return false;
448+
}
449+
440450
UniValue CRPCTable::execute(const JSONRPCRequest &request) const
441451
{
442452
// Return immediately if in warmup
@@ -450,10 +460,8 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
450460
auto it = mapCommands.find(request.strMethod);
451461
if (it != mapCommands.end()) {
452462
UniValue result;
453-
for (const auto& command : it->second) {
454-
if (ExecuteCommand(*command, request, result, &command == &it->second.back())) {
455-
return result;
456-
}
463+
if (ExecuteCommands(it->second, request, result)) {
464+
return result;
457465
}
458466
}
459467
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");

0 commit comments

Comments
 (0)