From 640176153016e6b38b367d6d7e37ecf15cfee745 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 17 Mar 2022 09:44:47 +0200 Subject: [PATCH] automatically label new bip47 receive addresses to identify incoming bip47 payments --- .../drongo/wallet/WalletNode.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java index ae1374a..af1fe5d 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletNode.java @@ -179,11 +179,22 @@ public class WalletNode extends Persistable implements Comparable { public Set fillToIndex(Wallet wallet, int index) { Set newNodes = fillToIndex(index); - if(!wallet.getDetachedLabels().isEmpty() && wallet.isValid()) { - for(WalletNode newNode : newNodes) { - String label = wallet.getDetachedLabels().remove(newNode.getAddress().toString()); - if(label != null && (newNode.getLabel() == null || newNode.getLabel().isEmpty())) { - newNode.setLabel(label); + if(wallet.isValid()) { + if(!wallet.getDetachedLabels().isEmpty()) { + for(WalletNode newNode : newNodes) { + String label = wallet.getDetachedLabels().remove(newNode.getAddress().toString()); + if(label != null && (newNode.getLabel() == null || newNode.getLabel().isEmpty())) { + newNode.setLabel(label); + } + } + } + + if(wallet.isBip47() && keyPurpose == KeyPurpose.RECEIVE && wallet.getLabel() != null && !newNodes.isEmpty()) { + String suffix = " " + wallet.getScriptType().getName(); + for(WalletNode newNode : newNodes) { + if((newNode.getLabel() == null || newNode.getLabel().isEmpty()) && wallet.getLabel().endsWith(suffix)) { + newNode.setLabel("From " + wallet.getLabel().substring(0, wallet.getLabel().length() - suffix.length())); + } } } }