mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
various db persistence improvements
This commit is contained in:
parent
445db6a4d6
commit
eaa5190502
5 changed files with 31 additions and 7 deletions
|
@ -836,7 +836,10 @@ public class AppServices {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void openWallets(OpenWalletsEvent event) {
|
public void openWallets(OpenWalletsEvent event) {
|
||||||
if(event.getWalletTabDataList().isEmpty()) {
|
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 {
|
} else {
|
||||||
walletWindows.put(event.getWindow(), event.getWalletTabDataList());
|
walletWindows.put(event.getWindow(), event.getWalletTabDataList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ public class KeystoneSinglesig implements KeystoreFileImport, WalletImport {
|
||||||
keystore.setExtendedPublicKey(xpub);
|
keystore.setExtendedPublicKey(xpub);
|
||||||
|
|
||||||
return keystore;
|
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) {
|
} catch (Exception e) {
|
||||||
log.error("Error getting Keystone keystore", e);
|
log.error("Error getting Keystone keystore", e);
|
||||||
throw new ImportException("Error getting Keystone keystore", e);
|
throw new ImportException("Error getting Keystone keystore", e);
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class DbPersistence implements Persistence {
|
||||||
Wallet backupWallet = null;
|
Wallet backupWallet = null;
|
||||||
if(backupFile != null) {
|
if(backupFile != null) {
|
||||||
Persistence backupPersistence = PersistenceType.DB.getInstance();
|
Persistence backupPersistence = PersistenceType.DB.getInstance();
|
||||||
|
backupPersistence.setKeyDeriver(keyDeriver);
|
||||||
backupWallet = backupPersistence.loadWallet(new Storage(backupPersistence, backupFile), password, encryptionKey).getWallet();
|
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 {
|
private ECKey getEncryptionKey(CharSequence password, File walletFile, ECKey alreadyDerivedKey) throws IOException {
|
||||||
if(password != null && password.equals("")) {
|
if(alreadyDerivedKey != null) {
|
||||||
|
return alreadyDerivedKey;
|
||||||
|
} else if(password == null) {
|
||||||
|
return null;
|
||||||
|
} else if(password.equals("")) {
|
||||||
return Storage.NO_PASSWORD_KEY;
|
return Storage.NO_PASSWORD_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
AsymmetricKeyDeriver keyDeriver = getKeyDeriver(walletFile);
|
AsymmetricKeyDeriver keyDeriver = getKeyDeriver(walletFile);
|
||||||
if(alreadyDerivedKey != null) {
|
return keyDeriver.deriveECKey(password);
|
||||||
return alreadyDerivedKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
return password == null ? null : keyDeriver.deriveECKey(password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -555,6 +555,9 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
|
|
||||||
walletForm.getStorage().setEncryptionPubKey(null);
|
walletForm.getStorage().setEncryptionPubKey(null);
|
||||||
walletForm.getWallet().decrypt(key);
|
walletForm.getWallet().decrypt(key);
|
||||||
|
for(Wallet childWallet : walletForm.getWallet().getChildWallets()) {
|
||||||
|
childWallet.decrypt(key);
|
||||||
|
}
|
||||||
saveWallet(true, false);
|
saveWallet(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -564,6 +567,9 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
}
|
}
|
||||||
|
|
||||||
walletForm.getWallet().encrypt(key);
|
walletForm.getWallet().encrypt(key);
|
||||||
|
for(Wallet childWallet : walletForm.getWallet().getChildWallets()) {
|
||||||
|
childWallet.encrypt(key);
|
||||||
|
}
|
||||||
walletForm.getStorage().setEncryptionPubKey(encryptionPubKey);
|
walletForm.getStorage().setEncryptionPubKey(encryptionPubKey);
|
||||||
walletForm.saveAndRefresh();
|
walletForm.saveAndRefresh();
|
||||||
EventManager.get().post(new RequestOpenWalletsEvent());
|
EventManager.get().post(new RequestOpenWalletsEvent());
|
||||||
|
|
|
@ -95,6 +95,17 @@ public class SettingsWalletForm extends WalletForm {
|
||||||
EventManager.get().post(new KeystoreEncryptionChangedEvent(wallet, pastWallet, getWalletId(), encryptionChangedKeystores));
|
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()) {
|
if(labelChangedKeystores.isEmpty() && encryptionChangedKeystores.isEmpty()) {
|
||||||
//Can only be a wallet password change on a wallet without private keys
|
//Can only be a wallet password change on a wallet without private keys
|
||||||
EventManager.get().post(new WalletPasswordChangedEvent(wallet, pastWallet, getWalletId()));
|
EventManager.get().post(new WalletPasswordChangedEvent(wallet, pastWallet, getWalletId()));
|
||||||
|
|
Loading…
Reference in a new issue