TransactionFactory uses ICoinsView
MODIFY
WalletWasabi.Tests/UnitTests/TransactionFactoryTests.cs
WalletWasabi.Tests/UnitTests/TransactionFactoryTests.cs
@@ -429,8 +429,9 @@ namespace WalletWasabi.Tests.UnitTests
keyManager.AssertCleanKeysIndexed();
var keys = keyManager.GetKeys().Take(10).ToArray();
- var scoins = coins.Select(x => Coin(x.Label, keys[x.KeyIndex], x.Amount, x.Confirmed, x.AnonymitySet)).ToList();
- return new TransactionFactory(Network.Main, keyManager, scoins, password, allowUnconfirmed);
+ var scoins = coins.Select(x => Coin(x.Label, keys[x.KeyIndex], x.Amount, x.Confirmed, x.AnonymitySet));
+ var coinsView = new CoinsView(scoins.ToArray());
+ return new TransactionFactory(Network.Main, keyManager, coinsView, password, allowUnconfirmed);
}
private static (string, KeyManager) DefaultKeyManager()

MODIFY
WalletWasabi/Services/TransactionFactory.cs
WalletWasabi/Services/TransactionFactory.cs
@@ -16,12 +16,12 @@ namespace WalletWasabi.Services
{
public Network Network { get; }
public KeyManager KeyManager { get; }
- public IEnumerable<SmartCoin> Coins { get; }
+ public ICoinsView Coins { get; }
public string Password { get; }
public bool AllowUnconfirmed { get; }
/// <param name="allowUnconfirmed">Allow to spend unconfirmed transactions, if necessary.</param>
- public TransactionFactory(Network network, KeyManager keyManager, IEnumerable<SmartCoin> coins, string password = "", bool allowUnconfirmed = false)
+ public TransactionFactory(Network network, KeyManager keyManager, ICoinsView coins, string password = "", bool allowUnconfirmed = false)
{
Network = network;
KeyManager = keyManager;
@@ -56,7 +56,10 @@ namespace WalletWasabi.Services
}
// Get allowed coins to spend.
- List<SmartCoin> allowedSmartCoinInputs; // Inputs that can be used to build the transaction.
+ var availableCoinsView = Coins.Available();
+ List<SmartCoin> allowedSmartCoinInputs = AllowUnconfirmed // Inputs that can be used to build the transaction.
+ ? availableCoinsView.ToList()
+ : availableCoinsView.Confirmed().ToList();
if (allowedInputs != null) // If allowedInputs are specified then select the coins from them.
{
if (!allowedInputs.Any())
@@ -64,16 +67,16 @@ namespace WalletWasabi.Services
throw new ArgumentException($"{nameof(allowedInputs)} is not null, but empty.");
}
- allowedSmartCoinInputs = AllowUnconfirmed
- ? Coins.Where(x => !x.Unavailable && allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index)).ToList()
- : Coins.Where(x => !x.Unavailable && x.Confirmed && allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index)).ToList();
+ allowedSmartCoinInputs = allowedSmartCoinInputs
+ .Where(x => allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index))
+ .ToList();
// Add those that have the same script, because common ownership is already exposed.
// But only if the user didn't click the "max" button. In this case he'd send more money than what he'd think.
if (payments.ChangeStrategy != ChangeStrategy.AllRemainingCustom)
{
var allScripts = allowedSmartCoinInputs.Select(x => x.ScriptPubKey).ToHashSet();
- foreach (var coin in Coins.Where(x => !x.Unavailable && !allowedSmartCoinInputs.Any(y => x.TransactionId == y.TransactionId && x.Index == y.Index)))
+ foreach (var coin in availableCoinsView.Where(x => !allowedSmartCoinInputs.Any(y => x.TransactionId == y.TransactionId && x.Index == y.Index)))
{
if (!(AllowUnconfirmed || coin.Confirmed))
{
@@ -87,10 +90,6 @@ namespace WalletWasabi.Services
}
}
}
- else
- {
- allowedSmartCoinInputs = AllowUnconfirmed ? Coins.Where(x => !x.Unavailable).ToList() : Coins.Where(x => !x.Unavailable && x.Confirmed).ToList();
- }
// Get and calculate fee
Logger.LogInfo("Calculating dynamic transaction fee...");

TransactionFactory uses ICoinsView