fix default monero port in custom node input #928

This commit is contained in:
woodser 2024-05-18 11:26:16 -04:00
parent bee93bf45f
commit b4369fbb9f
5 changed files with 15 additions and 16 deletions

View File

@ -68,15 +68,6 @@ public class XmrLocalNode {
if (!Config.baseCurrencyNetwork().isMainnet()) MONEROD_ARGS.add("--" + Config.baseCurrencyNetwork().getNetwork().toLowerCase());
}
// default rpc ports
private static Integer rpcPort;
static {
if (Config.baseCurrencyNetwork().isMainnet()) rpcPort = 18081;
else if (Config.baseCurrencyNetwork().isTestnet()) rpcPort = 28081;
else if (Config.baseCurrencyNetwork().isStagenet()) rpcPort = 38081;
else throw new RuntimeException("Base network is not local testnet, stagenet, or mainnet");
}
@Inject
public XmrLocalNode(Config config, Preferences preferences) {
this.config = config;
@ -93,7 +84,7 @@ public class XmrLocalNode {
}
public String getUri() {
return "http://" + HavenoUtils.LOOPBACK_HOST + ":" + rpcPort;
return "http://" + HavenoUtils.LOOPBACK_HOST + ":" + HavenoUtils.getDefaultMoneroPort();
}
/**
@ -129,7 +120,7 @@ public class XmrLocalNode {
}
public boolean equalsUri(String uri) {
return HavenoUtils.isLocalHost(uri) && MoneroUtils.parseUri(uri).getPort() == rpcPort;
return HavenoUtils.isLocalHost(uri) && MoneroUtils.parseUri(uri).getPort() == HavenoUtils.getDefaultMoneroPort();
}
/**

View File

@ -515,4 +515,11 @@ public class HavenoUtils {
for (MoneroOutput input : tx.getInputs()) inputKeyImages.add(input.getKeyImage().getHex());
return inputKeyImages;
}
public static int getDefaultMoneroPort() {
if (Config.baseCurrencyNetwork().isMainnet()) return 18081;
else if (Config.baseCurrencyNetwork().isTestnet()) return 28081;
else if (Config.baseCurrencyNetwork().isStagenet()) return 38081;
else throw new RuntimeException("Base network is not local testnet, stagenet, or mainnet");
}
}

View File

@ -35,6 +35,7 @@
package haveno.core.xmr.nodes;
import haveno.common.config.Config;
import haveno.core.trade.HavenoUtils;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@ -127,7 +128,6 @@ public class XmrNodes {
@EqualsAndHashCode
@Getter
public static class XmrNode {
private static final int DEFAULT_PORT = Config.baseCurrencyNetworkParameters().getPort();
private final MoneroNodesOption type;
@Nullable
@ -138,7 +138,7 @@ public class XmrNodes {
private final String operator; // null in case the user provides a list of custom btc nodes
@Nullable
private final String address; // IPv4 address
private int port = DEFAULT_PORT;
private int port = HavenoUtils.getDefaultMoneroPort();
private int priority = 0;
/**
@ -149,7 +149,7 @@ public class XmrNodes {
String[] parts = fullAddress.split("]");
checkArgument(parts.length > 0);
String host = "";
int port = DEFAULT_PORT;
int port = HavenoUtils.getDefaultMoneroPort();
if (parts[0].contains("[") && parts[0].contains(":")) {
// IPv6 address and optional port number
// address part delimited by square brackets e.g. [2a01:123:456:789::2]:8333

View File

@ -1345,7 +1345,7 @@ settings.net.notKnownYet=Not known yet...
settings.net.sentData=Sent data: {0}, {1} messages, {2} messages/sec
settings.net.receivedData=Received data: {0}, {1} messages, {2} messages/sec
settings.net.chainHeight=Monero Peers chain height: {0}
settings.net.ips=[IP address:port | host name:port | onion address:port] (comma separated). Port can be omitted if default is used (8333).
settings.net.ips=[IP address:port | host name:port | onion address:port] (comma separated). Port can be omitted if default is used ({0}).
settings.net.seedNode=Seed node
settings.net.directPeer=Peer (direct)
settings.net.initialDataExchange={0} [Bootstrapping]

View File

@ -25,6 +25,7 @@ import haveno.core.api.XmrLocalNode;
import haveno.core.filter.Filter;
import haveno.core.filter.FilterManager;
import haveno.core.locale.Res;
import haveno.core.trade.HavenoUtils;
import haveno.core.user.Preferences;
import haveno.core.util.FormattingUtils;
import haveno.core.util.validation.RegexValidator;
@ -266,7 +267,7 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
}
};
xmrNodesInputTextField.setPromptText(Res.get("settings.net.ips"));
xmrNodesInputTextField.setPromptText(Res.get("settings.net.ips", "" + HavenoUtils.getDefaultMoneroPort()));
RegexValidator regexValidator = RegexValidatorFactory.addressRegexValidator();
xmrNodesInputTextField.setValidator(regexValidator);
xmrNodesInputTextField.setErrorMessage(Res.get("validation.invalidAddressList"));