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

This commit is contained in:
Craig Raw 2022-04-28 14:57:04 +02:00
parent 6931cf7a45
commit b1e715b272
2 changed files with 11 additions and 3 deletions

View file

@ -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;

View file

@ -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;