From b4369fbb9f7f32bffe95624b5cbe66df4ee0aa95 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 18 May 2024 11:26:16 -0400 Subject: [PATCH] fix default monero port in custom node input #928 --- .../src/main/java/haveno/core/api/XmrLocalNode.java | 13 ++----------- .../main/java/haveno/core/trade/HavenoUtils.java | 7 +++++++ .../main/java/haveno/core/xmr/nodes/XmrNodes.java | 6 +++--- .../main/resources/i18n/displayStrings.properties | 2 +- .../main/settings/network/NetworkSettingsView.java | 3 ++- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/haveno/core/api/XmrLocalNode.java b/core/src/main/java/haveno/core/api/XmrLocalNode.java index d19b27453a..80682e9a34 100644 --- a/core/src/main/java/haveno/core/api/XmrLocalNode.java +++ b/core/src/main/java/haveno/core/api/XmrLocalNode.java @@ -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(); } /** diff --git a/core/src/main/java/haveno/core/trade/HavenoUtils.java b/core/src/main/java/haveno/core/trade/HavenoUtils.java index 22e29d8ad2..ba63187618 100644 --- a/core/src/main/java/haveno/core/trade/HavenoUtils.java +++ b/core/src/main/java/haveno/core/trade/HavenoUtils.java @@ -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"); + } } diff --git a/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java b/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java index 7330a4cb73..25df963b22 100644 --- a/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java +++ b/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java @@ -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 diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index f631fd8ac8..de12827a79 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -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] diff --git a/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java b/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java index c3226ec9ba..89c0e7504f 100644 --- a/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java +++ b/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java @@ -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 { } }; - 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"));