Skip to content

Commit b36e0cd

Browse files
committed
rpc: simplify addpeeraddress and improve code constness
1 parent 6b1926c commit b36e0cd

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/rpc/net.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -931,26 +931,22 @@ static RPCHelpMan addpeeraddress()
931931
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
932932
}
933933

934-
UniValue obj(UniValue::VOBJ);
935-
936-
std::string addr_string = request.params[0].get_str();
937-
uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
934+
const std::string& addr_string{request.params[0].get_str()};
935+
const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
938936

937+
UniValue obj(UniValue::VOBJ);
939938
CNetAddr net_addr;
940-
if (!LookupHost(addr_string, net_addr, false)) {
941-
obj.pushKV("success", false);
942-
return obj;
943-
}
944-
CAddress address = CAddress({net_addr, port}, ServiceFlags(NODE_NETWORK|NODE_WITNESS));
945-
address.nTime = GetAdjustedTime();
946-
// The source address is set equal to the address. This is equivalent to the peer
947-
// announcing itself.
948-
if (!node.addrman->Add(address, address)) {
949-
obj.pushKV("success", false);
950-
return obj;
939+
bool success{false};
940+
941+
if (LookupHost(addr_string, net_addr, false)) {
942+
CAddress address{CAddress({net_addr, port}, ServiceFlags(NODE_NETWORK | NODE_WITNESS))};
943+
address.nTime = GetAdjustedTime();
944+
// The source address is set equal to the address. This is equivalent to the peer
945+
// announcing itself.
946+
if (node.addrman->Add(address, address)) success = true;
951947
}
952948

953-
obj.pushKV("success", true);
949+
obj.pushKV("success", success);
954950
return obj;
955951
},
956952
};

0 commit comments

Comments
 (0)