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;
}
public void copyLabels(WalletNode pastNode) {
public boolean copyLabels(WalletNode pastNode) {
if(pastNode == null) {
return;
return false;
}
boolean changed = false;
if(label == null && pastNode.label != null) {
label = pastNode.label;
changed = true;
}
for(BlockTransactionHashIndex txo : getTransactionOutputs()) {
@ -223,16 +226,22 @@ public class WalletNode implements Comparable<WalletNode> {
BlockTransactionHashIndex pastTxo = optPastTxo.get();
if(txo.getLabel() == null && pastTxo.getLabel() != null) {
txo.setLabel(pastTxo.getLabel());
changed = true;
}
if(txo.isSpent() && pastTxo.isSpent() && txo.getSpentBy().getLabel() == null && pastTxo.getSpentBy().getLabel() != null) {
txo.getSpentBy().setLabel(pastTxo.getSpentBy().getLabel());
changed = true;
}
}
}
for(WalletNode childNode : getChildren()) {
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;
}
}