From c17572c76f7309d9c3292e5c1ec3f9538f8fbf63 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 26 Apr 2023 18:24:46 +0900 Subject: [PATCH] Clip configuration values for payout processors --- .../PayoutProcessors/BaseAutomatedPayoutProcessor.cs | 11 +++++++++++ .../UILightningAutomatedPayoutProcessorsController.cs | 5 ++++- .../UIOnChainAutomatedPayoutProcessorsController.cs | 5 +++++ .../Configure.cshtml | 3 ++- .../Configure.cshtml | 4 +++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs b/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs index 3eac03b41..cf9e0f7b9 100644 --- a/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs +++ b/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs @@ -16,6 +16,11 @@ using PayoutProcessorData = BTCPayServer.Data.PayoutProcessorData; namespace BTCPayServer.PayoutProcessors; +public class AutomatedPayoutConstants +{ + public const double MinIntervalMinutes = 10.0; + public const double MaxIntervalMinutes = 60.0; +} public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T : AutomatedPayoutBlob { protected readonly StoreRepository _storeRepository; @@ -86,6 +91,12 @@ public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T new AfterPayoutFilterData(store, paymentMethod, payouts)); } } + + // Clip interval + if (blob.Interval < TimeSpan.FromMinutes(AutomatedPayoutConstants.MinIntervalMinutes)) + blob.Interval = TimeSpan.FromMinutes(AutomatedPayoutConstants.MinIntervalMinutes); + if (blob.Interval > TimeSpan.FromMinutes(AutomatedPayoutConstants.MaxIntervalMinutes)) + blob.Interval = TimeSpan.FromMinutes(AutomatedPayoutConstants.MaxIntervalMinutes); await Task.Delay(blob.Interval, CancellationToken); } diff --git a/BTCPayServer/PayoutProcessors/Lightning/UILightningAutomatedPayoutProcessorsController.cs b/BTCPayServer/PayoutProcessors/Lightning/UILightningAutomatedPayoutProcessorsController.cs index 7a62599d3..99730969b 100644 --- a/BTCPayServer/PayoutProcessors/Lightning/UILightningAutomatedPayoutProcessorsController.cs +++ b/BTCPayServer/PayoutProcessors/Lightning/UILightningAutomatedPayoutProcessorsController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Abstractions.Constants; @@ -66,6 +67,8 @@ public class UILightningAutomatedPayoutProcessorsController : Controller [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] public async Task Configure(string storeId, string cryptoCode, LightningTransferViewModel automatedTransferBlob) { + if (!ModelState.IsValid) + return View(automatedTransferBlob); if (!_lightningAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id => id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase))) { @@ -120,7 +123,7 @@ public class UILightningAutomatedPayoutProcessorsController : Controller { IntervalMinutes = blob.Interval.TotalMinutes; } - + [Range(AutomatedPayoutConstants.MinIntervalMinutes, AutomatedPayoutConstants.MaxIntervalMinutes)] public double IntervalMinutes { get; set; } public AutomatedPayoutBlob ToBlob() diff --git a/BTCPayServer/PayoutProcessors/OnChain/UIOnChainAutomatedPayoutProcessorsController.cs b/BTCPayServer/PayoutProcessors/OnChain/UIOnChainAutomatedPayoutProcessorsController.cs index a6f977a68..34cf41f2e 100644 --- a/BTCPayServer/PayoutProcessors/OnChain/UIOnChainAutomatedPayoutProcessorsController.cs +++ b/BTCPayServer/PayoutProcessors/OnChain/UIOnChainAutomatedPayoutProcessorsController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Abstractions.Constants; @@ -79,6 +80,8 @@ public class UIOnChainAutomatedPayoutProcessorsController : Controller [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] public async Task Configure(string storeId, string cryptoCode, OnChainTransferViewModel automatedTransferBlob) { + if (!ModelState.IsValid) + return View(automatedTransferBlob); if (!_onChainAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id => id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase))) { @@ -135,8 +138,10 @@ public class UIOnChainAutomatedPayoutProcessorsController : Controller FeeTargetBlock = blob.FeeTargetBlock; } + [Range(1, 1000)] public int FeeTargetBlock { get; set; } + [Range(AutomatedPayoutConstants.MinIntervalMinutes, AutomatedPayoutConstants.MaxIntervalMinutes)] public double IntervalMinutes { get; set; } public OnChainAutomatedPayoutBlob ToBlob() diff --git a/BTCPayServer/Views/UILightningAutomatedPayoutProcessors/Configure.cshtml b/BTCPayServer/Views/UILightningAutomatedPayoutProcessors/Configure.cshtml index 245bd475f..a4524ba3d 100644 --- a/BTCPayServer/Views/UILightningAutomatedPayoutProcessors/Configure.cshtml +++ b/BTCPayServer/Views/UILightningAutomatedPayoutProcessors/Configure.cshtml @@ -1,4 +1,4 @@ -@using BTCPayServer.Abstractions.Extensions +@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Views.Stores @using Microsoft.AspNetCore.Mvc.TagHelpers @model BTCPayServer.PayoutProcessors.Lightning.UILightningAutomatedPayoutProcessorsController.LightningTransferViewModel @@ -23,6 +23,7 @@
minutes +
diff --git a/BTCPayServer/Views/UIOnChainAutomatedPayoutProcessors/Configure.cshtml b/BTCPayServer/Views/UIOnChainAutomatedPayoutProcessors/Configure.cshtml index 6f15b4d75..cb7eff7cd 100644 --- a/BTCPayServer/Views/UIOnChainAutomatedPayoutProcessors/Configure.cshtml +++ b/BTCPayServer/Views/UIOnChainAutomatedPayoutProcessors/Configure.cshtml @@ -1,4 +1,4 @@ -@using BTCPayServer.Abstractions.Extensions +@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Views.Stores @model BTCPayServer.PayoutProcessors.OnChain.UIOnChainAutomatedPayoutProcessorsController.OnChainTransferViewModel @{ @@ -22,6 +22,7 @@
minutes +
@@ -29,6 +30,7 @@
blocks +