Fix coin may be null
MODIFY
WalletWasabi/Blockchain/TransactionOutputs/CoinsRegistry.cs
WalletWasabi/Blockchain/TransactionOutputs/CoinsRegistry.cs
@@ -71,7 +71,7 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
}
}
- public SmartCoin GetByOutPoint(OutPoint outpoint) => AsCoinsView().GetByOutPoint(outpoint);
+ public bool TryGetByOutPoint(OutPoint outpoint, [NotNullWhen(true)] out SmartCoin? coin) => AsCoinsView().TryGetByOutPoint(outpoint, out coin);
public bool TryAdd(SmartCoin coin)
{

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/CoinsView.cs
WalletWasabi/Blockchain/TransactionOutputs/CoinsView.cs
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using NBitcoin;
using WalletWasabi.Helpers;
@@ -70,7 +71,18 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
return new CoinsView(smartCoins);
}
- public SmartCoin GetByOutPoint(OutPoint outpoint) => Coins.FirstOrDefault(x => x.OutPoint == outpoint);
+ public bool TryGetByOutPoint(OutPoint outpoint, [NotNullWhen(true)] out SmartCoin? coin)
+ {
+ coin = Coins.FirstOrDefault(x => x.OutPoint == outpoint);
+ if (coin is null)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
public Money TotalAmount() => Coins.Sum(x => x.Amount);

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/ICoinsView.cs
WalletWasabi/Blockchain/TransactionOutputs/ICoinsView.cs
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using NBitcoin;
using WalletWasabi.Models;
@@ -37,6 +38,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
ICoinsView Unspent();
- SmartCoin GetByOutPoint(OutPoint outpoint);
+ bool TryGetByOutPoint(OutPoint outpoint, [NotNullWhen(true)] out SmartCoin? coin);
}
}

MODIFY
WalletWasabi/Blockchain/TransactionProcessing/TransactionProcessor.cs
WalletWasabi/Blockchain/TransactionProcessing/TransactionProcessor.cs
@@ -247,8 +247,7 @@ namespace WalletWasabi.Blockchain.TransactionProcessing
{
if (newCoin.Height != Height.Mempool) // Update the height of this old coin we already had.
{
- SmartCoin oldCoin = Coins.AsAllCoinsView().GetByOutPoint(new OutPoint(txId, i));
- if (oldCoin is { }) // Just to be sure, it is a concurrent collection.
+ if (Coins.AsAllCoinsView().TryGetByOutPoint(new OutPoint(txId, i), out var oldCoin)) // Just to be sure, it is a concurrent collection.
{
result.NewlyConfirmedReceivedCoins.Add(newCoin);
oldCoin.Height = newCoin.Height;

MODIFY
WalletWasabi/Wallets/WalletManager.cs
WalletWasabi/Wallets/WalletManager.cs
@@ -352,9 +352,11 @@ namespace WalletWasabi.Wallets
var res = new List<SmartCoin>();
foreach (var wallet in Wallets.Where(x => x.State == WalletState.Started))
{
- SmartCoin coin = wallet.Coins.GetByOutPoint(input);
+ if (wallet.Coins.TryGetByOutPoint(input, out var coin))
+ {
res.Add(coin);
}
+ }
return res;
}

Fix coin may be null