From 1d560d6aa620dd07c3d7954dd7a5eb8640de13c1 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 15 Nov 2023 10:20:58 +0200 Subject: [PATCH] save mix to wallet index to improve handling of mix out failures --- .../com/sparrowwallet/sparrow/whirlpool/Whirlpool.java | 4 ++++ .../whirlpool/dataSource/SparrowWalletStateSupplier.java | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java index 9f0984cb..ec39594e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java @@ -533,6 +533,10 @@ public class Whirlpool { int startIndex = highestUsedIndex == null ? 0 : highestUsedIndex + 1; int mixes = minMixes == null ? DEFAULT_MIXTO_MIN_MIXES : minMixes; + if(mixToWallet.getMixConfig() != null) { + startIndex = Math.max(startIndex, mixToWallet.getMixConfig().getReceiveIndex()); + } + IPostmixHandler postmixHandler = new SparrowPostmixHandler(whirlpoolWalletService, mixToWallet, KeyPurpose.RECEIVE, startIndex); ExternalDestination externalDestination = new ExternalDestination(postmixHandler, 0, startIndex, mixes, DEFAULT_MIXTO_RANDOM_FACTOR); config.setExternalDestination(externalDestination); diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowWalletStateSupplier.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowWalletStateSupplier.java index 8335cc78..13778a49 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowWalletStateSupplier.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowWalletStateSupplier.java @@ -71,6 +71,13 @@ public class SparrowWalletStateSupplier implements WalletStateSupplier { throw new IllegalStateException("Cannot find wallet for external destination " + externalDestination); } + //Ensure mix config is present to save indexes + MixConfig mixConfig = externalWallet.getMixConfig(); + if(mixConfig == null) { + mixConfig = new MixConfig(); + externalWallet.setMixConfig(mixConfig); + } + KeyPurpose keyPurpose = KeyPurpose.fromChildNumber(new ChildNumber(externalDestination.getChain())); WalletNode externalNode = externalWallet.getNode(keyPurpose); externalIndexHandler = new SparrowIndexHandler(externalWallet, externalNode, externalDestination.getStartIndex());