ws coin select

This commit is contained in:
Kukks
2024-03-28 05:52:20 +01:00
parent 2684c3d3ea
commit 930b3e568f
2 changed files with 21 additions and 21 deletions

View File

@@ -13,7 +13,7 @@
<PropertyGroup>
<Product>Coinjoin</Product>
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
<Version>1.0.74</Version>
<Version>1.0.75</Version>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

View File

@@ -446,29 +446,29 @@ namespace BTCPayServer.Plugins.Wabisabi
}
// coinSelect:
coinSelect:
var selectedCoinSum = selectedCoins.Sum(coin => ((Money)coin.Amount).ToDecimal(MoneyUnit.BTC));
var remaining = amount - selectedCoinSum;
var remainingCoins = coins.FilterBy(coin => !selectedCoins.Contains(coin.Coin)).Available().ToList();
// if (remaining > 0 && remainingCoins.Any())
// {
// //try to select the closest coin to the remaining amount while also prioritizing privacy
// //so filter rby the highest anonymity set first and then by closest amount
// var closestCoin = remainingCoins
// .OrderByDescending(coin => coin.AnonymitySet)
// .ThenBy(coin => Math.Abs(coin.Amount.ToDecimal(MoneyUnit.BTC) - remaining))
// .FirstOrDefault();
// if (closestCoin is not null)
// {
// selectedCoins.Add(closestCoin.Coin);
// remainingCoins.Remove(closestCoin);
//
// goto coinSelect;
// }
//
// }
//
// return Ok(selectedCoins.Select(coin => coin.Outpoint.ToString()).ToArray());
if (remaining > 0 && remainingCoins.Any())
{
//try to select the closest coin to the remaining amount while also prioritizing privacy
//so filter rby the highest anonymity set first and then by closest amount
var closestCoin = remainingCoins
.OrderByDescending(coin => coin.AnonymitySet)
.ThenBy(coin => Math.Abs(coin.Amount.ToDecimal(MoneyUnit.BTC) - remaining))
.FirstOrDefault();
if (closestCoin is not null)
{
selectedCoins.Add(closestCoin.Coin);
remainingCoins.Remove(closestCoin);
goto coinSelect;
}
}
return Ok(selectedCoins.Select(coin => coin.Outpoint.ToString()).ToArray());
var defaultCoinSelector = new DefaultCoinSelector();
var defaultSelection =