automatically label new bip47 receive addresses to identify incoming bip47 payments

This commit is contained in:
Craig Raw 2022-03-17 09:44:47 +02:00
parent 04631be8c1
commit 6401761530

View file

@ -179,7 +179,8 @@ public class WalletNode extends Persistable implements Comparable<WalletNode> {
public Set<WalletNode> fillToIndex(Wallet wallet, int index) { public Set<WalletNode> fillToIndex(Wallet wallet, int index) {
Set<WalletNode> newNodes = fillToIndex(index); Set<WalletNode> newNodes = fillToIndex(index);
if(!wallet.getDetachedLabels().isEmpty() && wallet.isValid()) { if(wallet.isValid()) {
if(!wallet.getDetachedLabels().isEmpty()) {
for(WalletNode newNode : newNodes) { for(WalletNode newNode : newNodes) {
String label = wallet.getDetachedLabels().remove(newNode.getAddress().toString()); String label = wallet.getDetachedLabels().remove(newNode.getAddress().toString());
if(label != null && (newNode.getLabel() == null || newNode.getLabel().isEmpty())) { if(label != null && (newNode.getLabel() == null || newNode.getLabel().isEmpty())) {
@ -188,6 +189,16 @@ public class WalletNode extends Persistable implements Comparable<WalletNode> {
} }
} }
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()));
}
}
}
}
return newNodes; return newNodes;
} }