Skip to content

Commit 1b91898

Browse files
committed
rpc: simplify/constify getnodeaddresses code
1 parent 3bb6e7b commit 1b91898

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/rpc/net.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -863,15 +863,11 @@ static RPCHelpMan getnodeaddresses()
863863
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
864864
}
865865

866-
int count = 1;
867-
if (!request.params[0].isNull()) {
868-
count = request.params[0].get_int();
869-
if (count < 0) {
870-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
871-
}
872-
}
866+
const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()};
867+
if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
868+
873869
// returns a shuffled list of CAddress
874-
std::vector<CAddress> vAddr = node.connman->GetAddresses(count, /* max_pct */ 0);
870+
const std::vector<CAddress> vAddr{node.connman->GetAddresses(count, /* max_pct */ 0)};
875871
UniValue ret(UniValue::VARR);
876872

877873
for (const CAddress& addr : vAddr) {

0 commit comments

Comments
 (0)