From cb98e301da2b0ced9006c22f3925f29f39a48da9 Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 18 Oct 2024 12:09:39 +0200 Subject: [PATCH] wip --- .../BTCPayWallet.cs | 4 +- .../Coordinator/CoordinatorExtensions.cs | 111 +++++++++++++++--- ...MultiPooledSerializerJsonInputFormatter.cs | 49 -------- ...ontextAwareSerializerJsonInputFormatter.cs | 44 ------- .../ControllerBasedJsonInputFormatter.cs | 80 ------------- ...rBasedJsonInputFormatterMvcOptionsSetup.cs | 70 ----------- ...putFormatterServiceCollectionExtensions.cs | 27 ----- ...ollerBasedJsonSerializerSettingsBuilder.cs | 10 -- .../Filters/JsonSerializerPooledPolicy.cs | 16 --- .../UseWasabiJsonInputFormatterAttribute.cs | 6 - .../WasabiSpecificJsonSerializerFilter.cs | 37 ------ .../Coordinator/WabiSabiController.cs | 5 +- .../WabisabiCoordinatorConfigController.cs | 2 +- .../UpdateWabisabiStoreSettings.cshtml | 13 +- .../WabisabiPlugin.cs | 1 - .../WalletProvider.cs | 87 +++++++------- 16 files changed, 150 insertions(+), 412 deletions(-) delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareMultiPooledSerializerJsonInputFormatter.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareSerializerJsonInputFormatter.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatter.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterMvcOptionsSetup.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterServiceCollectionExtensions.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/IControllerBasedJsonSerializerSettingsBuilder.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/JsonSerializerPooledPolicy.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/UseWasabiJsonInputFormatterAttribute.cs delete mode 100644 Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/WasabiSpecificJsonSerializerFilter.cs diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs index 4b800c9..683b581 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/BTCPayWallet.cs @@ -49,7 +49,7 @@ public class BTCPayWallet : IWallet, IDestinationProvider private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; private readonly WalletRepository _walletRepository; private readonly BTCPayNetworkProvider _btcPayNetworkProvider; - private readonly BitcoinLikePayoutHandler _bitcoinLikePayoutHandler; + private readonly IPayoutHandler _bitcoinLikePayoutHandler; private readonly BTCPayNetworkJsonSerializerSettings _btcPayNetworkJsonSerializerSettings; private readonly Services.Wallets.BTCPayWallet _btcPayWallet; private readonly PullPaymentHostedService _pullPaymentHostedService; @@ -63,7 +63,7 @@ public class BTCPayWallet : IWallet, IDestinationProvider PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, WalletRepository walletRepository, BTCPayNetworkProvider btcPayNetworkProvider, - BitcoinLikePayoutHandler bitcoinLikePayoutHandler, + IPayoutHandler bitcoinLikePayoutHandler, BTCPayNetworkJsonSerializerSettings btcPayNetworkJsonSerializerSettings, Services.Wallets.BTCPayWallet btcPayWallet, PullPaymentHostedService pullPaymentHostedService, diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/CoordinatorExtensions.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/CoordinatorExtensions.cs index 16ff99e..e58d7b7 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/CoordinatorExtensions.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/CoordinatorExtensions.cs @@ -1,9 +1,21 @@ -using BTCPayServer.Abstractions.Contracts; +using System; +using System.Buffers; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Services; using BTCPayServer.Configuration; using BTCPayServer.Plugins.Wabisabi.Coordinator; using BTCPayServer.Services; +using Microsoft.AspNetCore.JsonPatch; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.ObjectPool; +using Microsoft.Extensions.Options; +using NBitcoin; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using WalletWasabi.WabiSabi.Backend; using WalletWasabi.WabiSabi.Models.Serialization; @@ -13,16 +25,16 @@ public static class CoordinatorExtensions { public static void AddWabisabiCoordinator(this IServiceCollection services) { - services.AddSingleton(); services.AddSingleton(); services.AddTransient(provider => { var s = provider.GetRequiredService(); - if (!s.Started ) + if (!s.Started) { return null; } + return new WabiSabiController(s.IdempotencyRequestCache, s.WabiSabiCoordinator.Arena, s.WabiSabiCoordinator.CoinJoinFeeRateStatStore); }); @@ -34,28 +46,95 @@ public static class CoordinatorExtensions services.AddHttpClient("wabisabi-coordinator-scripts-no-redirect.onion") .ConfigurePrimaryHttpMessageHandler(provider => { - var handler = new Socks5HttpClientHandler(provider.GetRequiredService()); handler.AllowAutoRedirect = false; return handler; }); - services.AddHttpClient("wabisabi-coordinator-scripts.onion") + services.AddHttpClient("wabisabi-coordinator-scripts.onion") .ConfigurePrimaryHttpMessageHandler(provider => { var handler = new Socks5HttpClientHandler(provider.GetRequiredService()); handler.AllowAutoRedirect = false; return handler; }); - - - //inside Startup.ConfigureServices - services.AddControllerBasedJsonInputFormatter(formatter => { - formatter.ForControllersWithAttribute() - .ForActionsWithAttribute() - .WithSerializerSettingsConfigurer(settings => - { - settings.Converters = JsonSerializationOptions.Default.Settings.Converters; - }); - }); + + services.ConfigureOptions(); } } + +public class WasabiInputFormatter : NewtonsoftJsonInputFormatter +{ + public WasabiInputFormatter(ILogger logger, JsonSerializerSettings serializerSettings, ArrayPool charPool, + ObjectPoolProvider objectPoolProvider, MvcOptions options, MvcNewtonsoftJsonOptions jsonOptions) : base(logger, + serializerSettings, charPool, objectPoolProvider, options, jsonOptions) + { + } + + public override bool CanRead(InputFormatterContext context) + { + var controllerName = context.HttpContext.Request.RouteValues["controller"]?.ToString(); + return controllerName == "WabiSabi"; + } +} + +public class WasabiOutputFormatter : NewtonsoftJsonOutputFormatter +{ + public WasabiOutputFormatter(JsonSerializerSettings serializerSettings, ArrayPool charPool, + MvcOptions options, MvcNewtonsoftJsonOptions jsonOptions) : base(serializerSettings, charPool, options, + jsonOptions) + { + } + + public override bool CanWriteResult(OutputFormatterCanWriteContext context) + { + var controllerName = context.HttpContext.Request.RouteValues["controller"]?.ToString(); + return controllerName == "WabiSabi"; + } +} + +internal sealed class WasabiInputFormatterJsonMvcOptionsSetup : IConfigureOptions +{ + private readonly ILoggerFactory _loggerFactory; + private readonly MvcNewtonsoftJsonOptions _jsonOptions; + private readonly ArrayPool _charPool; + private readonly ObjectPoolProvider _objectPoolProvider; + private readonly JsonSerializerSettings _settings; + + public WasabiInputFormatterJsonMvcOptionsSetup( + ILoggerFactory loggerFactory, + IOptions jsonOptions, + ArrayPool charPool, + ObjectPoolProvider objectPoolProvider) + { + ArgumentNullException.ThrowIfNull(loggerFactory); + ArgumentNullException.ThrowIfNull(jsonOptions); + ArgumentNullException.ThrowIfNull(charPool); + ArgumentNullException.ThrowIfNull(objectPoolProvider); + + _loggerFactory = loggerFactory; + _jsonOptions = jsonOptions.Value; + _charPool = charPool; + _objectPoolProvider = objectPoolProvider; + + _settings = JsonSerializationOptions.Default.Settings; + } + + public void Configure(MvcOptions options) + { + options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(BitcoinAddress))); + options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(Script))); + + options.InputFormatters.Insert(0, new WasabiInputFormatter( + _loggerFactory.CreateLogger(), + _settings, + _charPool, + _objectPoolProvider, + options, + _jsonOptions)); + options.OutputFormatters.Insert(0, new WasabiOutputFormatter( + _settings, + _charPool, + options, + _jsonOptions)); + } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareMultiPooledSerializerJsonInputFormatter.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareMultiPooledSerializerJsonInputFormatter.cs deleted file mode 100644 index d113ffd..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareMultiPooledSerializerJsonInputFormatter.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Buffers; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.ObjectPool; -using Newtonsoft.Json; - -public abstract class ContextAwareMultiPooledSerializerJsonInputFormatter : ContextAwareSerializerJsonInputFormatter -{ - public ContextAwareMultiPooledSerializerJsonInputFormatter(ILogger logger, JsonSerializerSettings serializerSettings, ArrayPool charPool, ObjectPoolProvider objectPoolProvider, MvcOptions options, MvcNewtonsoftJsonOptions jsonOptions) - : base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions) - { - - } - readonly IDictionary> _serializerPools = new ConcurrentDictionary>(); - readonly AsyncLocal _currentPoolKeyAsyncLocal = new AsyncLocal(); - protected object CurrentPoolKey => _currentPoolKeyAsyncLocal.Value; - protected abstract object GetSerializerPoolKey(InputFormatterContext context); - protected override JsonSerializer CreateJsonSerializer(InputFormatterContext context) - { - object poolKey = GetSerializerPoolKey(context) ?? ""; - if(!_serializerPools.TryGetValue(poolKey, out var pool)) - { - //clone the settings - var serializerSettings = new JsonSerializerSettings(); - foreach(var prop in typeof(JsonSerializerSettings).GetProperties().Where(e => e.CanWrite)) - { - prop.SetValue(serializerSettings, prop.GetValue(SerializerSettings)); - } - ConfigureSerializerSettings(serializerSettings, poolKey, context); - pool = PoolProvider.Create(new JsonSerializerPooledPolicy(serializerSettings)); - _serializerPools[poolKey] = pool; - } - _currentPoolKeyAsyncLocal.Value = poolKey; - return pool.Get(); - } - protected override void ReleaseJsonSerializer(JsonSerializer serializer) - { - if(_serializerPools.TryGetValue(CurrentPoolKey ?? "", out var pool)) - { - pool.Return(serializer); - } - } - protected virtual void ConfigureSerializerSettings(JsonSerializerSettings serializerSettings, object poolKey, InputFormatterContext context) { } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareSerializerJsonInputFormatter.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareSerializerJsonInputFormatter.cs deleted file mode 100644 index b3257a4..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ContextAwareSerializerJsonInputFormatter.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Buffers; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.ObjectPool; -using Newtonsoft.Json; - -public abstract class ContextAwareSerializerJsonInputFormatter : NewtonsoftJsonInputFormatter -{ - public ContextAwareSerializerJsonInputFormatter(ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, ObjectPoolProvider objectPoolProvider, MvcOptions options, MvcNewtonsoftJsonOptions jsonOptions) : base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions) - { - PoolProvider = objectPoolProvider; - } - readonly AsyncLocal _currentContextAsyncLocal = new AsyncLocal(); - readonly AsyncLocal _currentActionAsyncLocal = new AsyncLocal(); - protected InputFormatterContext CurrentContext => _currentContextAsyncLocal.Value; - protected ActionContext CurrentAction => _currentActionAsyncLocal.Value; - protected ObjectPoolProvider PoolProvider { get; } - public override Task ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding) - { - _currentContextAsyncLocal.Value = context; - _currentActionAsyncLocal.Value = context.HttpContext.RequestServices.GetRequiredService().ActionContext; - return base.ReadRequestBodyAsync(context, encoding); - } - public override Task ReadRequestBodyAsync(InputFormatterContext context) - { - _currentContextAsyncLocal.Value = context; - _currentActionAsyncLocal.Value = context.HttpContext.RequestServices.GetRequiredService().ActionContext; - return base.ReadRequestBodyAsync(context); - } - protected virtual JsonSerializer CreateJsonSerializer(InputFormatterContext context) => null; - protected override JsonSerializer CreateJsonSerializer() - { - var context = CurrentContext; - return (context == null ? null : CreateJsonSerializer(context)) ?? base.CreateJsonSerializer(); - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatter.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatter.cs deleted file mode 100644 index b619d85..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatter.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Controllers; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Routing; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.ObjectPool; -using Newtonsoft.Json; - -public class ControllerBasedJsonInputFormatter : ContextAwareMultiPooledSerializerJsonInputFormatter, - IControllerBasedJsonSerializerSettingsBuilder -{ - public ControllerBasedJsonInputFormatter(ILogger logger, JsonSerializerSettings serializerSettings, ArrayPool charPool, ObjectPoolProvider objectPoolProvider, MvcOptions options, MvcNewtonsoftJsonOptions jsonOptions) : base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions) - { - } - readonly IDictionary> _configureSerializerSettings - = new Dictionary>(); - readonly HashSet _beingAppliedConfigurationKeys = new HashSet(); - protected override object GetSerializerPoolKey(InputFormatterContext context) - { - var routeValues = context.HttpContext.GetRouteData()?.Values; - var controllerName = routeValues == null ? null : routeValues["controller"]?.ToString(); - if(controllerName != null && _configureSerializerSettings.ContainsKey(controllerName)) - { - return controllerName; - } - var actionContext = CurrentAction; - if (actionContext != null && actionContext.ActionDescriptor is ControllerActionDescriptor actionDesc) - { - foreach (var attr in actionDesc.MethodInfo.GetCustomAttributes(true) - .Concat(actionDesc.ControllerTypeInfo.GetCustomAttributes(true))) - { - var key = attr.GetType(); - if (_configureSerializerSettings.ContainsKey(key)) - { - return key; - } - } - } - return null; - } - public IControllerBasedJsonSerializerSettingsBuilder ForControllers(params string[] controllerNames) - { - foreach(var controllerName in controllerNames ?? Enumerable.Empty()) - { - _beingAppliedConfigurationKeys.Add((controllerName ?? "").ToLowerInvariant()); - } - return this; - } - public IControllerBasedJsonSerializerSettingsBuilder ForControllersWithAttribute() - { - _beingAppliedConfigurationKeys.Add(typeof(T)); - return this; - } - public IControllerBasedJsonSerializerSettingsBuilder ForActionsWithAttribute() - { - _beingAppliedConfigurationKeys.Add(typeof(T)); - return this; - } - ControllerBasedJsonInputFormatter IControllerBasedJsonSerializerSettingsBuilder.WithSerializerSettingsConfigurer(Action configurer) - { - if (configurer == null) throw new ArgumentNullException(nameof(configurer)); - foreach(var key in _beingAppliedConfigurationKeys) - { - _configureSerializerSettings[key] = configurer; - } - _beingAppliedConfigurationKeys.Clear(); - return this; - } - protected override void ConfigureSerializerSettings(JsonSerializerSettings serializerSettings, object poolKey, InputFormatterContext context) - { - if (_configureSerializerSettings.TryGetValue(poolKey, out var configurer)) - { - configurer.Invoke(serializerSettings); - } - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterMvcOptionsSetup.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterMvcOptionsSetup.cs deleted file mode 100644 index 54a7aa8..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterMvcOptionsSetup.cs +++ /dev/null @@ -1,70 +0,0 @@ - -using System; -using System.Buffers; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.ObjectPool; -using Microsoft.Extensions.Options; - -public class ControllerBasedJsonInputFormatterMvcOptionsSetup : IConfigureOptions -{ - private readonly ILoggerFactory _loggerFactory; - private readonly MvcNewtonsoftJsonOptions _jsonOptions; - private readonly ArrayPool _charPool; - private readonly ObjectPoolProvider _objectPoolProvider; - public ControllerBasedJsonInputFormatterMvcOptionsSetup( - ILoggerFactory loggerFactory, - IOptions jsonOptions, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider) - { - if (loggerFactory == null) - { - throw new ArgumentNullException(nameof(loggerFactory)); - } - - if (jsonOptions == null) - { - throw new ArgumentNullException(nameof(jsonOptions)); - } - - if (charPool == null) - { - throw new ArgumentNullException(nameof(charPool)); - } - - if (objectPoolProvider == null) - { - throw new ArgumentNullException(nameof(objectPoolProvider)); - } - - _loggerFactory = loggerFactory; - _jsonOptions = jsonOptions.Value; - _charPool = charPool; - _objectPoolProvider = objectPoolProvider; - } - public void Configure(MvcOptions options) - { - //remove the default - options.InputFormatters.RemoveType(); - //add our own - var jsonInputLogger = _loggerFactory.CreateLogger(); - - options.InputFormatters.Add(new ControllerBasedJsonInputFormatter( - jsonInputLogger, - _jsonOptions.SerializerSettings, - _charPool, - _objectPoolProvider, - options, - _jsonOptions)); - } -} - -//there is a similar class like this implemented by the framework -//but it's a pity that it's internal -//So we define our own class here (which is exactly the same from the source code) -//It's quite simple like this - -//This attribute is used as a marker to decorate any controllers -//or actions that you want to apply your custom input formatter \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterServiceCollectionExtensions.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterServiceCollectionExtensions.cs deleted file mode 100644 index c7f3d6c..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/ControllerBasedJsonInputFormatterServiceCollectionExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Linq; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; - -public static class ControllerBasedJsonInputFormatterServiceCollectionExtensions -{ - public static IServiceCollection AddControllerBasedJsonInputFormatter(this IServiceCollection services, - Action configureFormatter) - { - if(configureFormatter == null) - { - throw new ArgumentNullException(nameof(configureFormatter)); - } - services.TryAddSingleton(); - return services.ConfigureOptions() - .PostConfigure(o => { - var jsonInputFormatter = o.InputFormatters.OfType().FirstOrDefault(); - if(jsonInputFormatter != null) - { - configureFormatter(jsonInputFormatter); - } - }); - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/IControllerBasedJsonSerializerSettingsBuilder.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/IControllerBasedJsonSerializerSettingsBuilder.cs deleted file mode 100644 index b5e76e7..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/IControllerBasedJsonSerializerSettingsBuilder.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using Newtonsoft.Json; - -public interface IControllerBasedJsonSerializerSettingsBuilder -{ - ControllerBasedJsonInputFormatter WithSerializerSettingsConfigurer(Action configurer); - IControllerBasedJsonSerializerSettingsBuilder ForControllers(params string[] controllerNames); - IControllerBasedJsonSerializerSettingsBuilder ForControllersWithAttribute(); - IControllerBasedJsonSerializerSettingsBuilder ForActionsWithAttribute(); -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/JsonSerializerPooledPolicy.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/JsonSerializerPooledPolicy.cs deleted file mode 100644 index a1945a7..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/JsonSerializerPooledPolicy.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.Extensions.ObjectPool; -using Newtonsoft.Json; - -public class JsonSerializerPooledPolicy : IPooledObjectPolicy -{ - private readonly JsonSerializerSettings _serializerSettings; - - public JsonSerializerPooledPolicy(JsonSerializerSettings serializerSettings) - { - _serializerSettings = serializerSettings; - } - - public JsonSerializer Create() => JsonSerializer.Create(_serializerSettings); - - public bool Return(JsonSerializer serializer) => true; -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/UseWasabiJsonInputFormatterAttribute.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/UseWasabiJsonInputFormatterAttribute.cs deleted file mode 100644 index f755789..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/UseWasabiJsonInputFormatterAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; - -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] -public class UseWasabiJsonInputFormatterAttribute : Attribute -{ -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/WasabiSpecificJsonSerializerFilter.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/WasabiSpecificJsonSerializerFilter.cs deleted file mode 100644 index 214a391..0000000 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/Filters/WasabiSpecificJsonSerializerFilter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Buffers; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Formatters; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using WalletWasabi.WabiSabi.Models.Serialization; - -namespace WalletWasabi.Backend.Filters; - -public class WasabiSpecificJsonSerializerFilter: Attribute, IResultFilter{ - - public void OnResultExecuted(ResultExecutedContext context) - { - } - - public void OnResultExecuting(ResultExecutingContext context) - { - if (context.Result is ObjectResult objectResult) - { - var serializerSettings = new JsonSerializerSettings() - { - Converters = JsonSerializationOptions.Default.Settings.Converters - }; - - var mvoptions = new MvcOptions(); - - var jsonFormatter = new NewtonsoftJsonOutputFormatter( - serializerSettings, - ArrayPool.Shared, mvoptions, new MvcNewtonsoftJsonOptions()); - - objectResult.Formatters.Add(jsonFormatter); - } - } - -} diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabiSabiController.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabiSabiController.cs index f9fc6f8..c9e4f20 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabiSabiController.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabiSabiController.cs @@ -16,9 +16,7 @@ namespace WalletWasabi.Backend.Controllers; [ApiController] [ExceptionTranslate] [LateResponseLoggerFilter] -[WasabiSpecificJsonSerializerFilter] [AllowAnonymous] -[UseWasabiJsonInputFormatter ] [Route("plugins/wabisabi-coordinator/wabisabi")] [Produces("application/json")] public class WabiSabiController : ControllerBase, IWabiSabiApiRequestHandler @@ -34,6 +32,8 @@ public class WabiSabiController : ControllerBase, IWabiSabiApiRequestHandler private IdempotencyRequestCache IdempotencyRequestCache { get; } private Arena Arena { get; } private CoinJoinFeeRateStatStore CoinJoinFeeRateStatStore { get; } + + [HttpPost("status")] public async Task GetStatusAsync(RoundStateRequest request, CancellationToken cancellationToken) @@ -41,7 +41,6 @@ public class WabiSabiController : ControllerBase, IWabiSabiApiRequestHandler var response = await Arena.GetStatusAsync(request, cancellationToken); var medians = CoinJoinFeeRateStatStore.GetDefaultMedians(); var ret = new RoundStateResponse(response.RoundStates, medians); - return ret; } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorConfigController.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorConfigController.cs index 956c447..2fe6d09 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorConfigController.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorConfigController.cs @@ -96,7 +96,7 @@ Reputation risks: as the coordinator, the user may be associated with illegal ac } else { - vm.UriToAdvertise = Request.GetAbsoluteRootUri(); + vm.UriToAdvertise = new Uri( Request.GetAbsoluteRootUri() + "plugins/wabisabi-coordinator"); TempData["SuccessMessage"] = $"Will create nostr events that point to { vm.UriToAdvertise }"; await _wabisabiCoordinatorService.UpdateSettings( vm); return RedirectToAction(nameof(UpdateWabisabiSettings)); diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml index 0587b66..d393488 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Views/WabisabiStore/UpdateWabisabiStoreSettings.cshtml @@ -2,6 +2,7 @@ @using BTCPayServer.Abstractions.Contracts @using NBitcoin @using System.Security.Claims +@using System.Web.NBitcoin @using BTCPayServer @using BTCPayServer.Abstractions.TagHelpers @using BTCPayServer.Client @@ -343,6 +344,8 @@ { continue; } + + var safeName = HttpUtility.UrlEncode(s.Coordinator);
@@ -350,7 +353,7 @@

@coordinator.CoordinatorDisplayName

- @if (coordinator.CoordinatorName != "local" && coordinator.CoordinatorName != "zksnacks") + @if (coordinator.CoordinatorName != "local") { } @@ -369,7 +372,7 @@ var round = coordinator.RoundStateUpdater.RoundStates.Last(pair => pair.Value.BlameOf == uint256.Zero).Value; var roundParameters = round.CoinjoinState.Parameters; -