Browse Source

update wallet name in db on load if wallet filename is changed

terminal
Craig Raw 3 years ago
parent
commit
b1e715b272
  1. 4
      src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java
  2. 10
      src/main/java/com/sparrowwallet/sparrow/io/db/WalletDao.java

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

@ -84,7 +84,7 @@ public class DbPersistence implements Persistence {
Jdbi jdbi = getJdbi(storage, getFilePassword(encryptionKey));
masterWallet = jdbi.withHandle(handle -> {
WalletDao walletDao = handle.attach(WalletDao.class);
return walletDao.getMainWallet(MASTER_SCHEMA);
return walletDao.getMainWallet(MASTER_SCHEMA, getWalletName(storage.getWalletFile(), null));
});
Map<WalletAndKey, Storage> childWallets = loadChildWallets(storage, masterWallet, encryptionKey);
@ -109,7 +109,7 @@ public class DbPersistence implements Persistence {
Jdbi childJdbi = getJdbi(storage, getFilePassword(encryptionKey));
Wallet wallet = childJdbi.withHandle(handle -> {
WalletDao walletDao = handle.attach(WalletDao.class);
Wallet childWallet = walletDao.getMainWallet(schema);
Wallet childWallet = walletDao.getMainWallet(schema, null);
childWallet.setName(schema.substring(WALLET_SCHEMA_PREFIX.length()));
childWallet.setMasterWallet(masterWallet);
return childWallet;

10
src/main/java/com/sparrowwallet/sparrow/io/db/WalletDao.java

@ -55,6 +55,9 @@ public interface WalletDao {
@GetGeneratedKeys("id")
long insert(String name, String label, int network, int policyType, int scriptType, Integer storedBlockHeight, Integer gapLimit, Integer watchLast, Date birthDate, long defaultPolicy);
@SqlUpdate("update wallet set name = :name where id = :id")
void updateName(@Bind("id") long id, @Bind("name") String name);
@SqlUpdate("update wallet set label = :label where id = :id")
void updateLabel(@Bind("id") long id, @Bind("label") String label);
@ -70,12 +73,17 @@ public interface WalletDao {
@SqlUpdate("set schema ?")
int setSchema(String schema);
default Wallet getMainWallet(String schema) {
default Wallet getMainWallet(String schema, String walletName) {
try {
setSchema(schema);
Wallet mainWallet = loadMainWallet();
if(mainWallet != null) {
loadWallet(mainWallet);
if(walletName != null && !walletName.equals(mainWallet.getName())) {
mainWallet.setName(walletName);
updateName(mainWallet.getId(), walletName);
}
}
return mainWallet;

Loading…
Cancel
Save