Browse Source

prevent wallet response updates while whirlpool is starting

terminal
Craig Raw 3 years ago
parent
commit
6cf40e327c
  1. 3
      src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java
  2. 18
      src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java

3
src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java

@ -319,7 +319,8 @@ public class Whirlpool {
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()) {
} else if(whirlpoolWalletService.whirlpoolWallet().getMixingState().getUtxosMixing().isEmpty() &&
!whirlpoolWalletService.whirlpoolWallet().getUtxoSupplier().findUtxos(WhirlpoolAccount.PREMIX, WhirlpoolAccount.POSTMIX).isEmpty()) {
log.warn("No UTXOs mixing, but mixingProperty is true");
//Will automatically restart
AppServices.getWhirlpoolServices().stopWhirlpool(this, false);

18
src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java

@ -33,6 +33,7 @@ import com.sparrowwallet.sparrow.event.WalletAddressesChangedEvent;
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
import com.sparrowwallet.sparrow.net.ElectrumServer;
import com.sparrowwallet.sparrow.whirlpool.Whirlpool;
import javafx.application.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -246,12 +247,12 @@ public class SparrowDataSource extends WalletResponseDataSource {
@Subscribe
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
refreshWallet(event.getWalletId());
refreshWallet(event.getWalletId(), event.getWallet());
}
@Subscribe
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
refreshWallet(event.getWalletId());
refreshWallet(event.getWalletId(), event.getWallet());
}
@Subscribe
@ -263,14 +264,19 @@ public class SparrowDataSource extends WalletResponseDataSource {
}
}
private void refreshWallet(String eventWalletId) {
private void refreshWallet(String walletId, Wallet wallet) {
try {
// match <prefix>:master, :Premix, :Postmix
if (eventWalletId.startsWith(walletIdentifierPrefix)) {
refresh();
if(walletId.startsWith(walletIdentifierPrefix) && (wallet.isWhirlpoolMasterWallet() || wallet.isWhirlpoolChildWallet())) {
Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(wallet);
if(whirlpool != null && whirlpool.isStarting()) {
Platform.runLater(() -> refreshWallet(walletId, wallet));
} else {
refresh();
}
}
} catch (Exception e) {
log.error("", e);
log.error("Error refreshing wallet", e);
}
}
}

Loading…
Cancel
Save