mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
fix keystore encryption issue when changing the password on a wallet with freshly added accounts
This commit is contained in:
parent
e0ff42b6a4
commit
7f254e763d
8 changed files with 58 additions and 5 deletions
|
@ -0,0 +1,24 @@
|
|||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
|
||||
public class NewChildWalletSavedEvent {
|
||||
private final Storage storage;
|
||||
private final Wallet masterWallet;
|
||||
private final Wallet childWallet;
|
||||
|
||||
public NewChildWalletSavedEvent(Storage storage, Wallet masterWallet, Wallet childWallet) {
|
||||
this.storage = storage;
|
||||
this.masterWallet = masterWallet;
|
||||
this.childWallet = childWallet;
|
||||
}
|
||||
|
||||
public String getMasterWalletId() {
|
||||
return storage.getWalletId(masterWallet);
|
||||
}
|
||||
|
||||
public Wallet getChildWallet() {
|
||||
return childWallet;
|
||||
}
|
||||
}
|
|
@ -441,6 +441,7 @@ public class PayNymController {
|
|||
if(!storage.isPersisted(addedWallet)) {
|
||||
try {
|
||||
storage.saveWallet(addedWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, addedWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sparrowwallet.sparrow.terminal.wallet;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.googlecode.lanterna.TerminalSize;
|
||||
import com.googlecode.lanterna.gui2.*;
|
||||
import com.googlecode.lanterna.gui2.dialogs.TextInputDialogBuilder;
|
||||
|
@ -21,8 +22,8 @@ import com.sparrowwallet.sparrow.io.Storage;
|
|||
import com.sparrowwallet.sparrow.io.StorageException;
|
||||
import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
|
||||
import com.sparrowwallet.sparrow.wallet.Function;
|
||||
import com.sparrowwallet.sparrow.wallet.SettingsWalletForm;
|
||||
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
||||
import com.sparrowwallet.sparrow.whirlpool.WhirlpoolServices;
|
||||
import javafx.application.Platform;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -276,6 +277,13 @@ public class SettingsDialog extends WalletDialog {
|
|||
return lines;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void newChildWalletSaved(NewChildWalletSavedEvent event) {
|
||||
if(event.getMasterWalletId().equals(getWalletForm().getMasterWalletId())) {
|
||||
((SettingsWalletForm)getWalletForm()).childWalletSaved(event.getChildWallet());
|
||||
}
|
||||
}
|
||||
|
||||
public enum PasswordRequirement {
|
||||
UPDATE_NEW("Add a password to the wallet?\nLeave empty for no password:", "No Password"),
|
||||
UPDATE_EMPTY("This wallet has no password.\nAdd a password to the wallet?\nLeave empty for no password:", "No Password"),
|
||||
|
|
|
@ -16,10 +16,7 @@ import com.sparrowwallet.sparrow.AppServices;
|
|||
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.UnitFormat;
|
||||
import com.sparrowwallet.sparrow.event.ChildWalletsAddedEvent;
|
||||
import com.sparrowwallet.sparrow.event.StorageEvent;
|
||||
import com.sparrowwallet.sparrow.event.TimedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent;
|
||||
import com.sparrowwallet.sparrow.event.*;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
|
||||
|
@ -151,6 +148,7 @@ public class WalletDialog extends DialogWindow {
|
|||
if(!storage.isPersisted(childWallet)) {
|
||||
try {
|
||||
storage.saveWallet(childWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, childWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
|
||||
|
|
|
@ -1196,6 +1196,7 @@ public class SendController extends WalletFormController implements Initializabl
|
|||
if(!storage.isPersisted(childWallet)) {
|
||||
try {
|
||||
storage.saveWallet(childWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, childWallet));
|
||||
} catch(Exception e) {
|
||||
AppServices.showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
|
||||
}
|
||||
|
@ -1381,6 +1382,7 @@ public class SendController extends WalletFormController implements Initializabl
|
|||
if(!storage.isPersisted(addedWallet)) {
|
||||
try {
|
||||
storage.saveWallet(addedWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, addedWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
|
||||
|
|
|
@ -631,6 +631,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
if(!storage.isPersisted(childWallet)) {
|
||||
try {
|
||||
storage.saveWallet(childWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, childWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
|
||||
|
@ -718,6 +719,13 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void newChildWalletSaved(NewChildWalletSavedEvent event) {
|
||||
if(event.getMasterWalletId().equals(walletForm.getMasterWalletId())) {
|
||||
((SettingsWalletForm)walletForm).childWalletSaved(event.getChildWallet());
|
||||
}
|
||||
}
|
||||
|
||||
private void saveWallet(boolean changePassword, boolean suggestChangePassword) {
|
||||
ECKey existingPubKey = walletForm.getStorage().getEncryptionPubKey();
|
||||
|
||||
|
|
|
@ -242,4 +242,15 @@ public class SettingsWalletForm extends WalletForm {
|
|||
|
||||
return changedKeystores;
|
||||
}
|
||||
|
||||
public void childWalletSaved(Wallet childWallet) {
|
||||
//Update the child wallets for the master wallet of the local walletCopy to ensure all KeystoreEncryptionChangedEvents are posted
|
||||
Wallet masterWalletCopy = walletCopy.isMasterWallet() ? walletCopy : walletCopy.getMasterWallet();
|
||||
Wallet childWalletCopy = masterWalletCopy.getChildWallet(childWallet.getName());
|
||||
if(childWalletCopy == null) {
|
||||
childWalletCopy = childWallet.copy();
|
||||
childWalletCopy.setMasterWallet(masterWalletCopy);
|
||||
masterWalletCopy.getChildWallets().add(childWallet.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,6 +189,7 @@ public class WalletForm {
|
|||
if(!storage.isPersisted(addedWallet)) {
|
||||
try {
|
||||
storage.saveWallet(addedWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, wallet, addedWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
|
||||
|
|
Loading…
Reference in a new issue