skip wallet checks on deletion if deposit not requested

This commit is contained in:
woodser 2024-07-19 14:38:05 -04:00
parent 5d739f912c
commit eb8025f6e8

View file

@ -967,29 +967,31 @@ public abstract class Trade implements Tradable, Model {
if (walletExists()) { if (walletExists()) {
try { try {
// ensure wallet is initialized // check wallet state if deposit requested
boolean syncedWallet = false; if (isDepositRequested()) {
if (wallet == null) {
log.warn("Wallet is not initialized for {} {}, opening", getClass().getSimpleName(), getId());
getWallet();
syncWallet(true);
syncedWallet = true;
}
// sync wallet if deposit requested and payout not unlocked // ensure wallet is initialized
if (isDepositRequested() && !isPayoutUnlocked() && !syncedWallet) { boolean syncedWallet = false;
log.warn("Syncing wallet on deletion for trade {} {}, syncing", getClass().getSimpleName(), getId()); if (wallet == null) {
syncWallet(true); log.warn("Wallet is not initialized for {} {}, opening", getClass().getSimpleName(), getId());
} getWallet();
syncWallet(true);
// check if deposits published and payout not unlocked syncedWallet = true;
if (isDepositsPublished() && !isPayoutUnlocked()) { }
throw new IllegalStateException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because the deposit txs have been published but payout tx has not unlocked");
} // sync wallet if deposit requested and payout not unlocked
if (!isPayoutUnlocked() && !syncedWallet) {
// check for balance log.warn("Syncing wallet on deletion for trade {} {}, syncing", getClass().getSimpleName(), getId());
if (wallet.getBalance().compareTo(BigInteger.ZERO) > 0) { syncWallet(true);
synchronized (HavenoUtils.getDaemonLock()) { }
// check if deposits published and payout not unlocked
if (isDepositsPublished() && !isPayoutUnlocked()) {
throw new IllegalStateException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because the deposit txs have been published but payout tx has not unlocked");
}
// check for balance
if (wallet.getBalance().compareTo(BigInteger.ZERO) > 0) {
log.warn("Rescanning spent outputs for {} {}", getClass().getSimpleName(), getId()); log.warn("Rescanning spent outputs for {} {}", getClass().getSimpleName(), getId());
wallet.rescanSpent(); wallet.rescanSpent();
if (wallet.getBalance().compareTo(BigInteger.ZERO) > 0) { if (wallet.getBalance().compareTo(BigInteger.ZERO) > 0) {
@ -1656,8 +1658,9 @@ public abstract class Trade implements Tradable, Model {
private void removeTradeOnError() { private void removeTradeOnError() {
log.warn("removeTradeOnError() trade={}, tradeId={}, state={}", getClass().getSimpleName(), getShortId(), getState()); log.warn("removeTradeOnError() trade={}, tradeId={}, state={}", getClass().getSimpleName(), getShortId(), getState());
// force close wallet in case stuck // force close and re-open wallet in case stuck
forceCloseWallet(); forceCloseWallet();
if (isDepositRequested()) getWallet();
// shut down trade thread // shut down trade thread
try { try {