Fix receive ordering
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return;
}
- HdPubKey newKey = Global.WalletService.GetReceiveKey(Label);
+ HdPubKey newKey = Global.WalletService.GetReceiveKey(Label, Addresses.Select(x => x.Model).Take(7)); // Never touch the first 7 keys.
AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
if (found != default)

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -242,7 +242,7 @@ namespace WalletWasabi.Services
}
}
- public HdPubKey GetReceiveKey(string label)
+ public HdPubKey GetReceiveKey(string label, IEnumerable<HdPubKey> dontTouch = null)
{
label = Guard.Correct(label);
@@ -250,9 +250,17 @@ namespace WalletWasabi.Services
AssertCleanKeysIndexed(21, false);
IEnumerable<HdPubKey> keys = KeyManager.GetKeys(KeyState.Clean, isInternal: false);
+ if (dontTouch != null)
+ {
+ keys = keys.Except(dontTouch);
+ if (!keys.Any())
+ {
+ throw new InvalidOperationException($"{nameof(dontTouch)} covers all the possible keys.");
+ }
+ }
var foundLabelless = keys.FirstOrDefault(x => !x.HasLabel()); // return the first labelless
- HdPubKey ret = foundLabelless ?? KeyManager.GetKeys(KeyState.Clean, isInternal: false).First(); // return the first, because that's the oldest
+ HdPubKey ret = foundLabelless ?? keys.RandomElement(); // return the first, because that's the oldest
ret.SetLabel(label, KeyManager);

Fix receive ordering