From dab6b9663a68a5fa0d03031c7caa32b4a0554e8b Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 28 Jul 2022 13:13:52 +0200 Subject: [PATCH] copy existing labels from deposit utxos into badbank utxos if present --- .../sparrow/net/ElectrumServer.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index c8de3a5d..9db6fe33 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -744,6 +744,7 @@ public class ElectrumServer { if(!transactionOutputs.equals(node.getTransactionOutputs())) { node.updateTransactionOutputs(wallet, transactionOutputs); copyPostmixLabels(wallet, transactionOutputs); + copyBadbankLabels(wallet, transactionOutputs); } } @@ -761,6 +762,21 @@ public class ElectrumServer { } } + public void copyBadbankLabels(Wallet wallet, Set newTransactionOutputs) { + if(wallet.getStandardAccountType() == StandardAccount.WHIRLPOOL_BADBANK && wallet.getMasterWallet() != null) { + Map masterWalletTxos = wallet.getMasterWallet().getWalletTxos(); + for(BlockTransactionHashIndex newRef : newTransactionOutputs) { + BlockTransactionHashIndex prevRef = masterWalletTxos.keySet().stream() + .filter(txo -> txo.isSpent() && txo.getSpentBy().getHash().equals(newRef.getHash()) && txo.getLabel() != null).findFirst().orElse(null); + if(prevRef != null) { + if(newRef.getLabel() == null && prevRef.getLabel() != null) { + newRef.setLabel("From " + prevRef.getLabel()); + } + } + } + } + } + public Map getReferencedTransactions(Set references, String scriptHash) throws ServerException { Set txids = new LinkedHashSet<>(references.size()); for(Sha256Hash reference : references) {