@@ -1355,12 +1355,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13551355 // -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
13561356 std::string proxyArg = args.GetArg (" -proxy" , " " );
13571357 if (proxyArg != " " && proxyArg != " 0" ) {
1358- CService proxyAddr;
1359- if (!Lookup (proxyArg, proxyAddr, 9050 , fNameLookup )) {
1358+ const std::optional< CService> proxyAddr{ Lookup (proxyArg, 9050 , fNameLookup )} ;
1359+ if (!proxyAddr. has_value ( )) {
13601360 return InitError (strprintf (_ (" Invalid -proxy address or hostname: '%s'" ), proxyArg));
13611361 }
13621362
1363- Proxy addrProxy = Proxy (proxyAddr, proxyRandomize);
1363+ Proxy addrProxy = Proxy (proxyAddr. value () , proxyRandomize);
13641364 if (!addrProxy.IsValid ())
13651365 return InitError (strprintf (_ (" Invalid -proxy address or hostname: '%s'" ), proxyArg));
13661366
@@ -1386,11 +1386,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13861386 " reaching the Tor network is explicitly forbidden: -onion=0" ));
13871387 }
13881388 } else {
1389- CService addr;
1390- if (!Lookup (onionArg, addr, 9050 , fNameLookup ) || !addr. IsValid ()) {
1389+ const std::optional< CService> addr{ Lookup (onionArg, 9050 , fNameLookup )} ;
1390+ if (!addr. has_value ( ) || !addr-> IsValid ()) {
13911391 return InitError (strprintf (_ (" Invalid -onion address or hostname: '%s'" ), onionArg));
13921392 }
1393- onion_proxy = Proxy{addr, proxyRandomize};
1393+ onion_proxy = Proxy{addr. value () , proxyRandomize};
13941394 }
13951395 }
13961396
@@ -1410,9 +1410,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14101410 }
14111411
14121412 for (const std::string& strAddr : args.GetArgs (" -externalip" )) {
1413- CService addrLocal;
1414- if (Lookup (strAddr, addrLocal, GetListenPort (), fNameLookup ) && addrLocal. IsValid ())
1415- AddLocal (addrLocal, LOCAL_MANUAL);
1413+ const std::optional< CService> addrLocal{ Lookup (strAddr, GetListenPort (), fNameLookup )} ;
1414+ if (addrLocal. has_value () && addrLocal-> IsValid ())
1415+ AddLocal (addrLocal. value () , LOCAL_MANUAL);
14161416 else
14171417 return InitError (ResolveErrMsg (" externalip" , strAddr));
14181418 }
@@ -1748,22 +1748,24 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17481748 };
17491749
17501750 for (const std::string& bind_arg : args.GetArgs (" -bind" )) {
1751- CService bind_addr;
1751+ std::optional< CService> bind_addr;
17521752 const size_t index = bind_arg.rfind (' =' );
17531753 if (index == std::string::npos) {
1754- if (Lookup (bind_arg, bind_addr, default_bind_port, /* fAllowLookup=*/ false )) {
1755- connOptions.vBinds .push_back (bind_addr);
1756- if (IsBadPort (bind_addr.GetPort ())) {
1757- InitWarning (BadPortWarning (" -bind" , bind_addr.GetPort ()));
1754+ bind_addr = Lookup (bind_arg, default_bind_port, /* fAllowLookup=*/ false );
1755+ if (bind_addr.has_value ()) {
1756+ connOptions.vBinds .push_back (bind_addr.value ());
1757+ if (IsBadPort (bind_addr.value ().GetPort ())) {
1758+ InitWarning (BadPortWarning (" -bind" , bind_addr.value ().GetPort ()));
17581759 }
17591760 continue ;
17601761 }
17611762 } else {
17621763 const std::string network_type = bind_arg.substr (index + 1 );
17631764 if (network_type == " onion" ) {
17641765 const std::string truncated_bind_arg = bind_arg.substr (0 , index);
1765- if (Lookup (truncated_bind_arg, bind_addr, BaseParams ().OnionServiceTargetPort (), false )) {
1766- connOptions.onion_binds .push_back (bind_addr);
1766+ bind_addr = Lookup (truncated_bind_arg, BaseParams ().OnionServiceTargetPort (), false );
1767+ if (bind_addr.has_value ()) {
1768+ connOptions.onion_binds .push_back (bind_addr.value ());
17671769 continue ;
17681770 }
17691771 }
@@ -1841,11 +1843,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18411843
18421844 const std::string& i2psam_arg = args.GetArg (" -i2psam" , " " );
18431845 if (!i2psam_arg.empty ()) {
1844- CService addr;
1845- if (!Lookup (i2psam_arg, addr, 7656 , fNameLookup ) || !addr. IsValid ()) {
1846+ const std::optional< CService> addr{ Lookup (i2psam_arg, 7656 , fNameLookup )} ;
1847+ if (!addr. has_value ( ) || !addr-> IsValid ()) {
18461848 return InitError (strprintf (_ (" Invalid -i2psam address or hostname: '%s'" ), i2psam_arg));
18471849 }
1848- SetProxy (NET_I2P, Proxy{addr});
1850+ SetProxy (NET_I2P, Proxy{addr. value () });
18491851 } else {
18501852 if (args.IsArgSet (" -onlynet" ) && IsReachable (NET_I2P)) {
18511853 return InitError (
0 commit comments