diff --git a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java index 20672c5d..5dd46005 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java +++ b/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 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; diff --git a/src/main/java/com/sparrowwallet/sparrow/io/db/WalletDao.java b/src/main/java/com/sparrowwallet/sparrow/io/db/WalletDao.java index 6753d0b3..06abe048 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/WalletDao.java +++ b/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;