do not ignore local node if configured
This commit is contained in:
parent
48501a6572
commit
31b0edca22
2 changed files with 25 additions and 4 deletions
|
@ -25,6 +25,8 @@ import haveno.core.trade.HavenoUtils;
|
||||||
import haveno.core.user.Preferences;
|
import haveno.core.user.Preferences;
|
||||||
import haveno.core.xmr.XmrNodeSettings;
|
import haveno.core.xmr.XmrNodeSettings;
|
||||||
import haveno.core.xmr.nodes.XmrNodes;
|
import haveno.core.xmr.nodes.XmrNodes;
|
||||||
|
import haveno.core.xmr.nodes.XmrNodes.XmrNode;
|
||||||
|
import haveno.core.xmr.nodes.XmrNodesSetupPreferences;
|
||||||
import haveno.core.xmr.wallet.XmrWalletService;
|
import haveno.core.xmr.wallet.XmrWalletService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -55,6 +57,7 @@ public class XmrLocalNode {
|
||||||
private MoneroConnectionManager connectionManager;
|
private MoneroConnectionManager connectionManager;
|
||||||
private final Config config;
|
private final Config config;
|
||||||
private final Preferences preferences;
|
private final Preferences preferences;
|
||||||
|
private final XmrNodes xmrNodes;
|
||||||
private final List<XmrLocalNodeListener> listeners = new ArrayList<>();
|
private final List<XmrLocalNodeListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
// required arguments
|
// required arguments
|
||||||
|
@ -69,9 +72,12 @@ public class XmrLocalNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public XmrLocalNode(Config config, Preferences preferences) {
|
public XmrLocalNode(Config config,
|
||||||
|
Preferences preferences,
|
||||||
|
XmrNodes xmrNodes) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
|
this.xmrNodes = xmrNodes;
|
||||||
this.daemon = new MoneroDaemonRpc(getUri());
|
this.daemon = new MoneroDaemonRpc(getUri());
|
||||||
|
|
||||||
// initialize connection manager to listen to local connection
|
// initialize connection manager to listen to local connection
|
||||||
|
@ -101,7 +107,20 @@ public class XmrLocalNode {
|
||||||
* Returns whether Haveno should ignore a local Monero node even if it is usable.
|
* Returns whether Haveno should ignore a local Monero node even if it is usable.
|
||||||
*/
|
*/
|
||||||
public boolean shouldBeIgnored() {
|
public boolean shouldBeIgnored() {
|
||||||
return config.ignoreLocalXmrNode || preferences.getMoneroNodesOption() == XmrNodes.MoneroNodesOption.CUSTOM;
|
if (config.ignoreLocalXmrNode) return true;
|
||||||
|
|
||||||
|
// determine if local node is configured
|
||||||
|
boolean hasConfiguredLocalNode = false;
|
||||||
|
for (XmrNode node : xmrNodes.selectPreferredNodes(new XmrNodesSetupPreferences(preferences))) {
|
||||||
|
String prefix = node.getAddress().startsWith("http") ? "" : "http://";
|
||||||
|
if (equalsUri(prefix + node.getAddress() + ":" + node.getPort())) {
|
||||||
|
hasConfiguredLocalNode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasConfiguredLocalNode) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(XmrLocalNodeListener listener) {
|
public void addListener(XmrLocalNodeListener listener) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import haveno.core.locale.CountryUtil;
|
||||||
import haveno.core.locale.CryptoCurrency;
|
import haveno.core.locale.CryptoCurrency;
|
||||||
import haveno.core.locale.CurrencyUtil;
|
import haveno.core.locale.CurrencyUtil;
|
||||||
import haveno.core.locale.TraditionalCurrency;
|
import haveno.core.locale.TraditionalCurrency;
|
||||||
|
import haveno.core.xmr.nodes.XmrNodes;
|
||||||
import haveno.core.locale.GlobalSettings;
|
import haveno.core.locale.GlobalSettings;
|
||||||
import haveno.core.locale.Res;
|
import haveno.core.locale.Res;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
@ -45,6 +46,7 @@ public class PreferencesTest {
|
||||||
|
|
||||||
private Preferences preferences;
|
private Preferences preferences;
|
||||||
private PersistenceManager persistenceManager;
|
private PersistenceManager persistenceManager;
|
||||||
|
private XmrNodes xmrNodes;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
@ -53,12 +55,12 @@ public class PreferencesTest {
|
||||||
GlobalSettings.setLocale(en_US);
|
GlobalSettings.setLocale(en_US);
|
||||||
Res.setBaseCurrencyCode("XMR");
|
Res.setBaseCurrencyCode("XMR");
|
||||||
Res.setBaseCurrencyName("Monero");
|
Res.setBaseCurrencyName("Monero");
|
||||||
|
|
||||||
persistenceManager = mock(PersistenceManager.class);
|
persistenceManager = mock(PersistenceManager.class);
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
XmrLocalNode xmrLocalNode = new XmrLocalNode(config, preferences);
|
|
||||||
preferences = new Preferences(
|
preferences = new Preferences(
|
||||||
persistenceManager, config, null, null);
|
persistenceManager, config, null, null);
|
||||||
|
xmrNodes = new XmrNodes();
|
||||||
|
XmrLocalNode xmrLocalNode = new XmrLocalNode(config, preferences, xmrNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue