Optimize && condition performances
MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -218,7 +218,7 @@ namespace WalletWasabi.KeyManagement
{
return HdPubKeys;
}
- if (!(keyState is null) && isInternal is null)
+ if (isInternal is null && !(keyState is null))
{
return HdPubKeys.Where(x => x.KeyState == keyState);
}
@@ -226,7 +226,7 @@ namespace WalletWasabi.KeyManagement
{
return HdPubKeys.Where(x => x.IsInternal() == isInternal);
}
- return HdPubKeys.Where(x => x.KeyState == keyState && x.IsInternal() == isInternal);
+ return HdPubKeys.Where(x => x.IsInternal() == isInternal && x.KeyState == keyState);
}
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -414,7 +414,7 @@ namespace WalletWasabi.Services
for (var i = 0; i < tx.Transaction.Outputs.Count; i++)
{
// If we already had it, just update the height. Maybe got from mempool to block or reorged.
- SmartCoin foundCoin = Coins.FirstOrDefault(x => x.Index == i && x.TransactionId == txId);
+ SmartCoin foundCoin = Coins.FirstOrDefault(x => x.TransactionId == txId && x.Index == i);
if (foundCoin != default)
{
// If tx height is mempool then don't, otherwise update the height.
@@ -449,7 +449,7 @@ namespace WalletWasabi.Services
if (tx.Height == Height.MemPool)
{
// if all double spent coins are mempool and RBF
- if (doubleSpends.All(x => x.Height == Height.MemPool && x.RBF))
+ if (doubleSpends.All(x => x.RBF && x.Height == Height.MemPool))
{
// remove double spent coins(if other coin spends it, remove that too and so on) // will add later if they came to our keys
foreach (var doubleSpentCoin in doubleSpends)
@@ -486,7 +486,7 @@ namespace WalletWasabi.Services
if (foundKey != default)
{
foundKey.SetKeyState(KeyState.Used, KeyManager);
- List<SmartCoin> spentOwnCoins = Coins.Where(x => tx.Transaction.Inputs.Any(y => y.PrevOut.N == x.Index && y.PrevOut.Hash == x.TransactionId)).ToList();
+ List<SmartCoin> spentOwnCoins = Coins.Where(x => tx.Transaction.Inputs.Any(y => y.PrevOut.Hash == x.TransactionId && y.PrevOut.N == x.Index)).ToList();
var mixin = tx.Transaction.GetMixin(i);
if (spentOwnCoins.Count != 0)
{
@@ -497,7 +497,7 @@ namespace WalletWasabi.Services
Coins.TryAdd(coin);
TransactionCache.Add(tx);
CoinReceived?.Invoke(this, coin);
- if (coin.Unspent && coin.Label == "ZeroLink Change" && !(ChaumianClient.OnePiece is null))
+ if (coin.Unspent && !(ChaumianClient.OnePiece is null) && coin.Label == "ZeroLink Change")
{
Task.Run(async () =>
{
@@ -536,7 +536,7 @@ namespace WalletWasabi.Services
{
var input = tx.Transaction.Inputs[i];
- var foundCoin = Coins.FirstOrDefault(x => x.Index == input.PrevOut.N && x.TransactionId == input.PrevOut.Hash);
+ var foundCoin = Coins.FirstOrDefault(x => x.TransactionId == input.PrevOut.Hash && x.Index == input.PrevOut.N);
if (!(foundCoin is null))
{
foundCoin.SpenderTransactionId = txId;

Optimize && condition performances