From ecfe5d116f0f89cbd496c2b38a5a195495f042da Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 9 Feb 2024 12:37:22 +0100 Subject: [PATCH] ps fix --- .../Shared/Wabisabi/WabisabiWalletSend.cshtml | 2 +- .../WabisabiStoreController.cs | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiWalletSend.cshtml b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiWalletSend.cshtml index 3822836..93a9cb5 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiWalletSend.cshtml +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiWalletSend.cshtml @@ -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(); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs index 54abea2..a6075fb 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs @@ -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()), (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()); }