From 143472bdfc120e84a10952a1bef60c6fb8710792 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 1 Jul 2021 09:41:56 +0200 Subject: [PATCH] fix save of address labels on a new wallet --- .../sparrow/io/db/DbPersistence.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 29771f60..2c2748c8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java @@ -237,8 +237,20 @@ public class DbPersistence implements Persistence { for(Entry entry : dirtyPersistables.labelEntries) { if(entry instanceof TransactionEntry && ((TransactionEntry)entry).getBlockTransaction().getId() != null) { blockTransactionDao.updateLabel(((TransactionEntry)entry).getBlockTransaction().getId(), entry.getLabel()); - } else if(entry instanceof NodeEntry && ((NodeEntry)entry).getNode().getId() != null) { - walletNodeDao.updateNodeLabel(((NodeEntry)entry).getNode().getId(), entry.getLabel()); + } else if(entry instanceof NodeEntry) { + WalletNode addressNode = ((NodeEntry)entry).getNode(); + if(addressNode.getId() == null) { + WalletNode purposeNode = wallet.getNode(addressNode.getKeyPurpose()); + if(purposeNode.getId() == null) { + long purposeNodeId = walletNodeDao.insertWalletNode(purposeNode.getDerivationPath(), purposeNode.getLabel(), wallet.getId(), null); + purposeNode.setId(purposeNodeId); + } + + long nodeId = walletNodeDao.insertWalletNode(addressNode.getDerivationPath(), addressNode.getLabel(), wallet.getId(), purposeNode.getId()); + addressNode.setId(nodeId); + } + + walletNodeDao.updateNodeLabel(addressNode.getId(), entry.getLabel()); } else if(entry instanceof HashIndexEntry && ((HashIndexEntry)entry).getHashIndex().getId() != null) { walletNodeDao.updateTxoLabel(((HashIndexEntry)entry).getHashIndex().getId(), entry.getLabel()); }