From 64dc8501ae25ee92e36df441189a8f9025a5cfd0 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 31 Oct 2023 14:12:43 +0100 Subject: [PATCH] small fixes to ss and wabi --- .../BTCPayServer.Plugins.SideShift.csproj | 2 +- .../PrismClaimCreate.cs | 2 +- .../BTCPayCoinjoinCoinSelector.cs | 20 +- .../BTCPayServer.Plugins.Wabisabi.csproj | 2 +- .../Filters/ExceptionTranslateAttribute.cs | 65 +-- .../NostrWabisabiApiServer.cs | 6 +- .../Shared/Wabisabi/WabisabiDashboard.cshtml | 464 ++++++++---------- 7 files changed, 266 insertions(+), 295 deletions(-) diff --git a/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj b/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj index 3d0657b..d8b95cf 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj +++ b/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj @@ -9,7 +9,7 @@ SideShift Allows you to embed a SideShift conversion screen to allow customers to pay with altcoins. - 1.1.11 + 1.1.12 diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs index 7de463d..51770e7 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs +++ b/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs @@ -25,7 +25,7 @@ public class PrismClaimCreate : IPluginHookFilter var network = _networkProvider.GetNetwork("BTC"); if (args is not ClaimRequest claimRequest || network is null) { - return Task.FromResult(args); + return args; } if (claimRequest.Destination?.ToString() is not { } args1 || !args1.StartsWith("sideshift:")) return args; diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs index 2bf3855..4f7f79a 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs @@ -195,22 +195,32 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector { continue; } - //if we have less than the max suggested output registration, we should add more coins to reach that number to avoid breaking up into too many coins? - var isLessThanMaxOutputRegistration = solution.Coins.Count < 8; + var isLessThanMaxOutputRegistration = solution.Coins.Count < Math.Max(solution.HandledPayments.Count +1, 8); var rand = Random.Shared.Next(1, 101); //let's check how many coins we are allowed to add max and how many we added, and use that percentage as the random chance of not adding it. // if max coins = 20, and current coins = 5 then 5/20 = 0.25 * 100 = 25 var maxCoinCapacityPercentage = Math.Floor((solution.Coins.Count / (decimal)maxCoins) * 100); //aggressively attempt to reach max coin target if consolidation mode is on //if we're less than the max output registration, we should be more aggressive in adding coins - var chance = consolidationMode ? (isLessThanMaxOutputRegistration? 100: 90 ): 100m - Math.Min(maxCoinCapacityPercentage, isLessThanMaxOutputRegistration ? 10m : maxCoinCapacityPercentage); - _logger.LogDebug( - $"coin selection: no payms left but at {solution.Coins.Count()} coins. random chance to add another coin if: {chance} <= {rand} (random 0-100) {chance <= rand} "); + + decimal chance = 100; + if (consolidationMode && !isLessThanMaxOutputRegistration) + { + chance -= maxCoinCapacityPercentage / random.GetInt(2, 8); + } + else if (!isLessThanMaxOutputRegistration) + { + chance -= maxCoinCapacityPercentage; + } + + _logger.LogDebug($"coin selection: no payments left but at {solution.Coins.Count()} coins. random chance to add another coin if: {chance} > {rand} (random 0-100) continue: {chance > rand}"); + if (chance <= rand) { break; } + } } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj index 0fac719..28a12a1 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj @@ -13,7 +13,7 @@ Wabisabi Coinjoin Allows you to integrate your btcpayserver store with coinjoins. - 1.0.59 + 1.0.60 diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ExceptionTranslateAttribute.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ExceptionTranslateAttribute.cs index a0e54b6..cbf8f3f 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ExceptionTranslateAttribute.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ExceptionTranslateAttribute.cs @@ -1,42 +1,47 @@ using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using Newtonsoft.Json; using WabiSabi.Crypto; +using WalletWasabi.Affiliation; using WalletWasabi.WabiSabi; using WalletWasabi.WabiSabi.Backend.Models; -using WalletWasabi.WabiSabi.Crypto; using WalletWasabi.WabiSabi.Models; -using WalletWasabi.WabiSabi.Models.Serialization; namespace WalletWasabi.Backend.Filters; public class ExceptionTranslateAttribute : ExceptionFilterAttribute { - public override void OnException(ExceptionContext context) - { - var exception = context.Exception.InnerException ?? context.Exception; - context.Result = exception switch - { - WabiSabiProtocolException e => new JsonResult(new Error( - Type: ProtocolConstants.ProtocolViolationType, - ErrorCode: e.ErrorCode.ToString(), - Description: e.Message, - ExceptionData: e.ExceptionData ?? EmptyExceptionData.Instance), - JsonSerializationOptions.Default.Settings ) - { - StatusCode = (int)HttpStatusCode.InternalServerError - }, - WabiSabiCryptoException e => new JsonResult(new Error( - Type: ProtocolConstants.ProtocolViolationType, - ErrorCode: WabiSabiProtocolErrorCode.CryptoException.ToString(), - Description: e.Message, - ExceptionData: EmptyExceptionData.Instance), - JsonSerializationOptions.Default.Settings) - { - StatusCode = (int)HttpStatusCode.InternalServerError - }, - _ => new StatusCodeResult((int)HttpStatusCode.InternalServerError) - }; - } -} + public override void OnException(ExceptionContext context) + { + var exception = context.Exception.InnerException ?? context.Exception; + + context.Result = exception switch + { + WabiSabiProtocolException e => new JsonResult(new Error( + Type: ProtocolConstants.ProtocolViolationType, + ErrorCode: e.ErrorCode.ToString(), + Description: e.Message, + ExceptionData: e.ExceptionData ?? EmptyExceptionData.Instance)) + { + StatusCode = (int) HttpStatusCode.InternalServerError + }, + WabiSabiCryptoException e => new JsonResult(new Error( + Type: ProtocolConstants.ProtocolViolationType, + ErrorCode: WabiSabiProtocolErrorCode.CryptoException.ToString(), + Description: e.Message, + ExceptionData: EmptyExceptionData.Instance)) + { + StatusCode = (int) HttpStatusCode.InternalServerError + }, + AffiliationException e => new JsonResult(new Error( + Type: AffiliationConstants.RequestSecrecyViolationType, + ErrorCode: "undefined", + Description: e.Message, + ExceptionData: EmptyExceptionData.Instance)) + { + StatusCode = (int) HttpStatusCode.InternalServerError + }, + _ => new StatusCodeResult((int) HttpStatusCode.InternalServerError) + }; + } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/NostrWabisabiApiServer.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/NostrWabisabiApiServer.cs index c54534b..7c3d7e3 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/NostrWabisabiApiServer.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/NostrWabisabiApiServer.cs @@ -95,7 +95,7 @@ public class NostrWabisabiApiServer: IHostedService Content = Serialize(response) }; await _client.PublishEvent(nostrEvent, cancellationToken); - _logger.LogInformation($"NOSTR SERVER: PUBLISHED ROUND STATE {nostrEvent.Id}"); + _logger.LogDebug($"NOSTR SERVER: PUBLISHED ROUND STATE {nostrEvent.Id}"); await Task.Delay(1000, cancellationToken); } } @@ -115,7 +115,7 @@ public class NostrWabisabiApiServer: IHostedService { try { - _logger.LogInformation($"NOSTR SERVER: Received request {evt.Id} {action}"); + _logger.LogDebug($"NOSTR SERVER: Received request {evt.Id} {action}"); switch (action) { case RemoteAction.GetStatus: @@ -205,7 +205,7 @@ public class NostrWabisabiApiServer: IHostedService CancellationToken cancellationToken) { - _logger.LogInformation($"NOSTR SERVER: REPLYING TO {originaltEvent.Id} WITH {response}"); + _logger.LogDebug($"NOSTR SERVER: REPLYING TO {originaltEvent.Id} WITH {response}"); var evt = new NostrEvent() { Content = Serialize(response), diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml index 34c2437..e3212a7 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/Shared/Wabisabi/WabisabiDashboard.cshtml @@ -65,8 +65,7 @@ } else { - - + } @@ -79,272 +78,229 @@ var colorCoins = coins.GroupBy(coin => coin.CoinColor(wallet.AnonScoreTarget)).ToDictionary(grouping => grouping.Key, grouping => grouping);
- @if (wallet is { }) - { - @if (!((BTCPayKeyChain) wallet.KeyChain).KeysAvailable) + @if (wallet is { }) { - + @if (!((BTCPayKeyChain) wallet.KeyChain).KeysAvailable) + { + + } } - } -
-

