diff --git a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java index 6bf36d82b4..b7042e1c74 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java @@ -22,6 +22,7 @@ import bisq.core.btc.nodes.ProxySocketFactory; import bisq.core.btc.wallet.BisqRiskAnalysis; import bisq.common.config.Config; +import bisq.common.file.FileUtil; import com.google.common.io.Closeables; import com.google.common.util.concurrent.*; @@ -510,6 +511,14 @@ public class WalletConfig extends AbstractIdleService { // wait for the aesKey to be set and this method to be invoked again. return; } + // Do a backup of the wallet + File backup = new File(directory, WalletsSetup.PRE_SEGWIT_WALLET_BACKUP); + try { + FileUtil.copyFile(new File(directory, "bisq_BTC.wallet"), backup); + } catch (IOException e) { + log.error(e.toString(), e); + } + // Btc wallet does not have a native segwit keychain, we should add one. DeterministicSeed seed = wallet.getKeyChainSeed(); if (aesKey != null) { diff --git a/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java b/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java index 650f929785..9b1ce93418 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java @@ -109,6 +109,8 @@ import static com.google.common.base.Preconditions.checkNotNull; @Slf4j public class WalletsSetup { + public static final String PRE_SEGWIT_WALLET_BACKUP = "pre_segwit_bisq_BTC.wallet.backup"; + @Getter public final BooleanProperty walletsSetupFailed = new SimpleBooleanProperty(); @@ -421,6 +423,13 @@ public class WalletsSetup { log.error("Could not delete directory " + e.getMessage()); e.printStackTrace(); } + + File segwitBackup = new File(walletDir, PRE_SEGWIT_WALLET_BACKUP); + try { + FileUtil.deleteFileIfExists(segwitBackup); + } catch (IOException e) { + log.error(e.toString(), e); + } }