Using FirstOrDefault in place of SingleOrDefault on unique collections
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -145,7 +145,7 @@ namespace WalletWasabi.Backend.Controllers
}
}
- var bannedElem = Coordinator.UtxoReferee.BannedUtxos.SingleOrDefault(x => x.Key == inputProof.Input);
+ var bannedElem = Coordinator.UtxoReferee.BannedUtxos.FirstOrDefault(x => x.Key == inputProof.Input);
if (bannedElem.Key != default)
{
int maxBan = (int)TimeSpan.FromDays(30).TotalMinutes;

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -2664,7 +2664,7 @@ namespace WalletWasabi.Tests
}
var times = 0;
- while (wallet.Coins.Where(x => x.Label == "ZeroLink Change" && x.Unspent).SingleOrDefault() == null)
+ while (wallet.Coins.Where(x => x.Label == "ZeroLink Change" && x.Unspent).FirstOrDefault() == null)
{
await Task.Delay(1000);
times++;

MODIFY
WalletWasabi/Services/CcjCoordinator.cs
WalletWasabi/Services/CcjCoordinator.cs
@@ -129,7 +129,7 @@ namespace WalletWasabi.Services
{
OutPoint prevOut = input.PrevOut;
- var found = UtxoReferee.BannedUtxos.SingleOrDefault(x => x.Key == prevOut);
+ var found = UtxoReferee.BannedUtxos.FirstOrDefault(x => x.Key == prevOut);
if (found.Key == default) continue; // if coin is not banned
if (!AnyRunningRoundContainsInput(prevOut, out _))

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -104,7 +104,7 @@ namespace WalletWasabi.Services
using (HandleFiltersLock.Lock())
using (WalletBlocksLock.Lock())
{
- var elem = WalletBlocks.SingleOrDefault(x => x.Value == invalidBlockHash);
+ var elem = WalletBlocks.FirstOrDefault(x => x.Value == invalidBlockHash);
await DeleteBlockAsync(invalidBlockHash);
WalletBlocks.RemoveByValue(invalidBlockHash);
ProcessedBlocks.Remove(invalidBlockHash);
@@ -288,7 +288,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.
- var foundCoin = Coins.SingleOrDefault(x => x.TransactionId == tx.GetHash() && x.Index == i);
+ var foundCoin = Coins.FirstOrDefault(x => x.TransactionId == tx.GetHash() && x.Index == i);
if (foundCoin != default)
{
// If tx height is mempool then don't, otherwise update the height.
@@ -374,7 +374,7 @@ namespace WalletWasabi.Services
{
var input = tx.Transaction.Inputs[i];
- var foundCoin = Coins.SingleOrDefault(x => x.TransactionId == input.PrevOut.Hash && x.Index == input.PrevOut.N);
+ var foundCoin = Coins.FirstOrDefault(x => x.TransactionId == input.PrevOut.Hash && x.Index == input.PrevOut.N);
if (foundCoin != null)
{
foundCoin.SpenderTransactionId = tx.GetHash();

Using FirstOrDefault in place of SingleOrDefault on unique collections