From b1bc25ba04a4e8a773e4a384b583fe4f9afa2b4a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 29 Aug 2023 16:03:46 +0200 Subject: [PATCH] propagate transaction label changes to inputs, outputs and addresses where their existing labels were set in the same manner --- .../com/sparrowwallet/sparrow/wallet/WalletForm.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 2a850d2d..aac386eb 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -506,16 +506,22 @@ public class WalletForm { for(WalletNode childNode : wallet.getNode(keyPurpose).getChildren()) { for(BlockTransactionHashIndex receivedRef : childNode.getTransactionOutputs()) { if(receivedRef.getHash().equals(transactionEntry.getBlockTransaction().getHash())) { - if((receivedRef.getLabel() == null || receivedRef.getLabel().isEmpty()) && wallet.getStandardAccountType() != StandardAccount.WHIRLPOOL_PREMIX) { + String prevRefLabel = ""; + if((receivedRef.getLabel() == null || receivedRef.getLabel().isEmpty() + || receivedRef.getLabel().endsWith(" (sent)") || receivedRef.getLabel().endsWith(" (change)") || receivedRef.getLabel().endsWith(" (received)")) + && wallet.getStandardAccountType() != StandardAccount.WHIRLPOOL_PREMIX) { + prevRefLabel = receivedRef.getLabel(); receivedRef.setLabel(entry.getLabel() + (keyPurpose == KeyPurpose.CHANGE ? (event.getWallet().isBip47() ? " (sent)" : " (change)") : " (received)")); labelChangedEntries.put(new HashIndexEntry(event.getWallet(), receivedRef, HashIndexEntry.Type.OUTPUT, keyPurpose), entry); } - if((childNode.getLabel() == null || childNode.getLabel().isEmpty())) { + if(childNode.getLabel() == null || childNode.getLabel().isEmpty() + || prevRefLabel.equals(childNode.getLabel() + " (sent)") || prevRefLabel.equals(childNode.getLabel() + " (change)") || prevRefLabel.equals(childNode.getLabel() + " (received)")) { childNode.setLabel(entry.getLabel()); labelChangedEntries.put(new NodeEntry(event.getWallet(), childNode), entry); } } - if(receivedRef.isSpent() && receivedRef.getSpentBy().getHash().equals(transactionEntry.getBlockTransaction().getHash()) && (receivedRef.getSpentBy().getLabel() == null || receivedRef.getSpentBy().getLabel().isEmpty())) { + if(receivedRef.isSpent() && receivedRef.getSpentBy().getHash().equals(transactionEntry.getBlockTransaction().getHash()) + && (receivedRef.getSpentBy().getLabel() == null || receivedRef.getSpentBy().getLabel().isEmpty() || receivedRef.getSpentBy().getLabel().endsWith(" (input)"))) { receivedRef.getSpentBy().setLabel(entry.getLabel() + " (input)"); labelChangedEntries.put(new HashIndexEntry(event.getWallet(), receivedRef.getSpentBy(), HashIndexEntry.Type.INPUT, keyPurpose), entry); }