diff --git a/BTCPayServerPlugins.sln.DotSettings.user b/BTCPayServerPlugins.sln.DotSettings.user index bfc1e32..0cc0f59 100644 --- a/BTCPayServerPlugins.sln.DotSettings.user +++ b/BTCPayServerPlugins.sln.DotSettings.user @@ -1,13 +1,13 @@  - ExplicitlyExcluded - ExplicitlyExcluded + ForceIncluded + ForceIncluded ExplicitlyExcluded ExplicitlyExcluded - ExplicitlyExcluded - ExplicitlyExcluded + ForceIncluded + ForceIncluded ExplicitlyExcluded ExplicitlyExcluded - ExplicitlyExcluded + ForceIncluded <SessionState ContinuousTestingMode="0" IsActive="True" Name="EnsureNewLightningInvoiceOnPartialPayment" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <TestAncestor> <TestId>xUnit::4146B6DF-7BEE-4BD0-B6B1-77E7630A1B81::net8.0::BTCPayServer.Tests.UnitTest1.EnsureNewLightningInvoiceOnPartialPayment</TestId> diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs index 857f4b9..41d21f3 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs @@ -134,11 +134,11 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector Dictionary idealMinimumPerType = new Dictionary() {{AnonsetType.Red, 1}, {AnonsetType.Orange, 1}, {AnonsetType.Green, 1}}; - var solution = await SelectCoinsInternal(utxoSelectionParameters, candidates, ineligibleCoins,payments, + var solution = await SelectCoinsInternal(utxoSelectionParameters, candidates,payments, Random.Shared.Next(20, 31), maxPerType, idealMinimumPerType, - consolidationMode, liquidityClue, secureRandom,mixReasons); + consolidationMode, liquidityClue, secureRandom); if (attemptingTobeParanoidWhenDoingPayments && !solution.HandledPayments.Any()) { @@ -192,7 +192,7 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector } } - if (mixReasons.Contains(IWallet.MixingReason.NotPrivate) && coins.All(coin => coin.SmartCoin.IsPrivate(_wallet.AnonScoreTarget))) + if (mixReasons.Contains(IWallet.MixingReason.NotPrivate) && coins.All(coin => coin.SmartCoin.IsPrivate(_wallet))) { remainingMixReasons.Remove(IWallet.MixingReason.NotPrivate); } @@ -266,25 +266,25 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector return remainingMixReasons.Any(); } - return (solution.Coins.ToImmutableList(), (IEnumerable coins) => AcceptableRegistered(coins) , AcceptableOutputs); + return (solution.Coins.ToImmutableList(), AcceptableRegistered , AcceptableOutputs); } private async Task SelectCoinsInternal(UtxoSelectionParameters utxoSelectionParameters, - IEnumerable coins, IEnumerable ineligibleCoins, + IEnumerable coins, IEnumerable pendingPayments, int maxCoins, Dictionary maxPerType, Dictionary idealMinimumPerType, - bool consolidationMode, Money liquidityClue, SecureRandom random, IWallet.MixingReason[] mixReason) + bool consolidationMode, Money liquidityClue, SecureRandom random) { // Sort the coins by their anon score and then by descending order their value, and then slightly randomize in 2 ways: //attempt to shift coins that comes from the same tx AND also attempt to shift coins based on percentage probability var remainingCoins = SlightlyShiftOrder(RandomizeCoins( - coins.OrderBy(coin => coin.CoinColor(_wallet.AnonScoreTarget)).ThenByDescending(x => + coins.OrderBy(coin => coin.CoinColor(_wallet)).ThenByDescending(x => x.EffectiveValue(utxoSelectionParameters.MiningFeeRate, utxoSelectionParameters.CoordinationFeeRate)) .ToList(), liquidityClue), 10); var remainingPendingPayments = new List(pendingPayments); - var solution = new SubsetSolution(remainingPendingPayments.Count, _wallet.AnonScoreTarget, + var solution = new SubsetSolution(remainingPendingPayments.Count, _wallet, utxoSelectionParameters); @@ -308,20 +308,20 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector coinColorCount.TryGetValue(coinColor.Key, out var currentCoinColorCount); if (currentCoinColorCount < coinColor.Value) { - predicate = coin1 => coin1.CoinColor(_wallet.AnonScoreTarget) == coinColor.Key; + predicate = coin1 => coin1.CoinColor(_wallet) == coinColor.Key; break; } } else { //if the ideal amount = 0, then we should de-prioritize. - predicate = coin1 => coin1.CoinColor(_wallet.AnonScoreTarget) != coinColor.Key; + predicate = coin1 => coin1.CoinColor(_wallet) != coinColor.Key; break; } } var coin = remainingCoins.FirstOrDefault(predicate) ?? remainingCoins.First(); - var color = coin.CoinColor(_wallet.AnonScoreTarget); + var color = coin.CoinColor(_wallet); // If the selected coins list is at its maximum size, break out of the loop if (solution.Coins.Count == maxCoins) { @@ -330,7 +330,7 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector remainingCoins.Remove(coin); if (maxPerType.TryGetValue(color, out var maxColor) && - solution.Coins.Count(coin1 => coin1.CoinColor(_wallet.AnonScoreTarget) == color) == maxColor) + solution.Coins.Count(coin1 => coin1.CoinColor(_wallet) == color) == maxColor) { continue; } @@ -436,7 +436,7 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector var currentCoin = remainingCoins.First(); remainingCoins.RemoveAt(0); var lastCoin = workingList.LastOrDefault(); - if (lastCoin is null || currentCoin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green || + if (lastCoin is null || currentCoin.CoinColor(_wallet) == AnonsetType.Green || !remainingCoins.Any() || (remainingCoins.Count == 1 && remainingCoins.First().TransactionId == currentCoin.TransactionId) || lastCoin.TransactionId != currentCoin.TransactionId || @@ -458,9 +458,9 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector public static class SmartCoinExtensions { - public static AnonsetType CoinColor(this SmartCoin coin, int anonsetTarget) + public static AnonsetType CoinColor(this SmartCoin coin, IWallet wallet) { - return coin.IsPrivate(anonsetTarget)? AnonsetType.Green: coin.IsSemiPrivate(anonsetTarget)? AnonsetType.Orange: AnonsetType.Red; + return coin.IsPrivate(wallet)? AnonsetType.Green: coin.IsSemiPrivate(wallet)? AnonsetType.Orange: AnonsetType.Red; } } @@ -475,11 +475,11 @@ public class SubsetSolution { private readonly UtxoSelectionParameters _utxoSelectionParameters; - public SubsetSolution(int totalPaymentsGross, int anonsetTarget, UtxoSelectionParameters utxoSelectionParameters) + public SubsetSolution(int totalPaymentsGross, IWallet wallet, UtxoSelectionParameters utxoSelectionParameters) { _utxoSelectionParameters = utxoSelectionParameters; TotalPaymentsGross = totalPaymentsGross; - AnonsetTarget = anonsetTarget; + Wallet = wallet; } public List Coins { get; set; } = new(); public List HandledPayments { get; set; } = new(); @@ -489,10 +489,10 @@ public class SubsetSolution .ToDecimal(MoneyUnit.BTC)); public Dictionary SortedCoins => - Coins.GroupBy(coin => coin.CoinColor(AnonsetTarget)).ToDictionary(coins => coins.Key, coins => coins.ToArray()); + Coins.GroupBy(coin => coin.CoinColor(Wallet)).ToDictionary(coins => coins.Key, coins => coins.ToArray()); public int TotalPaymentsGross { get; } - public int AnonsetTarget { get; } + public IWallet Wallet { get; } public decimal TotalPaymentCost => HandledPayments.Sum(payment => payment.ToTxOut().EffectiveCost(_utxoSelectionParameters.MiningFeeRate).ToDecimal(MoneyUnit.BTC)); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj index c4914af..dbc36d0 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj @@ -13,7 +13,7 @@ Coinjoin Allows you to integrate your btcpayserver store with coinjoins. - 1.0.72 + 1.0.73 true diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs index a612c7f..4ef09b6 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs @@ -27,6 +27,7 @@ using WalletWasabi.Blockchain.Keys; using WalletWasabi.Blockchain.TransactionOutputs; using WalletWasabi.Blockchain.Transactions; using WalletWasabi.Extensions; +using WalletWasabi.Helpers; using WalletWasabi.Models; using WalletWasabi.WabiSabi; using WalletWasabi.WabiSabi.Backend.Rounds; @@ -133,6 +134,9 @@ public class BTCPayWallet : IWallet, IDestinationProvider public const int HighAmountOfCoins = 30; public int ExplicitHighestFeeTarget => WabisabiStoreSettings.PlebMode? DefaultExplicitHighestFeeTarget: WabisabiStoreSettings.ExplicitHighestFeeTarget; public int LowFeeTarget => WabisabiStoreSettings.PlebMode? DefaultLowFeeTarget: WabisabiStoreSettings.LowFeeTarget; + + public bool ConsiderEntryProximity => WabisabiStoreSettings.PlebMode || WabisabiStoreSettings.ConsiderEntryProximity; + public bool RedCoinIsolation => !WabisabiStoreSettings.PlebMode &&WabisabiStoreSettings.RedCoinIsolation; public bool BatchPayments => WabisabiStoreSettings.PlebMode || WabisabiStoreSettings.BatchPayments; public long? MinimumDenominationAmount => WabisabiStoreSettings.PlebMode? 10000 : WabisabiStoreSettings.MinimumDenominationAmount; @@ -213,8 +217,8 @@ public class BTCPayWallet : IWallet, IDestinationProvider public double GetPrivacyPercentage(CoinsView coins, int privateThreshold) { - var privateAmount = coins.FilterBy(x => x.HdPubKey.AnonymitySet >= privateThreshold).TotalAmount(); - var normalAmount = coins.FilterBy(x => x.HdPubKey.AnonymitySet < privateThreshold).TotalAmount(); + var privateAmount = coins.FilterBy(x => x.IsPrivate(this)).TotalAmount(); + var normalAmount = coins.FilterBy(x => !x.IsPrivate(this)).TotalAmount(); var privateDecimalAmount = privateAmount.ToDecimal(MoneyUnit.BTC); var normalDecimalAmount = normalAmount.ToDecimal(MoneyUnit.BTC); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml index 147ca71..56dea43 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml @@ -73,7 +73,7 @@ { value = coin.Amount.ToDecimal(MoneyUnit.BTC), score = coin.AnonymitySet, - isPrivate = coin.CoinColor(wallet.AnonScoreTarget) == AnonsetType.Green, + isPrivate = coin.CoinColor(wallet) == AnonsetType.Green, confirmed = coin.Confirmed, id = coin.Outpoint.ToString(), coinjoinInProgress = coin.CoinJoinInProgress diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml index bd0b7a5..ee94fc3 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml @@ -17,8 +17,8 @@ @inject BTCPayNetworkProvider BtcPayNetworkProvider @inject BTCPayServerOptions BtcPayServerOptions @{ - var liteMode = Context.Items.TryGetValue("cjlite" , out _); - + var liteMode = Context.Items.TryGetValue("cjlite", out _); + var storeId = _scopeProvider.GetCurrentStoreId(); ViewData.SetActivePage("CoinjoinSettings", "Coinjoin", "Coinjoin settings", storeId); var userid = Context.User.Claims.Single(claim => claim.Type == ClaimTypes.NameIdentifier).Value; @@ -48,19 +48,19 @@
- @@ -75,14 +75,13 @@ } var wallet = await WalletProvider.GetWalletAsync(storeId); - if (wallet is BTCPayWallet && !((BTCPayKeyChain) wallet.KeyChain).KeysAvailable) - { - - } - + if (wallet is BTCPayWallet && !((BTCPayKeyChain) wallet.KeyChain).KeysAvailable) + { + + } }