diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs index 98c79b4..fd2de65 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayCoinjoinCoinSelector.cs @@ -108,11 +108,11 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector var rand = Random.Shared.Next(1, 1001); if (rand > _wallet.WabisabiStoreSettings.ExtraJoinProbability) { - _logger.LogInformation($"All coins are private and we have no pending payments. Skipping join."); + _logger.LogTrace($"All coins are private and we have no pending payments. Skipping join."); return solution; } - _logger.LogInformation( + _logger.LogTrace( "All coins are private and we have no pending payments but will join just to reduce timing analysis"); } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayServer.Plugins.Wabisabi.csproj index cda56a2..57ed9b3 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.41 + 1.0.42 diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs index b866dcb..450ac06 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs @@ -187,7 +187,6 @@ public class WabisabiCoordinatorService : PeriodicRunner _instanceManager.AddCoordinator(discoveredCoordinator.Name, discoveredCoordinator.Name, _ => discoveredCoordinator.Uri, null, discoveredCoordinator.Description ); } } - await base.StartAsync(cancellationToken); } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Nostr.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Nostr.cs index bfaad28..a3f2aa4 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Nostr.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Nostr.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Text.Json; -using System.Text.Json.Nodes; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Services; using LNURL; using NBitcoin; -using Newtonsoft.Json.Linq; using NNostr.Client; using WalletWasabi.Backend.Controllers; @@ -51,7 +48,7 @@ public class Nostr var evt = new NostrEvent() { Kind = Kind, - Content = description, + Content = description??string.Empty, Tags = new List() { new() {TagIdentifier = EndpointTagIdentifier, Data = new List() {new Uri(coordinatorUri, "plugins/wabisabi-coordinator/").ToString()}}, @@ -94,7 +91,7 @@ public class Nostr ["#network"] = JsonSerializer.SerializeToElement(new[] {network}) } } - }, true, cts.Token).ToListAsync(); + }, true, cts.Token).ToListAsync(cancellationToken); nostrClient.Dispose(); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml index d751579..473c1ab 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml @@ -217,7 +217,7 @@ @coordinator.Coordinator
-
@(coordinator.WasabiCoordinatorStatusFetcher.Connected? "Coordinator Status: Not connected": "Coordinator Status: Connected")
+
@(!coordinator.WasabiCoordinatorStatusFetcher.Connected? "Coordinator Status: Not connected": "Coordinator Status: Connected")
@if (!string.IsNullOrEmpty(coordinator.Description)) { diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs index 8c69b90..f0c2bf0 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiCoordinatorClientInstance.cs @@ -109,6 +109,8 @@ public class WabisabiCoordinatorClientInstanceManager:IHostedService { if(started) _ = instance.StartAsync(CancellationToken.None); + if(name == "local") + instance.WasabiCoordinatorStatusFetcher.OverrideConnected = null; } } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs index 2a44fbf..d14649c 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiService.cs @@ -5,6 +5,7 @@ using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Data; using BTCPayServer.PayoutProcessors; using BTCPayServer.Services; +using Microsoft.Extensions.Caching.Memory; using NBitcoin; using Newtonsoft.Json.Linq; @@ -16,32 +17,44 @@ namespace BTCPayServer.Plugins.Wabisabi private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager; private readonly WalletProvider _walletProvider; private readonly WalletRepository _walletRepository; + private readonly IMemoryCache _memoryCache; private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray(); public WabisabiService(IStoreRepository storeRepository, WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager, WalletProvider walletProvider, - WalletRepository walletRepository) + WalletRepository walletRepository, + IMemoryCache memoryCache) { _storeRepository = storeRepository; _coordinatorClientInstanceManager = coordinatorClientInstanceManager; _walletProvider = walletProvider; _walletRepository = walletRepository; + _memoryCache = memoryCache; } + private string GetCacheKey(string storeId) + { + return $"{nameof(WabisabiStoreSettings)}-{storeId}"; + } public async Task GetWabisabiForStore(string storeId) { - var res = await _storeRepository.GetSettingAsync(storeId, nameof(WabisabiStoreSettings)); - res ??= new WabisabiStoreSettings(); - res.Settings = res.Settings.Where(settings => _ids.Contains(settings.Coordinator)).ToList(); - res.Settings.ForEach(settings => + var res = await _memoryCache.GetOrCreate(GetCacheKey(storeId), async entry => { - if(settings.RoundWhenEnabled != null && string.IsNullOrEmpty(settings.RoundWhenEnabled.PlebsDontPayThreshold)) + var res = await _storeRepository.GetSettingAsync(storeId, nameof(WabisabiStoreSettings)); + res ??= new WabisabiStoreSettings(); + res.Settings = res.Settings.Where(settings => _ids.Contains(settings.Coordinator)).ToList(); + res.Settings.ForEach(settings => { - settings.RoundWhenEnabled.PlebsDontPayThreshold = "1000000"; - } + if(settings.RoundWhenEnabled != null && string.IsNullOrEmpty(settings.RoundWhenEnabled.PlebsDontPayThreshold)) + { + settings.RoundWhenEnabled.PlebsDontPayThreshold = "1000000"; + } + }); + return res; }); + foreach (var wabisabiCoordinatorManager in _coordinatorClientInstanceManager.HostedServices) { if (res.Settings.All(settings => settings.Coordinator != wabisabiCoordinatorManager.Key)) @@ -75,7 +88,7 @@ namespace BTCPayServer.Plugins.Wabisabi } else { - var res = await _storeRepository.GetSettingAsync(storeId, nameof(WabisabiStoreSettings)); + var res = await GetWabisabiForStore(storeId); foreach (var wabisabiStoreCoordinatorSettings in wabisabiSettings.Settings) { if (!wabisabiStoreCoordinatorSettings.Enabled) @@ -101,7 +114,7 @@ namespace BTCPayServer.Plugins.Wabisabi } await _storeRepository.UpdateSetting(storeId, nameof(WabisabiStoreSettings), wabisabiSettings!); } - + _memoryCache.Remove(GetCacheKey(storeId)); await _walletProvider.SettingsUpdated(storeId, wabisabiSettings); // var existingProcessor = (await _payoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery() // { diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs index 4bcde99..a6e46e1 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs @@ -1,36 +1,27 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Security.Claims; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; -using AngleSharp.Dom.Events; using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Client; using BTCPayServer.Client.Models; using BTCPayServer.Common; using BTCPayServer.Configuration; -using BTCPayServer.Data; -using BTCPayServer.Filters; -using BTCPayServer.Models.WalletViewModels; using BTCPayServer.Security; using BTCPayServer.Services; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using NBitcoin; using NBitcoin.Payment; using NBitcoin.Secp256k1; -using NBXplorer; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NNostr.Client; -using Org.BouncyCastle.Security; using WalletWasabi.Backend.Controllers; using WalletWasabi.Blockchain.TransactionBuilding; using WalletWasabi.Blockchain.TransactionOutputs; @@ -48,18 +39,15 @@ namespace BTCPayServer.Plugins.Wabisabi private readonly IExplorerClientProvider _explorerClientProvider; private readonly WabisabiCoordinatorService _wabisabiCoordinatorService; private readonly IAuthorizationService _authorizationService; - private readonly BTCPayServerOptions _options; private readonly WabisabiCoordinatorClientInstanceManager _instanceManager; private readonly Socks5HttpClientHandler _socks5HttpClientHandler; - public WabisabiStoreController(WabisabiService WabisabiService, WalletProvider walletProvider, IBTCPayServerClientFactory btcPayServerClientFactory, IExplorerClientProvider explorerClientProvider, WabisabiCoordinatorService wabisabiCoordinatorService, WabisabiCoordinatorClientInstanceManager instanceManager, IAuthorizationService authorizationService, - IServiceProvider serviceProvider, - BTCPayServerOptions options) + IServiceProvider serviceProvider) { _WabisabiService = WabisabiService; _walletProvider = walletProvider; @@ -67,13 +55,11 @@ namespace BTCPayServer.Plugins.Wabisabi _explorerClientProvider = explorerClientProvider; _wabisabiCoordinatorService = wabisabiCoordinatorService; _authorizationService = authorizationService; - _options = options; _instanceManager = instanceManager; _socks5HttpClientHandler = serviceProvider.GetRequiredService(); } [HttpGet("")] - [HttpGet("add-coordinator")] public async Task UpdateWabisabiStoreSettings(string storeId) { WabisabiStoreSettings Wabisabi = null; diff --git a/submodules/btcpayserver b/submodules/btcpayserver index 717f161..8db5e7e 160000 --- a/submodules/btcpayserver +++ b/submodules/btcpayserver @@ -1 +1 @@ -Subproject commit 717f1610f5723ee40a11dec6cf43a615af0fb8e4 +Subproject commit 8db5e7e043225d84220ff43f004d09d22a78c6e3