From 5aea538f0936aad0b81e094aaf2d3ad2809bdbcb Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 16 Aug 2022 10:45:01 +0200 Subject: [PATCH] cancel whirlpool startup service when disconnecting --- .../java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java | 6 ++++-- .../sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java index 74762f09..325c7f45 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java @@ -33,7 +33,6 @@ import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.event.WhirlpoolMixEvent; import com.sparrowwallet.sparrow.event.WhirlpoolMixSuccessEvent; -import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.wallet.UtxoEntry; import com.sparrowwallet.sparrow.whirlpool.dataPersister.SparrowDataPersister; import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowDataSource; @@ -46,7 +45,6 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.concurrent.ScheduledService; import javafx.concurrent.Service; import javafx.concurrent.Task; -import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -363,6 +361,10 @@ public class Whirlpool { return startupService; } + public StartupService getStartupService() { + return startupService; + } + private WalletUtxo getUtxo(WhirlpoolUtxo whirlpoolUtxo) { Wallet wallet = AppServices.get().getWallet(walletId); if(wallet != null) { diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java index e5e1c443..ea22aad2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java @@ -195,6 +195,8 @@ public class WhirlpoolServices { @Subscribe public void disconnection(DisconnectionEvent event) { + //Cancel any scheduled attempts to try reconnect + whirlpoolMap.values().stream().filter(whirlpool -> whirlpool.getStartupService() != null).forEach(whirlpool -> whirlpool.getStartupService().cancel()); stopAllWhirlpool(); }