This commit is contained in:
Kukks
2023-05-15 10:44:06 +02:00
parent f37edbd9bf
commit 545100820e
9 changed files with 34 additions and 37 deletions

View File

@@ -108,11 +108,11 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector
var rand = Random.Shared.Next(1, 1001); var rand = Random.Shared.Next(1, 1001);
if (rand > _wallet.WabisabiStoreSettings.ExtraJoinProbability) 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; return solution;
} }
_logger.LogInformation( _logger.LogTrace(
"All coins are private and we have no pending payments but will join just to reduce timing analysis"); "All coins are private and we have no pending payments but will join just to reduce timing analysis");
} }

View File

@@ -13,7 +13,7 @@
<PropertyGroup> <PropertyGroup>
<Product>Wabisabi Coinjoin</Product> <Product>Wabisabi Coinjoin</Product>
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description> <Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
<Version>1.0.41</Version> <Version>1.0.42</Version>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->

View File

@@ -187,7 +187,6 @@ public class WabisabiCoordinatorService : PeriodicRunner
_instanceManager.AddCoordinator(discoveredCoordinator.Name, discoveredCoordinator.Name, _ => discoveredCoordinator.Uri, null, discoveredCoordinator.Description ); _instanceManager.AddCoordinator(discoveredCoordinator.Name, discoveredCoordinator.Name, _ => discoveredCoordinator.Uri, null, discoveredCoordinator.Description );
} }
} }
await base.StartAsync(cancellationToken); await base.StartAsync(cancellationToken);
} }

View File

@@ -1,15 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Services; using BTCPayServer.Services;
using LNURL; using LNURL;
using NBitcoin; using NBitcoin;
using Newtonsoft.Json.Linq;
using NNostr.Client; using NNostr.Client;
using WalletWasabi.Backend.Controllers; using WalletWasabi.Backend.Controllers;
@@ -51,7 +48,7 @@ public class Nostr
var evt = new NostrEvent() var evt = new NostrEvent()
{ {
Kind = Kind, Kind = Kind,
Content = description, Content = description??string.Empty,
Tags = new List<NostrEventTag>() Tags = new List<NostrEventTag>()
{ {
new() {TagIdentifier = EndpointTagIdentifier, Data = new List<string>() {new Uri(coordinatorUri, "plugins/wabisabi-coordinator/").ToString()}}, new() {TagIdentifier = EndpointTagIdentifier, Data = new List<string>() {new Uri(coordinatorUri, "plugins/wabisabi-coordinator/").ToString()}},
@@ -94,7 +91,7 @@ public class Nostr
["#network"] = JsonSerializer.SerializeToElement(new[] {network}) ["#network"] = JsonSerializer.SerializeToElement(new[] {network})
} }
} }
}, true, cts.Token).ToListAsync(); }, true, cts.Token).ToListAsync(cancellationToken);
nostrClient.Dispose(); nostrClient.Dispose();

View File

@@ -217,7 +217,7 @@
<span class="text-muted">@coordinator.Coordinator</span> <span class="text-muted">@coordinator.Coordinator</span>
<div> <div>
<div>@(coordinator.WasabiCoordinatorStatusFetcher.Connected? "Coordinator Status: Not connected": "Coordinator Status: Connected")</div> <div>@(!coordinator.WasabiCoordinatorStatusFetcher.Connected? "Coordinator Status: Not connected": "Coordinator Status: Connected")</div>
@if (!string.IsNullOrEmpty(coordinator.Description)) @if (!string.IsNullOrEmpty(coordinator.Description))
{ {

View File

@@ -109,6 +109,8 @@ public class WabisabiCoordinatorClientInstanceManager:IHostedService
{ {
if(started) if(started)
_ = instance.StartAsync(CancellationToken.None); _ = instance.StartAsync(CancellationToken.None);
if(name == "local")
instance.WasabiCoordinatorStatusFetcher.OverrideConnected = null;
} }
} }

View File

