diff options
author | brunoerg <brunoely.gc@gmail.com> | 2022-10-11 13:37:45 -0300 |
---|---|---|
committer | brunoerg <brunoely.gc@gmail.com> | 2023-05-26 13:41:07 -0300 |
commit | 5c832c3820253affc65c0ed490e26e5b0a4d5c9b (patch) | |
tree | 3b57a22231de464f33b256cf21c9c300482ca499 /src/rpc | |
parent | 34bcdfc6a65de906c65edccdd96fe15219081cd2 (diff) |
p2p, refactor: return `std::optional<CNetAddr>` in `LookupHost`
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/net.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index f247e6ee91..a2a46ef32f 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -713,9 +713,10 @@ static RPCHelpMan setban() isSubnet = true; if (!isSubnet) { - CNetAddr resolved; - LookupHost(request.params[0].get_str(), resolved, false); - netAddr = resolved; + const std::optional<CNetAddr> addr{LookupHost(request.params[0].get_str(), false)}; + if (addr.has_value()) { + netAddr = addr.value(); + } } else LookupSubNet(request.params[0].get_str(), subNet); @@ -943,11 +944,11 @@ static RPCHelpMan addpeeraddress() const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()}; UniValue obj(UniValue::VOBJ); - CNetAddr net_addr; + std::optional<CNetAddr> net_addr{LookupHost(addr_string, false)}; bool success{false}; - if (LookupHost(addr_string, net_addr, false)) { - CService service{net_addr, port}; + if (net_addr.has_value()) { + CService service{net_addr.value(), port}; CAddress address{MaybeFlipIPv6toCJDNS(service), ServiceFlags{NODE_NETWORK | NODE_WITNESS}}; address.nTime = Now<NodeSeconds>(); // The source address is set equal to the address. This is equivalent to the peer |