Skip to content
Permalink
Browse files

Optimize GetNonSpecialLabels

  • Loading branch information...
nopara73 committed Nov 13, 2018
1 parent bd6a2c7 commit 99609972baef38e577b699c92b308e0df0b55f9b
@@ -30,7 +30,7 @@ public ReceiveTabViewModel(WalletViewModel walletViewModel)
: base("Receive", walletViewModel)
{
_addresses = new ObservableCollection<AddressViewModel>();
Label = String.Empty;
Label = "";

Observable.FromEventPattern(Global.WalletService.Coins, nameof(Global.WalletService.Coins.HashSetChanged))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -962,7 +962,7 @@ private void WalletTestsAsync_MemPoolService_TransactionReceived(object sender,
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 @@ private void WalletTestsAsync_MemPoolService_TransactionReceived(object sender,

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

@@ -53,5 +53,8 @@ public static BitcoinWitPubKeyAddress GetCoordinatorAddress(Network network)
// else regtest
return RegTestCoordinatorAddress;
}

public const string ChangeOfSpecialLabelStart = "change of (";
public const string ChangeOfSpecialLabelEnd = ")";
}
}
@@ -883,7 +883,7 @@ public Operation(Script script, Money amount, string label)
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 @@ public async Task SendTransactionAsync(SmartTransaction transaction)

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

0 comments on commit 9960997

Please sign in to comment.
You can’t perform that action at this time.