mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 18:16:45 +00:00
support wallet labels copying from past wallets
This commit is contained in:
parent
44b29b2b7b
commit
3882a4b4bd
4 changed files with 41 additions and 4 deletions
|
@ -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) {
|
||||
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.blockHash = blockHash;
|
||||
}
|
||||
|
|
|
@ -16,11 +16,12 @@ public abstract class BlockTransactionHash {
|
|||
|
||||
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.height = height;
|
||||
this.date = date;
|
||||
this.fee = fee;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Sha256Hash getHash() {
|
||||
|
|
|
@ -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) {
|
||||
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.value = value;
|
||||
this.spentBy = spentBy;
|
||||
|
@ -92,6 +96,6 @@ public class BlockTransactionHashIndex extends BlockTransactionHash implements C
|
|||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,4 +207,32 @@ public class WalletNode implements Comparable<WalletNode> {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue