Commit bf788a1e authored by Andreas Schildbach's avatar Andreas Schildbach

UpgradeWalletService: Simplify code.

parent 7c4fc3a4
/* /*
* Copyright 2014-2015 the original author or authors. * Copyright the original author or authors.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -33,7 +33,8 @@ import androidx.core.app.NotificationCompat; ...@@ -33,7 +33,8 @@ import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
/** /**
* This service upgrades the wallet to an HD wallet. Use {@link #startUpgrade(Context)} to start the process. * This service upgrades the wallet to a deterministic wallet. Use {@link #startUpgrade(Context)} to start the
* process.
* *
* It will upgrade and then hand over to {@Link BlockchainService} to pre-generate the look-ahead keys. If the * It will upgrade and then hand over to {@Link BlockchainService} to pre-generate the look-ahead keys. If the
* wallet is already upgraded, it will do nothing. * wallet is already upgraded, it will do nothing.
...@@ -51,7 +52,6 @@ public final class UpgradeWalletService extends IntentService { ...@@ -51,7 +52,6 @@ public final class UpgradeWalletService extends IntentService {
public UpgradeWalletService() { public UpgradeWalletService() {
super(UpgradeWalletService.class.getName()); super(UpgradeWalletService.class.getName());
setIntentRedelivery(true); setIntentRedelivery(true);
} }
...@@ -73,28 +73,20 @@ public final class UpgradeWalletService extends IntentService { ...@@ -73,28 +73,20 @@ public final class UpgradeWalletService extends IntentService {
@Override @Override
protected void onHandleIntent(final Intent intent) { protected void onHandleIntent(final Intent intent) {
org.bitcoinj.core.Context.propagate(Constants.CONTEXT); org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
final Wallet wallet = application.getWallet(); final Wallet wallet = application.getWallet();
if (wallet.isDeterministicUpgradeRequired(Constants.UPGRADE_OUTPUT_SCRIPT_TYPE)) { // Maybe upgrade wallet from basic to deterministic
// upgrade wallet to a specific deterministic chain if (wallet.isDeterministicUpgradeRequired(Constants.UPGRADE_OUTPUT_SCRIPT_TYPE))
wallet.upgradeToDeterministic(Constants.UPGRADE_OUTPUT_SCRIPT_TYPE, null); wallet.upgradeToDeterministic(Constants.UPGRADE_OUTPUT_SCRIPT_TYPE, null);
// let other service pre-generate look-ahead keys // Maybe upgrade wallet to secure chain
BlockchainService.start(this, false);
}
maybeUpgradeToSecureChain(wallet);
}
private void maybeUpgradeToSecureChain(final Wallet wallet) {
try { try {
wallet.doMaintenance(null, false); wallet.doMaintenance(null, false);
// let other service pre-generate look-ahead keys
BlockchainService.start(this, false);
} catch (final Exception x) { } catch (final Exception x) {
log.error("failed doing wallet maintenance", x); log.error("failed doing wallet maintenance", x);
} }
// Let other service pre-generate look-ahead keys
BlockchainService.start(this, false);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment