This commit is contained in:
Kukks
2024-02-09 12:37:22 +01:00
parent 3cda852e92
commit ecfe5d116f
2 changed files with 24 additions and 4 deletions

View File

@@ -64,7 +64,7 @@
labels.push(value.value);
});
let url =@Safe.Json(@Url.Action("ComputeCoinSelection", "WabisabiStore", new { storeId }));
url += "?amount=${amount}";
url += `?amount=${amount}`;
url += labels.length >0? "&" + labels.map(x => "labels=" + encodeURIComponent(x)).join("&"): "";
const response = await fetch(url);
const coins = await response.json();

View File

@@ -426,9 +426,6 @@ namespace BTCPayServer.Plugins.Wabisabi
if (directLinkCoins.TotalAmount().ToDecimal(MoneyUnit.BTC) > amount)
{
//select enough to be able to spend the amount requested
var result = directLinkCoins.ToShuffled(new InsecureRandom()).Aggregate(
(Money.Zero, new List<SmartCoin>()), (acc, coin) =>
@@ -448,9 +445,31 @@ namespace BTCPayServer.Plugins.Wabisabi
}
// 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());
var defaultCoinSelector = new DefaultCoinSelector();
var defaultSelection =
(defaultCoinSelector.Select(coins.Select(coin => coin.Coin).ToArray(),
@@ -458,6 +477,7 @@ namespace BTCPayServer.Plugins.Wabisabi
.ToArray();
var selector = new SmartCoinSelector(remainingCoins);
selectedCoins.AddRange(selector.Select(defaultSelection, new Money(remaining, MoneyUnit.BTC)).ToList());
return Ok(selectedCoins.Select(coin => coin.Outpoint.ToString()).ToArray());
}