restart whirlpool if no utxos mixing, bind debug logging accelerator

This commit is contained in:
Craig Raw 2021-11-23 09:17:19 +02:00
parent 4554c9d0df
commit 39fa65ea37
2 changed files with 38 additions and 7 deletions

View file

@ -315,11 +315,26 @@ public class Whirlpool {
return;
}
if(isMixing() && !whirlpoolWalletService.whirlpoolWallet().isStarted()) {
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;

View file

@ -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<Window> 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<String, Whirlpool> 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