diff options
author | Jon Atack <jon@atack.com> | 2021-05-22 22:08:46 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2021-05-24 14:10:23 +0200 |
commit | b36e0cd1b9d361ac6f9777c09328a13e9ee923be (patch) | |
tree | 421fa73b705137f6eea102af4876f7c0f4999c80 /src/rpc | |
parent | 6b1926cf1eac1ad1850599d2753dd22bc21fd327 (diff) |
rpc: simplify addpeeraddress and improve code constness
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/net.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 4999eefc24..c4d6e3d546 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -931,26 +931,22 @@ static RPCHelpMan addpeeraddress() throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled"); } - UniValue obj(UniValue::VOBJ); - - std::string addr_string = request.params[0].get_str(); - uint16_t port{static_cast<uint16_t>(request.params[1].get_int())}; + const std::string& addr_string{request.params[0].get_str()}; + const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())}; + UniValue obj(UniValue::VOBJ); CNetAddr net_addr; - if (!LookupHost(addr_string, net_addr, false)) { - obj.pushKV("success", false); - return obj; - } - CAddress address = CAddress({net_addr, port}, ServiceFlags(NODE_NETWORK|NODE_WITNESS)); - address.nTime = GetAdjustedTime(); - // The source address is set equal to the address. This is equivalent to the peer - // announcing itself. - if (!node.addrman->Add(address, address)) { - obj.pushKV("success", false); - return obj; + bool success{false}; + + if (LookupHost(addr_string, net_addr, false)) { + CAddress address{CAddress({net_addr, port}, ServiceFlags(NODE_NETWORK | NODE_WITNESS))}; + address.nTime = GetAdjustedTime(); + // The source address is set equal to the address. This is equivalent to the peer + // announcing itself. + if (node.addrman->Add(address, address)) success = true; } - obj.pushKV("success", true); + obj.pushKV("success", success); return obj; }, }; |