Finish generate address backend
MODIFY
WalletWasabi.Gui/Tabs/WalletManager/AddressViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/AddressViewModel.cs
@@ -4,16 +4,15 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
{
public class AddressViewModel
{
- private HdPubKey _model;
+ public HdPubKey Model { get; }
public AddressViewModel(HdPubKey model)
{
- _model = model;
- Address = _model.GetP2wpkhAddress(Global.Network).ToString();
+ Model = model;
}
- public string Label => _model.Label;
+ public string Label => Model.Label;
- public string Address { get; }
+ public string Address => Model.GetP2wpkhAddress(Global.Network).ToString();
}
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/ReceiveTabViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/ReceiveTabViewModel.cs
@@ -21,9 +21,14 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
GenerateCommand = ReactiveCommand.Create(() =>
{
- var newKey = Global.WalletService.KeyManager.GenerateNewKey(Label, KeyState.Clean, false);
+ HdPubKey newKey = Global.WalletService.GetReceiveKey(Label);
- Addresses.Add(new AddressViewModel(newKey));
+ AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
+ if (found != default)
+ {
+ Addresses.Remove(found);
+ }
+ Addresses.Insert(0, new AddressViewModel(newKey));
Label = null;
}, this.WhenAnyValue(x => x.Label, label => !string.IsNullOrWhiteSpace(label)));
@@ -35,7 +40,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
var keys = Global.WalletService.KeyManager.GetKeys(KeyState.Clean, false);
- foreach (var key in keys)
+ foreach (HdPubKey key in keys.Where(x => !string.IsNullOrWhiteSpace(x.Label)).Reverse())
{
_addresses.Add(new AddressViewModel(key));
}

MODIFY
WalletWasabi/KeyManagement/HdPubKey.cs
WalletWasabi/KeyManagement/HdPubKey.cs
@@ -116,6 +116,8 @@ namespace WalletWasabi.KeyManagement
return (bool)_isInternal;
}
+ public bool HasLabel() => !string.IsNullOrEmpty(Label);
+
#region Equality
// speedup

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -204,7 +204,10 @@ namespace WalletWasabi.Services
// Make sure there's always 21 clean keys generated and indexed.
AssertCleanKeysIndexed(21, false);
- var ret = KeyManager.GetKeys(KeyState.Clean, false).RandomElement();
+ IEnumerable<HdPubKey> keys = KeyManager.GetKeys(KeyState.Clean, false);
+
+ var foundLabelless = keys.FirstOrDefault(x => !x.HasLabel()); // return the first labelless
+ HdPubKey ret = foundLabelless ?? KeyManager.GetKeys(KeyState.Clean, false).First(); // return the first, because that's the oldest
ret.SetLabel(label, KeyManager);

Finish generate address backend