Browse Source

various db persistence improvements

terminal
Craig Raw 4 years ago
parent
commit
eaa5190502
  1. 5
      src/main/java/com/sparrowwallet/sparrow/AppServices.java
  2. 3
      src/main/java/com/sparrowwallet/sparrow/io/KeystoneSinglesig.java
  3. 13
      src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java
  4. 6
      src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java
  5. 11
      src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java

5
src/main/java/com/sparrowwallet/sparrow/AppServices.java

@ -836,7 +836,10 @@ public class AppServices {
@Subscribe
public void openWallets(OpenWalletsEvent event) {
if(event.getWalletTabDataList().isEmpty()) {
walletWindows.remove(event.getWindow());
List<WalletTabData> closedTabData = walletWindows.remove(event.getWindow());
if(closedTabData != null && !closedTabData.isEmpty()) {
EventManager.get().post(new WalletTabsClosedEvent(closedTabData));
}
} else {
walletWindows.put(event.getWindow(), event.getWalletTabDataList());
}

3
src/main/java/com/sparrowwallet/sparrow/io/KeystoneSinglesig.java

@ -61,6 +61,9 @@ public class KeystoneSinglesig implements KeystoreFileImport, WalletImport {
keystore.setExtendedPublicKey(xpub);
return keystore;
} catch (IllegalArgumentException e) {
log.error("Error getting Keystone keystore - not an output descriptor");
throw new ImportException("Error getting Keystone keystore", e);
} catch (Exception e) {
log.error("Error getting Keystone keystore", e);
throw new ImportException("Error getting Keystone keystore", e);

13
src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java

@ -86,6 +86,7 @@ public class DbPersistence implements Persistence {
Wallet backupWallet = null;
if(backupFile != null) {
Persistence backupPersistence = PersistenceType.DB.getInstance();
backupPersistence.setKeyDeriver(keyDeriver);
backupWallet = backupPersistence.loadWallet(new Storage(backupPersistence, backupFile), password, encryptionKey).getWallet();
}
@ -392,16 +393,16 @@ public class DbPersistence implements Persistence {
}
private ECKey getEncryptionKey(CharSequence password, File walletFile, ECKey alreadyDerivedKey) throws IOException {
if(password != null && password.equals("")) {
return Storage.NO_PASSWORD_KEY;
}
AsymmetricKeyDeriver keyDeriver = getKeyDeriver(walletFile);
if(alreadyDerivedKey != null) {
return alreadyDerivedKey;
} else if(password == null) {
return null;
} else if(password.equals("")) {
return Storage.NO_PASSWORD_KEY;
}
return password == null ? null : keyDeriver.deriveECKey(password);
AsymmetricKeyDeriver keyDeriver = getKeyDeriver(walletFile);
return keyDeriver.deriveECKey(password);
}
@Override

6
src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java

@ -555,6 +555,9 @@ public class SettingsController extends WalletFormController implements Initiali
walletForm.getStorage().setEncryptionPubKey(null);
walletForm.getWallet().decrypt(key);
for(Wallet childWallet : walletForm.getWallet().getChildWallets()) {
childWallet.decrypt(key);
}
saveWallet(true, false);
return;
}
@ -564,6 +567,9 @@ public class SettingsController extends WalletFormController implements Initiali
}
walletForm.getWallet().encrypt(key);
for(Wallet childWallet : walletForm.getWallet().getChildWallets()) {
childWallet.encrypt(key);
}
walletForm.getStorage().setEncryptionPubKey(encryptionPubKey);
walletForm.saveAndRefresh();
EventManager.get().post(new RequestOpenWalletsEvent());

11
src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java

@ -95,6 +95,17 @@ public class SettingsWalletForm extends WalletForm {
EventManager.get().post(new KeystoreEncryptionChangedEvent(wallet, pastWallet, getWalletId(), encryptionChangedKeystores));
}
for(Wallet childWallet : wallet.getChildWallets()) {
Wallet childWalletCopy = walletCopy.getChildWallet(childWallet.getName());
if(childWalletCopy != null) {
Wallet pastChildWallet = childWallet.copy();
List<Keystore> childEncryptionChangedKeystores = getEncryptionChangedKeystores(childWallet, childWalletCopy);
if(!childEncryptionChangedKeystores.isEmpty()) {
EventManager.get().post(new KeystoreEncryptionChangedEvent(childWallet, pastChildWallet, getStorage().getWalletId(childWallet), childEncryptionChangedKeystores));
}
}
}
if(labelChangedKeystores.isEmpty() && encryptionChangedKeystores.isEmpty()) {
//Can only be a wallet password change on a wallet without private keys
EventManager.get().post(new WalletPasswordChangedEvent(wallet, pastWallet, getWalletId()));

Loading…
Cancel
Save