aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/net.cpp
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-04-03 20:22:55 +0200
committerJon Atack <jon@atack.com>2021-04-07 12:57:09 +0200
commit1b9189866af26ed0003c1afe8dd5652ebe9b2e4a (patch)
tree2d6ca110d8ff3123ac9f5e1cae909a20b7744dea /src/rpc/net.cpp
parent3bb6e7b6555f3c8743a697cb9d509620714dc483 (diff)
downloadbitcoin-1b9189866af26ed0003c1afe8dd5652ebe9b2e4a.tar.xz
rpc: simplify/constify getnodeaddresses code
Diffstat (limited to 'src/rpc/net.cpp')
-rw-r--r--src/rpc/net.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index aff9bf7ae1..96c195a20e 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -863,15 +863,11 @@ static RPCHelpMan getnodeaddresses()
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
}
- int count = 1;
- if (!request.params[0].isNull()) {
- count = request.params[0].get_int();
- if (count < 0) {
- throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
- }
- }
+ const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()};
+ if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
+
// returns a shuffled list of CAddress
- std::vector<CAddress> vAddr = node.connman->GetAddresses(count, /* max_pct */ 0);
+ const std::vector<CAddress> vAddr{node.connman->GetAddresses(count, /* max_pct */ 0)};
UniValue ret(UniValue::VARR);
for (const CAddress& addr : vAddr) {