aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrunoerg <brunoely.gc@gmail.com>2022-10-21 15:03:40 -0300
committerbrunoerg <brunoely.gc@gmail.com>2023-08-02 10:28:28 -0300
commit56b27b84877376ffc32b3bad09f1047b23de4ba1 (patch)
tree5db82bd8e0395195e159b2cc5a8065aa02c181c4
parentf08bde7f715cf84ef050c3f6902bc75fb90cedb3 (diff)
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.
-rw-r--r--src/rpc/net.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index a2a46ef32f..da511d1ed9 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -297,10 +297,8 @@ static RPCHelpMan addnode()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
- std::string strCommand;
- if (!request.params[1].isNull())
- strCommand = request.params[1].get_str();
- if (strCommand != "onetry" && strCommand != "add" && strCommand != "remove") {
+ const std::string command{request.params[1].get_str()};
+ if (command != "onetry" && command != "add" && command != "remove") {
throw std::runtime_error(
self.ToString());
}
@@ -308,24 +306,24 @@ static RPCHelpMan addnode()
NodeContext& node = EnsureAnyNodeContext(request.context);
CConnman& connman = EnsureConnman(node);
- std::string strNode = request.params[0].get_str();
+ const std::string node_arg{request.params[0].get_str()};
- if (strCommand == "onetry")
+ if (command == "onetry")
{
CAddress addr;
- connman.OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), ConnectionType::MANUAL);
+ connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grantOutbound=*/nullptr, node_arg.c_str(), ConnectionType::MANUAL);
return UniValue::VNULL;
}
- if (strCommand == "add")
+ if (command == "add")
{
- if (!connman.AddNode(strNode)) {
+ if (!connman.AddNode(node_arg)) {
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
}
}
- else if(strCommand == "remove")
+ else if (command == "remove")
{
- if (!connman.RemoveAddedNode(strNode)) {
+ if (!connman.RemoveAddedNode(node_arg)) {
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
}
}