diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 73484647..7b1741fe 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -876,7 +876,19 @@ public abstract class Trade implements Tradable, Model { public void saveWallet() { synchronized (walletLock) { if (wallet == null) throw new RuntimeException("Trade wallet is not open for trade " + getId()); - xmrWalletService.saveWallet(wallet, !isArbitrator()); // skip backup if arbitrator + xmrWalletService.saveWallet(wallet); + maybeBackupWallet(); + } + } + + private void maybeBackupWallet() { + boolean createBackup = !isArbitrator() && !(Utilities.isWindows() && isWalletOpen()); // create backup unless arbitrator or windows and wallet is open (cannot copy file while open on windows) + if (createBackup) xmrWalletService.backupWallet(getWalletName()); + } + + private boolean isWalletOpen() { + synchronized (walletLock) { + return wallet != null; } } @@ -1313,7 +1325,7 @@ public abstract class Trade implements Tradable, Model { // save wallet if (wallet != null) { try { - xmrWalletService.saveWallet(wallet, false); // skip backup + xmrWalletService.saveWallet(wallet); stopWallet(); } catch (Exception e) { // warning will be logged for main wallet, so skip logging here @@ -1333,6 +1345,9 @@ public abstract class Trade implements Tradable, Model { forceStopWallet(); } + // backup trade wallet if applicable + maybeBackupWallet(); + // de-initialize if (idlePayoutSyncer != null) { xmrWalletService.removeWalletListener(idlePayoutSyncer); diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 9111aad0..44528ee9 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -220,7 +220,7 @@ public class XmrWalletService { } public void saveMainWallet() { - saveMainWallet(true); + saveMainWallet(!(Utilities.isWindows() && wallet != null)); } public void saveMainWallet(boolean backup) { @@ -324,6 +324,10 @@ public class XmrWalletService { return syncWallet(wallet); } + public void saveWallet(MoneroWallet wallet) { + saveWallet(wallet, false); + } + public void saveWallet(MoneroWallet wallet, boolean backup) { wallet.save(); if (backup) backupWallet(wallet.getPath());