fix comment and parameter order
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/ChangeAvoidanceSuggestionViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/ChangeAvoidanceSuggestionViewModel.cs
@@ -51,7 +51,7 @@ public partial class ChangeAvoidanceSuggestionViewModel : SuggestionViewModel
{
Task<ChangeAvoidanceSuggestionViewModel?> moreSuggestionTask = Task.Run(() =>
{
- if (ChangelessTransactionCoinSelector.TryGetCoins(transactionInfo.Coins, transactionInfo.FeeRate, new TxOut(transactionInfo.Amount, destination), SuggestionType.More, out IEnumerable<SmartCoin>? selection, cancellationToken))
+ if (ChangelessTransactionCoinSelector.TryGetCoins(SuggestionType.More, transactionInfo.Coins, transactionInfo.FeeRate, new TxOut(transactionInfo.Amount, destination), out IEnumerable<SmartCoin>? selection, cancellationToken))
{
BuildTransactionResult transaction = TransactionHelpers.BuildChangelessTransaction(
wallet,
@@ -73,7 +73,7 @@ public partial class ChangeAvoidanceSuggestionViewModel : SuggestionViewModel
Task<ChangeAvoidanceSuggestionViewModel?> lesserSuggestionTask = Task.Run(() =>
{
- if (ChangelessTransactionCoinSelector.TryGetCoins(transactionInfo.Coins, transactionInfo.FeeRate, new TxOut(transactionInfo.Amount, destination), SuggestionType.Less, out IEnumerable<SmartCoin>? selection, cancellationToken))
+ if (ChangelessTransactionCoinSelector.TryGetCoins(SuggestionType.Less, transactionInfo.Coins, transactionInfo.FeeRate, new TxOut(transactionInfo.Amount, destination), out IEnumerable<SmartCoin>? selection, cancellationToken))
{
BuildTransactionResult transaction = TransactionHelpers.BuildChangelessTransaction(
wallet,

MODIFY
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/BranchAndBoundTests.cs
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/BranchAndBoundTests.cs
@@ -20,7 +20,7 @@ public class BranchAndBoundTests
long target = 27; // Target that we cannot get as a sum of input values.
BranchAndBound algorithm = new();
- CheapestSelectionStrategy strategy = new(target, SuggestionType.More, inputValues, inputCosts);
+ CheapestSelectionStrategy strategy = new(SuggestionType.More, target, inputValues, inputCosts);
bool wasSuccessful = algorithm.TryGetMatch(strategy, out List<long>? selectedCoins);
Assert.False(wasSuccessful);
@@ -39,7 +39,7 @@ public class BranchAndBoundTests
long target = 27;
BranchAndBound algorithm = new();
- CheapestSelectionStrategy strategy = new(target, SuggestionType.More, inputValues, inputCosts);
+ CheapestSelectionStrategy strategy = new(SuggestionType.More, target, inputValues, inputCosts);
bool wasSuccessful = algorithm.TryGetMatch(strategy, out List<long>? selectedCoins);
Assert.False(wasSuccessful);
@@ -62,7 +62,7 @@ public class BranchAndBoundTests
long target = 27; // Target that we cannot get as a sum of input values.
BranchAndBound algorithm = new();
- CheapestSelectionStrategy strategy = new(target, SuggestionType.More, inputValues, inputCosts);
+ CheapestSelectionStrategy strategy = new(SuggestionType.More, target, inputValues, inputCosts);
bool wasSuccessful = algorithm.TryGetMatch(strategy, out List<long>? selectedCoins);
Assert.False(wasSuccessful);
@@ -85,7 +85,7 @@ public class BranchAndBoundTests
long target = 19;
BranchAndBound algorithm = new();
- CheapestSelectionStrategy strategy = new(target, SuggestionType.Less, inputValues, inputCosts);
+ CheapestSelectionStrategy strategy = new(SuggestionType.Less, target, inputValues, inputCosts);
bool wasSuccessful = algorithm.TryGetMatch(strategy, out List<long>? selectedCoins);
Assert.False(wasSuccessful);

MODIFY
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/ChangelessTransactionCoinSelectorTests.cs
WalletWasabi.Tests/UnitTests/Blockchain/TransactionBuilding/ChangelessTransactionCoinSelectorTests.cs
@@ -31,7 +31,7 @@ public class ChangelessTransactionCoinSelectorTests
var txOut = new TxOut(target, BitcoinFactory.CreateBitcoinAddress(Network.TestNet, key));
- bool found = ChangelessTransactionCoinSelector.TryGetCoins(coins, new FeeRate(satoshiPerByte: 4), txOut, SuggestionType.More, out IEnumerable<SmartCoin>? selectedCoins);
+ bool found = ChangelessTransactionCoinSelector.TryGetCoins(SuggestionType.More, coins, new FeeRate(satoshiPerByte: 4), txOut, out IEnumerable<SmartCoin>? selectedCoins);
Assert.True(found);
long[] solution = selectedCoins!.Select(x => x.Amount.Satoshi).ToArray();
@@ -49,7 +49,7 @@ public class ChangelessTransactionCoinSelectorTests
var txOut = new TxOut(target, BitcoinFactory.CreateBitcoinAddress(Network.TestNet, key));
- bool found = ChangelessTransactionCoinSelector.TryGetCoins(coins, new FeeRate(satoshiPerByte: 4), txOut, SuggestionType.Less, out IEnumerable<SmartCoin>? selectedCoins);
+ bool found = ChangelessTransactionCoinSelector.TryGetCoins(SuggestionType.Less, coins, new FeeRate(satoshiPerByte: 4), txOut, out IEnumerable<SmartCoin>? selectedCoins);
//Assert.True(found);
long[] solution = selectedCoins!.Select(x => x.Amount.Satoshi).ToArray();
@@ -69,7 +69,7 @@ public class ChangelessTransactionCoinSelectorTests
var txOut = new TxOut(target, BitcoinFactory.CreateBitcoinAddress(Network.TestNet, key));
- bool found = ChangelessTransactionCoinSelector.TryGetCoins(coins, new FeeRate(satoshiPerByte: 4), txOut, SuggestionType.More, out IEnumerable<SmartCoin>? selectedCoins);
+ bool found = ChangelessTransactionCoinSelector.TryGetCoins(SuggestionType.More, coins, new FeeRate(satoshiPerByte: 4), txOut, out IEnumerable<SmartCoin>? selectedCoins);
Assert.False(found);
}

MODIFY
WalletWasabi/Blockchain/TransactionBuilding/BnB/CheapestSelectionStrategy.cs
WalletWasabi/Blockchain/TransactionBuilding/BnB/CheapestSelectionStrategy.cs
@@ -15,7 +15,7 @@ public class CheapestSelectionStrategy
/// <param name="target">Value in satoshis.</param>
/// <param name="inputCosts">Costs of spending coins in satoshis.</param>
- public CheapestSelectionStrategy(long target, SuggestionType suggestionType, long[] inputValues, long[] inputCosts)
+ public CheapestSelectionStrategy(SuggestionType suggestionType, long target, long[] inputValues, long[] inputCosts)
{
InputCosts = inputCosts;
InputValues = inputValues;
@@ -36,7 +36,7 @@ public class CheapestSelectionStrategy
/// <summary>Gives lowest found value selection whose sum is larger than or equal to <see cref="Target"/>.</summary>
public long[]? GetBestSelectionFound() => _bestSelectionSoFar?.Where(x => x > 0).ToArray();
- // <summary>The type of suggestion we want. (Less/More)</summary>
+ // <summary>Suggestion type affecting whether selection sums to a larger or a smaller sum than the target.</summary>
private SuggestionType SuggestionType { get; }
/// <summary>

MODIFY
WalletWasabi/Blockchain/TransactionBuilding/ChangelessTransactionCoinSelector.cs
WalletWasabi/Blockchain/TransactionBuilding/ChangelessTransactionCoinSelector.cs
@@ -22,7 +22,7 @@ public static class ChangelessTransactionCoinSelector
/// <param name="txOut">Amount the user wants to pay + the type of the output address</param>
/// <returns><c>true</c> if a solution was found, <c>false</c> otherwise.</returns>
/// <remarks>The implementation gives only the guarantee that user can pay at most 25% more than <paramref name="txOut.Value"/>.</remarks>
- public static bool TryGetCoins(IEnumerable<SmartCoin> availableCoins, FeeRate feeRate, TxOut txOut, SuggestionType suggestionType, [NotNullWhen(true)] out IEnumerable<SmartCoin>? selectedCoins, CancellationToken cancellationToken = default)
+ public static bool TryGetCoins(SuggestionType suggestionType, IEnumerable<SmartCoin> availableCoins, FeeRate feeRate, TxOut txOut, [NotNullWhen(true)] out IEnumerable<SmartCoin>? selectedCoins, CancellationToken cancellationToken = default)
{
selectedCoins = null;
@@ -41,7 +41,7 @@ public static class ChangelessTransactionCoinSelector
long[] inputValues = inputEffectiveValues.Values.ToArray();
BranchAndBound branchAndBound = new();
- CheapestSelectionStrategy strategy = new(target, suggestionType, inputValues, inputCosts);
+ CheapestSelectionStrategy strategy = new(suggestionType, target, inputValues, inputCosts);
var foundExactMatch = branchAndBound.TryGetMatch(strategy, out List<long>? solution, cancellationToken);

fix comment and parameter order