From a80a7eec5f84ca89240e3022ca5c35a1064ba878 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 16 Jul 2022 18:22:46 -0400 Subject: [PATCH] check state before deleting trade wallet --- .../java/bisq/core/trade/TradeManager.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index ecc86e3161..d668a30dde 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -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()); + } }