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);
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");
}

View File

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

View File

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

View File

@@ -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<NostrEventTag>()
{
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})
}
}
}, true, cts.Token).ToListAsync();
}, true, cts.Token).ToListAsync(cancellationToken);
nostrClient.Dispose();

View File

@@ -217,7 +217,7 @@
<span class="text-muted">@coordinator.Coordinator</span>
<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))
{

View File

@@ -109,6 +109,8 @@ public class WabisabiCoordinatorClientInstanceManager:IHostedService
{
if(started)
_ = 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.PayoutProcessors;
using BTCPayServer.Services;
using Microsoft.Extensions.Caching.Memory;
using NBitcoin;
using Newtonsoft.Json.Linq;
@@ -16,22 +17,31 @@ 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<WabisabiStoreSettings> GetWabisabiForStore(string storeId)
{
var res = await _memoryCache.GetOrCreate(GetCacheKey(storeId), async entry =>
{
var res = await _storeRepository.GetSettingAsync<WabisabiStoreSettings>(storeId, nameof(WabisabiStoreSettings));
res ??= new WabisabiStoreSettings();
res.Settings = res.Settings.Where(settings => _ids.Contains(settings.Coordinator)).ToList();
@@ -42,6 +52,9 @@ namespace BTCPayServer.Plugins.Wabisabi
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<WabisabiStoreSettings>(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()
// {

View File

@@ -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<Socks5HttpClientHandler>();
}
[HttpGet("")]
[HttpGet("add-coordinator")]
public async Task<IActionResult> UpdateWabisabiStoreSettings(string storeId)
{
WabisabiStoreSettings Wabisabi = null;