From 84978a3d5dc1bbf33a0b345e473c3755586f7dd2 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 6 Mar 2023 12:30:26 +0200 Subject: [PATCH] use different addresses when sending batched payments to the same paynym --- .../sparrow/wallet/PaymentController.java | 9 +++++++++ .../sparrow/wallet/SendController.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java index c4433e93..2498282c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java @@ -413,7 +413,11 @@ public class PaymentController extends WalletFormController implements Initializ try { Wallet recipientBip47Wallet = getWalletForPayNym(payNym); if(recipientBip47Wallet != null) { + int index = sendController.getPayNymSendIndex(this); WalletNode sendNode = recipientBip47Wallet.getFreshNode(KeyPurpose.SEND); + for(int i = 0; i < index; i++) { + sendNode = recipientBip47Wallet.getFreshNode(KeyPurpose.SEND, sendNode); + } ECKey pubKey = sendNode.getPubKey(); Address address = recipientBip47Wallet.getScriptType().getAddress(pubKey); if(sendController.getPaymentTabs().getTabs().size() > 1 || (getRecipientValueSats() != null && getRecipientValueSats() > getRecipientDustThreshold(address)) || maxButton.isSelected()) { @@ -433,6 +437,11 @@ public class PaymentController extends WalletFormController implements Initializ return masterWallet.getChildWallet(new PaymentCode(payNym.paymentCode().toString()), payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH); } + boolean isSentToSamePayNym(PaymentController paymentController) { + return (this != paymentController && payNymProperty.get() != null && !payNymProperty.get().isCollaborativeSend() + && payNymProperty.get().paymentCode().equals(paymentController.payNymProperty.get().paymentCode())); + } + private Long getRecipientValueSats() { return getRecipientValueSats(amountUnit.getSelectionModel().getSelectedItem()); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 5966f809..b080a06b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -542,6 +542,20 @@ public class SendController extends WalletFormController implements Initializabl } } + int getPayNymSendIndex(PaymentController paymentController) { + int index = 0; + for(Tab tab : paymentTabs.getTabs()) { + PaymentController controller = (PaymentController)tab.getUserData(); + if(controller == paymentController) { + break; + } else if(controller.isSentToSamePayNym(paymentController)) { + index++; + } + } + + return index; + } + public void updateTransaction() { updateTransaction(null); }