Add GenerateWithEffectiveCost
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/AmountDecompositionTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/AmountDecompositionTests.cs
+using NBitcoin;
using System.Linq;
using WalletWasabi.WabiSabi.Models.Decomposition;
using Xunit;
@@ -9,8 +10,11 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Models
[Fact]
public void BaseDenomGeneratorTest()
{
- var denoms = BaseDenominationGenerator.Generate();
+ FeeRate feeRate = new(100m);
+ var denoms = BaseDenominationGenerator.GenerateWithEffectiveCost(feeRate);
Assert.Equal(157, denoms.Count());
+
+ // It should be ordered.
Assert.Equal(denoms.OrderBy(d => d), denoms);
}
}

MODIFY
WalletWasabi/WabiSabi/Models/Decomposition/BaseDenomGenerator.cs
WalletWasabi/WabiSabi/Models/Decomposition/BaseDenomGenerator.cs
@@ -2,19 +2,20 @@ using NBitcoin;
using System;
using System.Collections.Generic;
using System.Linq;
+using WalletWasabi.Helpers;
namespace WalletWasabi.WabiSabi.Models.Decomposition
{
public static class BaseDenominationGenerator
{
- private static Money MaxSats = Money.Satoshis(2099999997690000);
+ private static Money MaxSats = Money.Satoshis(Constants.MaximumNumberOfSatoshis);
private static IEnumerable<Money> Multiple(IEnumerable<long> coefficients, IEnumerable<long> values) =>
values.SelectMany(v => coefficients.Select(c => Money.Satoshis(c * v))).Where(x => x <= MaxSats);
- public static IEnumerable<Money> Generate()
+ private static IEnumerable<Money> Generate()
{
- var powersOfTwo = Enumerable.Range(0, 50).Select(x => (long)1 << x);
+ var powersOfTwo = Enumerable.Range(0, 50).Select(x => (long)1m << x);
var powersOfThree = Enumerable.Range(0, 32).Select(x => (long)Math.Pow(3, x));
var powersOfTen = Enumerable.Range(0, 16).Select(x => (long)Math.Pow(10, x));
@@ -27,5 +28,12 @@ namespace WalletWasabi.WabiSabi.Models.Decomposition
.Union(preferredValueSeries)
.OrderBy(v => v);
}
+
+ public static IEnumerable<Money> GenerateWithEffectiveCost(FeeRate feeRate)
+ {
+ var outputSize = Constants.OutputSizeInBytes;
+ var fee = feeRate.GetFee(outputSize);
+ return Generate().Select(m => m + fee);
+ }
}
}

Add GenerateWithEffectiveCost