mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
update wallet name in db on load if wallet filename is changed
This commit is contained in:
parent
6931cf7a45
commit
b1e715b272
2 changed files with 11 additions and 3 deletions
|
@ -84,7 +84,7 @@ public class DbPersistence implements Persistence {
|
||||||
Jdbi jdbi = getJdbi(storage, getFilePassword(encryptionKey));
|
Jdbi jdbi = getJdbi(storage, getFilePassword(encryptionKey));
|
||||||
masterWallet = jdbi.withHandle(handle -> {
|
masterWallet = jdbi.withHandle(handle -> {
|
||||||
WalletDao walletDao = handle.attach(WalletDao.class);
|
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);
|
Map<WalletAndKey, Storage> childWallets = loadChildWallets(storage, masterWallet, encryptionKey);
|
||||||
|
@ -109,7 +109,7 @@ public class DbPersistence implements Persistence {
|
||||||
Jdbi childJdbi = getJdbi(storage, getFilePassword(encryptionKey));
|
Jdbi childJdbi = getJdbi(storage, getFilePassword(encryptionKey));
|
||||||
Wallet wallet = childJdbi.withHandle(handle -> {
|
Wallet wallet = childJdbi.withHandle(handle -> {
|
||||||
WalletDao walletDao = handle.attach(WalletDao.class);
|
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.setName(schema.substring(WALLET_SCHEMA_PREFIX.length()));
|
||||||
childWallet.setMasterWallet(masterWallet);
|
childWallet.setMasterWallet(masterWallet);
|
||||||
return childWallet;
|
return childWallet;
|
||||||
|
|
|
@ -55,6 +55,9 @@ public interface WalletDao {
|
||||||
@GetGeneratedKeys("id")
|
@GetGeneratedKeys("id")
|
||||||
long insert(String name, String label, int network, int policyType, int scriptType, Integer storedBlockHeight, Integer gapLimit, Integer watchLast, Date birthDate, long defaultPolicy);
|
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")
|
@SqlUpdate("update wallet set label = :label where id = :id")
|
||||||
void updateLabel(@Bind("id") long id, @Bind("label") String label);
|
void updateLabel(@Bind("id") long id, @Bind("label") String label);
|
||||||
|
|
||||||
|
@ -70,12 +73,17 @@ public interface WalletDao {
|
||||||
@SqlUpdate("set schema ?")
|
@SqlUpdate("set schema ?")
|
||||||
int setSchema(String schema);
|
int setSchema(String schema);
|
||||||
|
|
||||||
default Wallet getMainWallet(String schema) {
|
default Wallet getMainWallet(String schema, String walletName) {
|
||||||
try {
|
try {
|
||||||
setSchema(schema);
|
setSchema(schema);
|
||||||
Wallet mainWallet = loadMainWallet();
|
Wallet mainWallet = loadMainWallet();
|
||||||
if(mainWallet != null) {
|
if(mainWallet != null) {
|
||||||
loadWallet(mainWallet);
|
loadWallet(mainWallet);
|
||||||
|
|
||||||
|
if(walletName != null && !walletName.equals(mainWallet.getName())) {
|
||||||
|
mainWallet.setName(walletName);
|
||||||
|
updateName(mainWallet.getId(), walletName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainWallet;
|
return mainWallet;
|
||||||
|
|
Loading…
Reference in a new issue