save mix to wallet index to improve handling of mix out failures

This commit is contained in:
Craig Raw 2023-11-15 10:20:58 +02:00
parent d128401a09
commit 1d560d6aa6
2 changed files with 11 additions and 0 deletions

View file

@ -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);

View file

@ -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());