check state before deleting trade wallet

This commit is contained in:
woodser 2022-07-16 18:22:46 -04:00
parent 477246f8f0
commit a80a7eec5f

View File

@ -1044,9 +1044,8 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
}
}
// delete multisig wallet // TODO (woodser): don't delete multisig wallet until payout tx unlocked
if (xmrWalletService.multisigWalletExists(trade.getId())) xmrWalletService.deleteMultisigWallet(trade.getId());
else log.warn("Multisig wallet to delete for trade {} does not exist", trade.getId());
// delete trade wallet when empty
deleteTradeWalletWhenEmpty(trade);
// unregister and persist
p2PService.removeDecryptedDirectMessageListener(getTradeProtocol(trade));
@ -1069,4 +1068,21 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
private void onTradesChanged() {
this.numPendingTrades.set(getObservableList().size());
}
private void deleteTradeWalletWhenEmpty(Trade trade) {
// delete trade wallet before funds deposited or after payout unlocked
// TODO: delete wallet if trade state < deposit_requested || state >= payout_unlocked (add trade states)
if (trade.getPhase().ordinal() < Trade.Phase.DEPOSIT_PUBLISHED.ordinal() || trade.getPhase().ordinal() >= Trade.Phase.PAYOUT_PUBLISHED.ordinal()) {
deleteTradeWallet(trade);
} else {
// TODO: schedule wallet for deletion after unlock
log.warn("Not deleting trade " + trade.getId() + " wallet because it might not be empty");
}
}
private void deleteTradeWallet(Trade trade) {
if (xmrWalletService.multisigWalletExists(trade.getId())) xmrWalletService.deleteMultisigWallet(trade.getId());
else log.warn("Multisig wallet to delete for trade {} does not exist", trade.getId());
}
}