Do a backup of the wallet before segwit migration

This commit is contained in:
Oscar Guindzberg 2020-10-08 16:22:52 -03:00
parent 417daf5692
commit 87da2ae349
No known key found for this signature in database
GPG key ID: 209796BF2E1D4F75
2 changed files with 18 additions and 0 deletions

View file

@ -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) {

View file

@ -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);
}
}