Skip to content

Commit

Permalink
Do a backup of the wallet before segwit migration
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarguindzberg committed Oct 8, 2020
1 parent 417daf5 commit 87da2ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/btc/setup/WalletConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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.*;
Expand Down Expand Up @@ -510,6 +511,14 @@ public void maybeAddSegwitKeychain(Wallet wallet, KeyParameter aesKey) {
// 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) {
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/btc/setup/WalletsSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
@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();

Expand Down Expand Up @@ -421,6 +423,13 @@ public void clearBackups() {
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);
}
}


Expand Down

0 comments on commit 87da2ae

Please sign in to comment.