diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2021-01-29 18:12:19 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2021-01-29 18:12:19 -0500 |
commit | 14f3d9b908ed9e78997bfaad3d8a06357a89d46e (patch) | |
tree | 393ac84c51be5dff233dd04901ecda279537e11c /src/rpc/server.cpp | |
parent | 6158a6d3978a18d5ac4166ca2f59056d8ef71c3d (diff) |
refactor: Add RPC server ExecuteCommands function
No change in behavior. New function is split from CRPCTable::execute and
used in the next commit.
Diffstat (limited to 'src/rpc/server.cpp')
-rw-r--r-- | src/rpc/server.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1b8bbafcef..66134a77b2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -437,6 +437,16 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c return out; } +static bool ExecuteCommands(const std::vector<const CRPCCommand*>& commands, const JSONRPCRequest& request, UniValue& result) +{ + for (const auto& command : commands) { + if (ExecuteCommand(*command, request, result, &command == &commands.back())) { + return true; + } + } + return false; +} + UniValue CRPCTable::execute(const JSONRPCRequest &request) const { // Return immediately if in warmup @@ -450,10 +460,8 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const auto it = mapCommands.find(request.strMethod); if (it != mapCommands.end()) { UniValue result; - for (const auto& command : it->second) { - if (ExecuteCommand(*command, request, result, &command == &it->second.back())) { - return result; - } + if (ExecuteCommands(it->second, request, result)) { + return result; } } throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); |