From 813e0f3ab199920765f7e8ba60c27d4e7efc3671 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 21 Oct 2021 14:38:13 +0200 Subject: [PATCH] retrieve stored index from mixconfig on whirlpool wallet load --- .../com/sparrowwallet/sparrow/wallet/SendController.java | 1 + .../sparrow/whirlpool/dataSource/SparrowDataSource.java | 6 ++++-- .../sparrow/whirlpool/dataSource/SparrowIndexHandler.java | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 69c37704..942cacef 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -1145,6 +1145,7 @@ public class SendController extends WalletFormController implements Initializabl AppServices.showErrorDialog("Error broadcasting premix transaction", exception.getMessage()); }); ServiceProgressDialog progressDialog = new ServiceProgressDialog("Whirlpool", "Broadcast Premix Transaction", "/image/whirlpool.png", tx0BroadcastService); + AppServices.moveToActiveWindowScreen(progressDialog); tx0BroadcastService.start(); } diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java index c3ee29a3..bb133dce 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java @@ -89,8 +89,10 @@ public class SparrowDataSource extends WalletResponseDataSource { List headers = ExtendedKey.Header.getHeaders(Network.get()); ExtendedKey.Header header = headers.stream().filter(head -> head.getDefaultScriptType().equals(wallet.getScriptType()) && !head.isPrivateKey()).findFirst().orElse(ExtendedKey.Header.xpub); address.address = wallet.getKeystores().get(0).getExtendedPublicKey().toString(header); - address.account_index = wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() + 1; - address.change_index = wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() + 1; + int receiveIndex = wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() + 1; + address.account_index = wallet.getMixConfig() != null ? Math.max(receiveIndex, wallet.getMixConfig().getReceiveIndex()) : receiveIndex; + int changeIndex = wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() + 1; + address.change_index = wallet.getMixConfig() != null ? Math.max(changeIndex, wallet.getMixConfig().getChangeIndex()) : changeIndex; address.n_tx = wallet.getTransactions().size(); addresses.add(address); diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowIndexHandler.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowIndexHandler.java index d1cc7032..db635ee0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowIndexHandler.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowIndexHandler.java @@ -60,13 +60,13 @@ public class SparrowIndexHandler extends AbstractIndexHandler { private void setStoredIndex(int index) { if(wallet.getMixConfig() != null) { - if(walletNode.getKeyPurpose() == KeyPurpose.RECEIVE) { + if(walletNode.getKeyPurpose() == KeyPurpose.RECEIVE && wallet.getMixConfig().getReceiveIndex() != index) { wallet.getMixConfig().setReceiveIndex(index); - } else if(walletNode.getKeyPurpose() == KeyPurpose.CHANGE) { + EventManager.get().post(new WalletMixConfigChangedEvent(wallet)); + } else if(walletNode.getKeyPurpose() == KeyPurpose.CHANGE && wallet.getMixConfig().getChangeIndex() != index) { wallet.getMixConfig().setChangeIndex(index); + EventManager.get().post(new WalletMixConfigChangedEvent(wallet)); } - - EventManager.get().post(new WalletMixConfigChangedEvent(wallet)); } }