Call validatePayoutTx only after trades are initialized

This commit is contained in:
chimp1984 2020-09-11 20:25:48 -05:00
parent 677211badf
commit 08fb596629
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
4 changed files with 88 additions and 27 deletions

View File

@ -725,9 +725,19 @@ public abstract class Trade implements Tradable, Model {
@Nullable
public Transaction getDelayedPayoutTx() {
if (delayedPayoutTx == null) {
delayedPayoutTx = delayedPayoutTxBytes != null && processModel.getBtcWalletService() != null ?
processModel.getBtcWalletService().getTxFromSerializedTx(delayedPayoutTxBytes) :
null;
BtcWalletService btcWalletService = processModel.getBtcWalletService();
if (btcWalletService == null) {
log.warn("btcWalletService is null. You might call that method before the tradeManager has " +
"initialized all trades");
return null;
}
if (delayedPayoutTxBytes == null) {
log.warn("delayedPayoutTxBytes are null");
return null;
}
delayedPayoutTx = btcWalletService.getTxFromSerializedTx(delayedPayoutTxBytes);
}
return delayedPayoutTx;
}

View File

@ -135,6 +135,7 @@ public class TradeManager implements PersistedDataHost {
private final Storage<TradableList<Trade>> tradableListStorage;
private TradableList<Trade> tradableList;
@Getter
private final BooleanProperty pendingTradesInitialized = new SimpleBooleanProperty();
private List<Trade> tradesForStatistics;
@Setter

View File

@ -24,7 +24,13 @@ import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView;
import bisq.core.locale.Res;
import bisq.core.trade.DelayedPayoutTxValidation;
import bisq.common.UserThread;
import javafx.beans.property.BooleanProperty;
import javafx.beans.value.ChangeListener;
public class BuyerStep1View extends TradeStepView {
private ChangeListener<Boolean> pendingTradesInitializedListener;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, Initialisation
@ -38,18 +44,18 @@ public class BuyerStep1View extends TradeStepView {
public void activate() {
super.activate();
try {
DelayedPayoutTxValidation.validatePayoutTx(trade,
trade.getDelayedPayoutTx(),
model.dataModel.daoFacade,
model.dataModel.btcWalletService);
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
// trade manager after initPendingTrades which happens after activate might be called.
} catch (DelayedPayoutTxValidation.ValidationException e) {
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
}
// We need to have the trades initialized before we can call validatePayoutTx.
BooleanProperty pendingTradesInitialized = model.dataModel.tradeManager.getPendingTradesInitialized();
if (pendingTradesInitialized.get()) {
validatePayoutTx();
} else {
pendingTradesInitializedListener = (observable, oldValue, newValue) -> {
if (newValue) {
validatePayoutTx();
UserThread.execute(() -> pendingTradesInitialized.removeListener(pendingTradesInitializedListener));
}
};
pendingTradesInitialized.addListener(pendingTradesInitializedListener);
}
}
@ -85,6 +91,29 @@ public class BuyerStep1View extends TradeStepView {
protected String getPeriodOverWarnText() {
return Res.get("portfolio.pending.step1.openForDispute");
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private void validatePayoutTx() {
try {
DelayedPayoutTxValidation.validatePayoutTx(trade,
trade.getDelayedPayoutTx(),
model.dataModel.daoFacade,
model.dataModel.btcWalletService);
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
// trade manager after initPendingTrades which happens after activate might be called.
log.error("");
} catch (DelayedPayoutTxValidation.ValidationException e) {
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
}
}
}
}

View File

@ -88,6 +88,9 @@ import javafx.scene.layout.Priority;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
import javafx.beans.property.BooleanProperty;
import javafx.beans.value.ChangeListener;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -104,6 +107,7 @@ public class BuyerStep2View extends TradeStepView {
private BusyAnimation busyAnimation;
private Subscription tradeStatePropertySubscription;
private Timer timeoutTimer;
private ChangeListener<Boolean> pendingTradesInitializedListener;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, Initialisation
@ -117,18 +121,18 @@ public class BuyerStep2View extends TradeStepView {
public void activate() {
super.activate();
try {
DelayedPayoutTxValidation.validatePayoutTx(trade,
trade.getDelayedPayoutTx(),
model.dataModel.daoFacade,
model.dataModel.btcWalletService);
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
// trade manager after initPendingTrades which happens after activate might be called.
} catch (DelayedPayoutTxValidation.ValidationException e) {
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
}
// We need to have the trades initialized before we can call validatePayoutTx.
BooleanProperty pendingTradesInitialized = model.dataModel.tradeManager.getPendingTradesInitialized();
if (pendingTradesInitialized.get()) {
validatePayoutTx();
} else {
pendingTradesInitializedListener = (observable, oldValue, newValue) -> {
if (newValue) {
validatePayoutTx();
UserThread.execute(() -> pendingTradesInitialized.removeListener(pendingTradesInitializedListener));
}
};
pendingTradesInitialized.addListener(pendingTradesInitializedListener);
}
if (timeoutTimer != null)
@ -629,6 +633,23 @@ public class BuyerStep2View extends TradeStepView {
}
}
private void validatePayoutTx() {
try {
DelayedPayoutTxValidation.validatePayoutTx(trade,
trade.getDelayedPayoutTx(),
model.dataModel.daoFacade,
model.dataModel.btcWalletService);
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
// trade manager after initPendingTrades which happens after activate might be called.
log.error("");
} catch (DelayedPayoutTxValidation.ValidationException e) {
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
}
}
}
@Override
protected void updateConfirmButtonDisableState(boolean isDisabled) {
confirmButton.setDisable(isDisabled);