support wallet labels copying from past wallets

This commit is contained in:
Craig Raw 2021-02-09 17:31:26 +02:00
parent 44b29b2b7b
commit 3882a4b4bd
4 changed files with 41 additions and 4 deletions

View file

@ -18,7 +18,11 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
} }
public BlockTransaction(Sha256Hash hash, int height, Date date, Long fee, Transaction transaction, Sha256Hash blockHash) { public BlockTransaction(Sha256Hash hash, int height, Date date, Long fee, Transaction transaction, Sha256Hash blockHash) {
super(hash, height, date, fee); this(hash, height, date, fee, transaction, blockHash, null);
}
public BlockTransaction(Sha256Hash hash, int height, Date date, Long fee, Transaction transaction, Sha256Hash blockHash, String label) {
super(hash, height, date, fee, label);
this.transaction = transaction; this.transaction = transaction;
this.blockHash = blockHash; this.blockHash = blockHash;
} }

View file

@ -16,11 +16,12 @@ public abstract class BlockTransactionHash {
private String label; private String label;
public BlockTransactionHash(Sha256Hash hash, int height, Date date, Long fee) { public BlockTransactionHash(Sha256Hash hash, int height, Date date, Long fee, String label) {
this.hash = hash; this.hash = hash;
this.height = height; this.height = height;
this.date = date; this.date = date;
this.fee = fee; this.fee = fee;
this.label = label;
} }
public Sha256Hash getHash() { public Sha256Hash getHash() {

View file

@ -16,7 +16,11 @@ public class BlockTransactionHashIndex extends BlockTransactionHash implements C
} }
public BlockTransactionHashIndex(Sha256Hash hash, int height, Date date, Long fee, long index, long value, BlockTransactionHashIndex spentBy) { public BlockTransactionHashIndex(Sha256Hash hash, int height, Date date, Long fee, long index, long value, BlockTransactionHashIndex spentBy) {
super(hash, height, date, fee); this(hash, height, date, fee, index, value, spentBy, null);
}
public BlockTransactionHashIndex(Sha256Hash hash, int height, Date date, Long fee, long index, long value, BlockTransactionHashIndex spentBy, String label) {
super(hash, height, date, fee, label);
this.index = index; this.index = index;
this.value = value; this.value = value;
this.spentBy = spentBy; this.spentBy = spentBy;
@ -92,6 +96,6 @@ public class BlockTransactionHashIndex extends BlockTransactionHash implements C
} }
public BlockTransactionHashIndex copy() { public BlockTransactionHashIndex copy() {
return new BlockTransactionHashIndex(super.getHash(), super.getHeight(), super.getDate(), super.getFee(), index, value, spentBy == null ? null : spentBy.copy()); return new BlockTransactionHashIndex(super.getHash(), super.getHeight(), super.getDate(), super.getFee(), index, value, spentBy == null ? null : spentBy.copy(), super.getLabel());
} }
} }

View file

@ -207,4 +207,32 @@ public class WalletNode implements Comparable<WalletNode> {
return copy; return copy;
} }
public void copyLabels(WalletNode pastNode) {
if(pastNode == null) {
return;
}
if(label == null && pastNode.label != null) {
label = pastNode.label;
}
for(BlockTransactionHashIndex txo : getTransactionOutputs()) {
Optional<BlockTransactionHashIndex> optPastTxo = pastNode.getTransactionOutputs().stream().filter(pastTxo -> pastTxo.equals(txo)).findFirst();
if(optPastTxo.isPresent()) {
BlockTransactionHashIndex pastTxo = optPastTxo.get();
if(txo.getLabel() == null && pastTxo.getLabel() != null) {
txo.setLabel(pastTxo.getLabel());
}
if(txo.isSpent() && pastTxo.isSpent() && txo.getSpentBy().getLabel() == null && pastTxo.getSpentBy().getLabel() != null) {
txo.getSpentBy().setLabel(pastTxo.getSpentBy().getLabel());
}
}
}
for(WalletNode childNode : getChildren()) {
Optional<WalletNode> optPastChildNode = pastNode.getChildren().stream().filter(node -> node.equals(childNode)).findFirst();
optPastChildNode.ifPresent(childNode::copyLabels);
}
}
} }