From 39fa65ea37037e50b7f6f6998bf626c9e738368d Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 23 Nov 2021 09:17:19 +0200 Subject: [PATCH] restart whirlpool if no utxos mixing, bind debug logging accelerator --- .../sparrow/whirlpool/Whirlpool.java | 21 +++++++++++++--- .../sparrow/whirlpool/WhirlpoolServices.java | 24 +++++++++++++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java index fd5f6576..0462f161 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java @@ -315,12 +315,27 @@ public class Whirlpool { return; } - if(isMixing() && !whirlpoolWalletService.whirlpoolWallet().isStarted()) { - log.warn("Wallet is not started, but mixingProperty is true"); - WhirlpoolEventService.getInstance().post(new WalletStopEvent(whirlpoolWalletService.whirlpoolWallet())); + if(isMixing()) { + if(!whirlpoolWalletService.whirlpoolWallet().isStarted()) { + log.warn("Wallet is not started, but mixingProperty is true"); + WhirlpoolEventService.getInstance().post(new WalletStopEvent(whirlpoolWalletService.whirlpoolWallet())); + } else if(whirlpoolWalletService.whirlpoolWallet().getMixingState().getUtxosMixing().isEmpty()) { + log.warn("No UTXOs mixing, but mixingProperty is true"); + //Will automatically restart + AppServices.getWhirlpoolServices().stopWhirlpool(this, false); + } } } + public void logDebug() { + if(whirlpoolWalletService.whirlpoolWallet() == null) { + log.warn("Whirlpool wallet for " + walletId + " not started"); + return; + } + + log.warn("Whirlpool debug for " + walletId + "\n" + whirlpoolWalletService.whirlpoolWallet().getDebug()); + } + public boolean hasWallet() { return hdWallet != null; } diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java index 7b96c181..55e892da 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java @@ -15,15 +15,16 @@ import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.io.Storage; import com.sparrowwallet.sparrow.net.TorService; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyCombination; +import javafx.stage.Window; import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.SocketTimeoutException; -import java.util.HashMap; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Objects; +import java.util.*; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -65,6 +66,20 @@ public class WhirlpoolServices { (Config.get().getProxyServer() == null || Config.get().getProxyServer().isEmpty() || !Config.get().isUseProxy() ? null : HostAndPort.fromString(Config.get().getProxyServer())); } + private void bindDebugAccelerator() { + List windows = whirlpoolMap.keySet().stream().map(walletId -> AppServices.get().getWindowForWallet(walletId)).filter(Objects::nonNull).distinct().collect(Collectors.toList()); + for(Window window : windows) { + KeyCombination keyCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN, KeyCombination.ALT_DOWN); + if(!window.getScene().getAccelerators().containsKey(keyCombination)) { + window.getScene().getAccelerators().put(keyCombination, () -> { + for(Whirlpool whirlpool : whirlpoolMap.values()) { + whirlpool.logDebug(); + } + }); + } + } + } + private void startAllWhirlpool() { for(Map.Entry entry : whirlpoolMap.entrySet().stream().filter(entry -> entry.getValue().hasWallet() && !entry.getValue().isStarted()).collect(Collectors.toList())) { Wallet wallet = AppServices.get().getWallet(entry.getKey()); @@ -175,6 +190,7 @@ public class WhirlpoolServices { @Subscribe public void newConnection(ConnectionEvent event) { startAllWhirlpool(); + bindDebugAccelerator(); } @Subscribe