@@ -5,6 +5,7 @@ using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.PayoutProcessors; using BTCPayServer.PayoutProcessors;
using BTCPayServer.Services; using BTCPayServer.Services;
using Microsoft.Extensions.Caching.Memory;
using NBitcoin; using NBitcoin;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -16,32 +17,44 @@ namespace BTCPayServer.Plugins.Wabisabi
private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager; private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager;
private readonly WalletProvider _walletProvider; private readonly WalletProvider _walletProvider;
private readonly WalletRepository _walletRepository; private readonly WalletRepository _walletRepository;
private readonly IMemoryCache _memoryCache;
private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray(); private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray();
public WabisabiService(IStoreRepository storeRepository, public WabisabiService(IStoreRepository storeRepository,
WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager, WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager,
WalletProvider walletProvider, WalletProvider walletProvider,
WalletRepository walletRepository) WalletRepository walletRepository,
IMemoryCache memoryCache)
{ {
_storeRepository = storeRepository; _storeRepository = storeRepository;
_coordinatorClientInstanceManager = coordinatorClientInstanceManager; _coordinatorClientInstanceManager = coordinatorClientInstanceManager;
_walletProvider = walletProvider; _walletProvider = walletProvider;
_walletRepository = walletRepository; _walletRepository = walletRepository;
_memoryCache = memoryCache;
} }
private string GetCacheKey(string storeId)
{
return $"{nameof(WabisabiStoreSettings)}-{storeId}";
}
public async Task<WabisabiStoreSettings> GetWabisabiForStore(string storeId) public async Task<WabisabiStoreSettings> GetWabisabiForStore(string storeId)
{ {
var res = await _storeRepository.GetSettingAsync<WabisabiStoreSettings>(storeId, nameof(WabisabiStoreSettings)); var res = await _memoryCache.GetOrCreate(GetCacheKey(storeId), async entry =>
res ??= new WabisabiStoreSettings();
res.Settings = res.Settings.Where(settings => _ids.Contains(settings.Coordinator)).ToList();
res.Settings.ForEach(settings =>
{ {
if(settings.RoundWhenEnabled != null && string.IsNullOrEmpty(settings.RoundWhenEnabled.PlebsDontPayThreshold)) var res = await _storeRepository.GetSettingAsync<WabisabiStoreSettings>(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) foreach (var wabisabiCoordinatorManager in _coordinatorClientInstanceManager.HostedServices)
{ {
if (res.Settings.All(settings => settings.Coordinator != wabisabiCoordinatorManager.Key)) if (res.Settings.All(settings => settings.Coordinator != wabisabiCoordinatorManager.Key))
@@ -75,7 +88,7 @@ namespace BTCPayServer.Plugins.Wabisabi
} }
else else
{ {
var res = await _storeRepository.GetSettingAsync<WabisabiStoreSettings>(storeId, nameof(WabisabiStoreSettings)); var res = await GetWabisabiForStore(storeId);
foreach (var wabisabiStoreCoordinatorSettings in wabisabiSettings.Settings) foreach (var wabisabiStoreCoordinatorSettings in wabisabiSettings.Settings)
{ {
if (!wabisabiStoreCoordinatorSettings.Enabled) if (!wabisabiStoreCoordinatorSettings.Enabled)
@@ -101,7 +114,7 @@ namespace BTCPayServer.Plugins.Wabisabi
} }
await _storeRepository.UpdateSetting(storeId, nameof(WabisabiStoreSettings), wabisabiSettings!); await _storeRepository.UpdateSetting(storeId, nameof(WabisabiStoreSettings), wabisabiSettings!);
} }
_memoryCache.Remove(GetCacheKey(storeId));
await _walletProvider.SettingsUpdated(storeId, wabisabiSettings); await _walletProvider.SettingsUpdated(storeId, wabisabiSettings);
// var existingProcessor = (await _payoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery() // var existingProcessor = (await _payoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery()
// { // {

View File

@@ -1,36 +1,27 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AngleSharp.Dom.Events;
using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Client; using BTCPayServer.Client;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Common; using BTCPayServer.Common;
using BTCPayServer.Configuration; using BTCPayServer.Configuration;
using BTCPayServer.Data;
using BTCPayServer.Filters;
using BTCPayServer.Models.WalletViewModels;
using BTCPayServer.Security; using BTCPayServer.Security;
using BTCPayServer.Services; using BTCPayServer.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NBitcoin; using NBitcoin;
using NBitcoin.Payment; using NBitcoin.Payment;
using NBitcoin.Secp256k1; using NBitcoin.Secp256k1;
using NBXplorer;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NNostr.Client; using NNostr.Client;
using Org.BouncyCastle.Security;
using WalletWasabi.Backend.Controllers; using WalletWasabi.Backend.Controllers;
using WalletWasabi.Blockchain.TransactionBuilding; using WalletWasabi.Blockchain.TransactionBuilding;
using WalletWasabi.Blockchain.TransactionOutputs; using WalletWasabi.Blockchain.TransactionOutputs;
@@ -48,18 +39,15 @@ namespace BTCPayServer.Plugins.Wabisabi
private readonly IExplorerClientProvider _explorerClientProvider; private readonly IExplorerClientProvider _explorerClientProvider;
private readonly WabisabiCoordinatorService _wabisabiCoordinatorService; private readonly WabisabiCoordinatorService _wabisabiCoordinatorService;
private readonly IAuthorizationService _authorizationService; private readonly IAuthorizationService _authorizationService;
private readonly BTCPayServerOptions _options;
private readonly WabisabiCoordinatorClientInstanceManager _instanceManager; private readonly WabisabiCoordinatorClientInstanceManager _instanceManager;
private readonly Socks5HttpClientHandler _socks5HttpClientHandler; private readonly Socks5HttpClientHandler _socks5HttpClientHandler;
public WabisabiStoreController(WabisabiService WabisabiService, WalletProvider walletProvider, public WabisabiStoreController(WabisabiService WabisabiService, WalletProvider walletProvider,
IBTCPayServerClientFactory btcPayServerClientFactory, IBTCPayServerClientFactory btcPayServerClientFactory,
IExplorerClientProvider explorerClientProvider, IExplorerClientProvider explorerClientProvider,
WabisabiCoordinatorService wabisabiCoordinatorService, WabisabiCoordinatorService wabisabiCoordinatorService,
WabisabiCoordinatorClientInstanceManager instanceManager, WabisabiCoordinatorClientInstanceManager instanceManager,
IAuthorizationService authorizationService, IAuthorizationService authorizationService,
IServiceProvider serviceProvider, IServiceProvider serviceProvider)
BTCPayServerOptions options)
{ {
_WabisabiService = WabisabiService; _WabisabiService = WabisabiService;
_walletProvider = walletProvider; _walletProvider = walletProvider;
@@ -67,13 +55,11 @@ namespace BTCPayServer.Plugins.Wabisabi
_explorerClientProvider = explorerClientProvider; _explorerClientProvider = explorerClientProvider;
_wabisabiCoordinatorService = wabisabiCoordinatorService; _wabisabiCoordinatorService = wabisabiCoordinatorService;
_authorizationService = authorizationService; _authorizationService = authorizationService;
_options = options;
_instanceManager = instanceManager; _instanceManager = instanceManager;
_socks5HttpClientHandler = serviceProvider.GetRequiredService<Socks5HttpClientHandler>(); _socks5HttpClientHandler = serviceProvider.GetRequiredService<Socks5HttpClientHandler>();
} }
[HttpGet("")] [HttpGet("")]
[HttpGet("add-coordinator")]
public async Task<IActionResult> UpdateWabisabiStoreSettings(string storeId) public async Task<IActionResult> UpdateWabisabiStoreSettings(string storeId)
{ {
WabisabiStoreSettings Wabisabi = null; WabisabiStoreSettings Wabisabi = null;