Coinjoin stats

- - Configure coinjoin settings - +
+

Coinjoin stats

+ + Configure coinjoin settings + -
-
+
+
-
-
Privacy progress
-
-
@privacyPercentage%
-
-
-
-
-
Coins per privacy
-
- @foreach (var cc in colorCoins) - { - var cssClass = cc.Key == AnonsetType.Green ? "bg-success" : cc.Key == AnonsetType.Orange ? "bg-warning" : - "bg-danger"; - var text = cc.Key == AnonsetType.Green ? "private" : cc.Key == AnonsetType.Orange ? "semi-private" : - "non-private"; - - var tooltiptext = $"{cc.Value.Count()} {text} coins"; - text = cc.Value.Count().ToString(); - var percentage = decimal.Divide(cc.Value.Count(), coins.Count()) * 100; -
@text
- } -
-
-
-
Value per privacy
-
- @foreach (var cc in colorCoins) - { - var cssClass = cc.Key == AnonsetType.Green ? "bg-success" : cc.Key == AnonsetType.Orange ? "bg-warning" : - "bg-danger"; - var text = cc.Key == AnonsetType.Green ? "private" : cc.Key == AnonsetType.Orange ? "semi-private" : - "non-private"; - var percentage = decimal.Divide(cc.Value.Sum(coin => coin.Amount.ToDecimal(MoneyUnit.BTC)), coins.TotalAmount().ToDecimal(MoneyUnit.BTC)) * 100; - var tooltiptext = $"{cc.Value.Sum(coin => coin.Amount.ToDecimal(MoneyUnit.BTC))} {text} BTC"; - - text = cc.Value.Sum(coin => coin.Amount.ToDecimal(MoneyUnit.BTC)).ToString(); -
@text
- } -
-
- @* @{ *@ - @* var coinjoined = @coins.CoinJoinInProcess(); *@ - @* } *@ - @* @if (coinjoined.Any()) *@ - @* { *@ - @* var count = @coins.CoinJoinInProcess().Count(); *@ - @* var totalCount = @coins.Count(); *@ - @* var sum = @coinjoined.TotalAmount().ToDecimal(MoneyUnit.BTC); *@ - @* var totalSum = @coins.TotalAmount().ToDecimal(MoneyUnit.BTC); *@ - @* var sumPercentage = decimal.Divide(sum, totalSum) * 100; *@ - @* var countPercentage = decimal.Divide(count, totalCount) * 100; *@ - @* *@ - @*
*@ - @*
Coins currently joining
*@ - @*
*@ - @*
@count
*@ - @*
*@ - @*
*@ - @*
*@ - @*
*@ - @*
Value currently joining
*@ - @*
*@ - @*
@sum BTC
*@ - @*
*@ - @* *@ - @* *@ - @*
*@ - @*
*@ - @* } *@ - - - - } }