Optimize GetNonSpecialLabels
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
@@ -30,7 +30,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
: base("Receive", walletViewModel)
{
_addresses = new ObservableCollection<AddressViewModel>();
- Label = String.Empty;
+ Label = "";
Observable.FromEventPattern(Global.WalletService.Coins, nameof(Global.WalletService.Coins.HashSetChanged))
.ObserveOn(RxApp.MainThreadScheduler)

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -962,7 +962,7 @@ namespace WalletWasabi.Tests
allowUnconfirmed: true);
Assert.Single(res.InnerWalletOutputs);
- Assert.Equal("change of (my label)", res.InnerWalletOutputs.Single().Label);
+ Assert.Equal($"{Helpers.Constants.ChangeOfSpecialLabelStart}my label{Helpers.Constants.ChangeOfSpecialLabelEnd}", res.InnerWalletOutputs.Single().Label);
amountToSend = wallet.Coins.Where(x => !x.SpentOrCoinJoinInProgress).Sum(x => x.Amount) / 3;
res = await wallet.BuildTransactionAsync(password, new[] {
@@ -973,20 +973,20 @@ namespace WalletWasabi.Tests
Assert.Single(res.InnerWalletOutputs);
Assert.Equal(2, res.OuterWalletOutputs.Count());
- Assert.Equal("change of (outgoing, outgoing2)", res.InnerWalletOutputs.Single().Label);
+ Assert.Equal($"{Helpers.Constants.ChangeOfSpecialLabelStart}outgoing, outgoing2{Helpers.Constants.ChangeOfSpecialLabelEnd}", res.InnerWalletOutputs.Single().Label);
await wallet.SendTransactionAsync(res.Transaction);
- Assert.Contains("change of (outgoing, outgoing2)", wallet.Coins.Where(x => x.Height == Height.MemPool).Select(x => x.Label));
- Assert.Contains("change of (outgoing, outgoing2)", keyManager.GetKeys().Select(x => x.Label));
+ Assert.Contains($"{Helpers.Constants.ChangeOfSpecialLabelStart}outgoing, outgoing2{Helpers.Constants.ChangeOfSpecialLabelEnd}", wallet.Coins.Where(x => x.Height == Height.MemPool).Select(x => x.Label));
+ Assert.Contains($"{Helpers.Constants.ChangeOfSpecialLabelStart}outgoing, outgoing2{Helpers.Constants.ChangeOfSpecialLabelEnd}", keyManager.GetKeys().Select(x => x.Label));
Interlocked.Exchange(ref _filtersProcessedByWalletCount, 0);
await rpc.GenerateAsync(1);
await WaitForFiltersToBeProcessedAsync(TimeSpan.FromSeconds(120), 1);
var bestHeight = wallet.IndexDownloader.BestKnownFilter.BlockHeight;
- Assert.Contains("change of (outgoing, outgoing2)", wallet.Coins.Where(x => x.Height == bestHeight).Select(x => x.Label));
- Assert.Contains("change of (outgoing, outgoing2)", keyManager.GetKeys().Select(x => x.Label));
+ Assert.Contains($"{Helpers.Constants.ChangeOfSpecialLabelStart}outgoing, outgoing2{Helpers.Constants.ChangeOfSpecialLabelEnd}", wallet.Coins.Where(x => x.Height == bestHeight).Select(x => x.Label));
+ Assert.Contains($"{Helpers.Constants.ChangeOfSpecialLabelStart}outgoing, outgoing2{Helpers.Constants.ChangeOfSpecialLabelEnd}", keyManager.GetKeys().Select(x => x.Label));
#endregion Labeling

MODIFY
WalletWasabi/Helpers/Constants.cs
WalletWasabi/Helpers/Constants.cs
@@ -53,5 +53,8 @@ namespace WalletWasabi.Helpers
// else regtest
return RegTestCoordinatorAddress;
}
+
+ public const string ChangeOfSpecialLabelStart = "change of (";
+ public const string ChangeOfSpecialLabelEnd = ")";
}
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -883,7 +883,7 @@ namespace WalletWasabi.Services
sb.Append(item.label ?? "?");
sb.Append(", ");
}
- var changeLabel = $"change of ({sb.ToString().TrimEnd(',', ' ')})";
+ var changeLabel = $"{Constants.ChangeOfSpecialLabelStart}{sb.ToString().TrimEnd(',', ' ')}{Constants.ChangeOfSpecialLabelEnd}";
if (customChange is null)
{
@@ -1040,7 +1040,10 @@ namespace WalletWasabi.Services
public IEnumerable<string> GetNonSpecialLabels()
{
- return Coins.Where(x => !x.Label.StartsWith("change of") && !x.Label.StartsWith("ZeroLink")).SelectMany(x => x.Label.Split(',').Select(y => y.Trim())).Distinct();
+ return Coins.Where(x => !x.Label.StartsWith("ZeroLink"))
+ .SelectMany(x => x.Label.Split(new string[] { Constants.ChangeOfSpecialLabelStart, Constants.ChangeOfSpecialLabelEnd, "(", "," }, StringSplitOptions.RemoveEmptyEntries))
+ .Select(x => x.Trim())
+ .Distinct();
}
#region IDisposable Support

Optimize GetNonSpecialLabels