Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve restore wallet from seed process #2524

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions core/src/main/java/bisq/core/btc/model/AddressEntryList.java
Expand Up @@ -25,6 +25,7 @@

import com.google.protobuf.Message;

import org.bitcoinj.core.Transaction;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.wallet.Wallet;

Expand Down Expand Up @@ -123,22 +124,29 @@ public void onWalletReady(Wallet wallet) {
persist();
}

// We add a confidence listener to get notified about potential new transactions and
// We add those listeners to get notified about potential new transactions and
// add an address entry list in case it does not exist yet. This is mainly needed for restore from seed words
// but can help as well in case the addressEntry list would miss an address where the wallet was received
// funds (e.g. if the user sends funds to an address which has not been provided in the main UI - like from the
// wallet details window).
wallet.addTransactionConfidenceEventListener((w, tx) -> {
tx.getOutputs().stream()
.filter(output -> output.isMine(wallet))
.map(output -> output.getAddressFromP2PKHScript(wallet.getNetworkParameters()))
.filter(Objects::nonNull)
.filter(address -> !listContainsEntryWithAddress(address.toBase58()))
.map(address -> (DeterministicKey) wallet.findKeyFromPubHash(address.getHash160()))
.filter(Objects::nonNull)
.map(deterministicKey -> new AddressEntry(deterministicKey, AddressEntry.Context.AVAILABLE))
.forEach(addressEntry -> list.add(addressEntry));
wallet.addCoinsReceivedEventListener((w, tx, prevBalance, newBalance) -> {
updateList(tx);
});
wallet.addCoinsSentEventListener((w, tx, prevBalance, newBalance) -> {
updateList(tx);
});
}

private void updateList(Transaction tx) {
tx.getOutputs().stream()
.filter(output -> output.isMine(wallet))
.map(output -> output.getAddressFromP2PKHScript(wallet.getNetworkParameters()))
.filter(Objects::nonNull)
.filter(address -> !listContainsEntryWithAddress(address.toBase58()))
.map(address -> (DeterministicKey) wallet.findKeyFromPubHash(address.getHash160()))
.filter(Objects::nonNull)
.map(deterministicKey -> new AddressEntry(deterministicKey, AddressEntry.Context.AVAILABLE))
.forEach(addressEntry -> list.add(addressEntry));
}

private boolean listContainsEntryWithAddress(String addressString) {
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Expand Up @@ -1162,7 +1162,11 @@ account.seed.enterPw=Enter password to view seed words
account.seed.restore.info=Please make a backup before applying restore from seed words. Be aware that wallet restore is \
only for emergency cases and might cause problems with the internal wallet database.\n\
It is not a way for applying a backup! Please use a backup from the application data directory for restoring a \
previous application state.
previous application state.\n\n\
After restoring the application will shut down automatically. After you have restarted the application it will resync \
with the Bitcoin network. This can take a while and can consume a lot fo CPU, specially if the wallet was older and \
had many transactions. Please avoid to interrupt that process, otherwise you might need to delete the SPV chain file \
again or repeat the restore process.
account.seed.restore.ok=Ok, I understand and want to restore


Expand Down
5 changes: 2 additions & 3 deletions desktop/src/main/java/bisq/desktop/util/GUIUtil.java
Expand Up @@ -781,9 +781,8 @@ public static void restoreSeedWords(DeterministicSeed seed, WalletsManager walle
seed,
() -> UserThread.execute(() -> {
log.info("Wallets restored with seed words");
new Popup<>().feedback(Res.get("seed.restore.success"))
.useShutDownButton()
.show();
new Popup<>().feedback(Res.get("seed.restore.success")).hideCloseButton().show();
BisqApp.getShutDownHandler().run();
}),
throwable -> UserThread.execute(() -> {
log.error(throwable.toString());
Expand Down