From 5d523668610c18f3b7b234911fbf4066a9d3c472 Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 1 Aug 2023 08:01:37 -0400 Subject: [PATCH] --xmrNode starts local node if used last and offline --- .../api/CoreMoneroConnectionsService.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/haveno/core/api/CoreMoneroConnectionsService.java b/core/src/main/java/haveno/core/api/CoreMoneroConnectionsService.java index e11c280f..c70491cc 100644 --- a/core/src/main/java/haveno/core/api/CoreMoneroConnectionsService.java +++ b/core/src/main/java/haveno/core/api/CoreMoneroConnectionsService.java @@ -439,16 +439,8 @@ public final class CoreMoneroConnectionsService { if (coreContext.isApiUser()) connectionManager.setAutoSwitch(connectionList.getAutoSwitch()); else connectionManager.setAutoSwitch(true); - // start local node if used as last connection and currently offline - if (connectionManager.getConnection() != null && nodeService.equalsUri(connectionManager.getConnection().getUri()) && !nodeService.isOnline()) { - try { - log.info("Starting local node"); - nodeService.startMoneroNode(); - } catch (Exception e) { - log.warn("Unable to start local monero node: " + e.getMessage()); - e.printStackTrace(); - } - } + // start local node if used last and offline + startLocalNodeIfUsedLast(); // update connection if (connectionManager.getConnection() == null || connectionManager.getAutoSwitch()) { @@ -463,6 +455,12 @@ public final class CoreMoneroConnectionsService { MoneroRpcConnection connection = new MoneroRpcConnection(config.xmrNode, config.xmrNodeUsername, config.xmrNodePassword).setPriority(1); if (useProxy(connection)) connection.setProxyUri(getProxyUri()); connectionManager.setConnection(connection); + + // start local node if used last and offline + startLocalNodeIfUsedLast(); + + // update connection + checkConnection(); } // register connection listener @@ -474,6 +472,20 @@ public final class CoreMoneroConnectionsService { } } + private void startLocalNodeIfUsedLast() { + + // start local node if offline and used as last connection + if (connectionManager.getConnection() != null && nodeService.equalsUri(connectionManager.getConnection().getUri()) && !nodeService.isOnline()) { + try { + log.info("Starting local node"); + nodeService.startMoneroNode(); + } catch (Exception e) { + log.warn("Unable to start local monero node: " + e.getMessage()); + e.printStackTrace(); + } + } + } + private void onConnectionChanged(MoneroRpcConnection currentConnection) { log.info("CoreMoneroConnectionsService.onConnectionChanged() uri={}, connected={}", currentConnection == null ? null : currentConnection.getUri(), currentConnection == null ? "false" : currentConnection.isConnected()); if (isShutDownStarted) return; @@ -544,7 +556,7 @@ public final class CoreMoneroConnectionsService { if (lastErrorTimestamp != null) { log.info("Successfully fetched daemon info after previous error"); lastErrorTimestamp = null; - HavenoUtils.havenoSetup.getWalletServiceErrorMsg().set(null); + if (HavenoUtils.havenoSetup != null) HavenoUtils.havenoSetup.getWalletServiceErrorMsg().set(null); } // update and notify connected state