Skip to content

Commit 56b27b8

Browse files
committed
rpc, refactor: clean-up addnode
1. Use const where possible; 2. Rename variables to make them clearer; 3. There is no need to check whether `command` is null since it's a non-optional field.
1 parent f08bde7 commit 56b27b8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/rpc/net.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,35 +297,33 @@ static RPCHelpMan addnode()
297297
},
298298
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
299299
{
300-
std::string strCommand;
301-
if (!request.params[1].isNull())
302-
strCommand = request.params[1].get_str();
303-
if (strCommand != "onetry" && strCommand != "add" && strCommand != "remove") {
300+
const std::string command{request.params[1].get_str()};
301+
if (command != "onetry" && command != "add" && command != "remove") {
304302
throw std::runtime_error(
305303
self.ToString());
306304
}
307305

308306
NodeContext& node = EnsureAnyNodeContext(request.context);
309307
CConnman& connman = EnsureConnman(node);
310308

311-
std::string strNode = request.params[0].get_str();
309+
const std::string node_arg{request.params[0].get_str()};
312310

313-
if (strCommand == "onetry")
311+
if (command == "onetry")
314312
{
315313
CAddress addr;
316-
connman.OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), ConnectionType::MANUAL);
314+
connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grantOutbound=*/nullptr, node_arg.c_str(), ConnectionType::MANUAL);
317315
return UniValue::VNULL;
318316
}
319317

320-
if (strCommand == "add")
318+
if (command == "add")
321319
{
322-
if (!connman.AddNode(strNode)) {
320+
if (!connman.AddNode(node_arg)) {
323321
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
324322
}
325323
}
326-
else if(strCommand == "remove")
324+
else if (command == "remove")
327325
{
328-
if (!connman.RemoveAddedNode(strNode)) {
326+
if (!connman.RemoveAddedNode(node_arg)) {
329327
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
330328
}
331329
}

0 commit comments

Comments
 (0)