return boolean if labels have changed

This commit is contained in:
Craig Raw 2021-03-01 15:26:55 +02:00
parent 08acfe5ba1
commit faa8f71313

View file

@ -208,13 +208,16 @@ public class WalletNode implements Comparable<WalletNode> {
return copy; return copy;
} }
public void copyLabels(WalletNode pastNode) { public boolean copyLabels(WalletNode pastNode) {
if(pastNode == null) { if(pastNode == null) {
return; return false;
} }
boolean changed = false;
if(label == null && pastNode.label != null) { if(label == null && pastNode.label != null) {
label = pastNode.label; label = pastNode.label;
changed = true;
} }
for(BlockTransactionHashIndex txo : getTransactionOutputs()) { for(BlockTransactionHashIndex txo : getTransactionOutputs()) {
@ -223,16 +226,22 @@ public class WalletNode implements Comparable<WalletNode> {
BlockTransactionHashIndex pastTxo = optPastTxo.get(); BlockTransactionHashIndex pastTxo = optPastTxo.get();
if(txo.getLabel() == null && pastTxo.getLabel() != null) { if(txo.getLabel() == null && pastTxo.getLabel() != null) {
txo.setLabel(pastTxo.getLabel()); txo.setLabel(pastTxo.getLabel());
changed = true;
} }
if(txo.isSpent() && pastTxo.isSpent() && txo.getSpentBy().getLabel() == null && pastTxo.getSpentBy().getLabel() != null) { if(txo.isSpent() && pastTxo.isSpent() && txo.getSpentBy().getLabel() == null && pastTxo.getSpentBy().getLabel() != null) {
txo.getSpentBy().setLabel(pastTxo.getSpentBy().getLabel()); txo.getSpentBy().setLabel(pastTxo.getSpentBy().getLabel());
changed = true;
} }
} }
} }
for(WalletNode childNode : getChildren()) { for(WalletNode childNode : getChildren()) {
Optional<WalletNode> optPastChildNode = pastNode.getChildren().stream().filter(node -> node.equals(childNode)).findFirst(); Optional<WalletNode> optPastChildNode = pastNode.getChildren().stream().filter(node -> node.equals(childNode)).findFirst();
optPastChildNode.ifPresent(childNode::copyLabels); if(optPastChildNode.isPresent()) {
changed |= childNode.copyLabels(optPastChildNode.get());
}
} }
return changed;
} }
} }