prevent wallet response updates while whirlpool is starting

This commit is contained in:
Craig Raw 2022-03-02 16:15:27 +02:00
parent 5959b00611
commit 6cf40e327c
2 changed files with 14 additions and 7 deletions

View file

@ -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);

View file

@ -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)) {
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);
}
}
}