From 3d57b944cad9588abe0e67a5cc788bddb6c74604 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Fri, 19 May 2023 08:41:21 +0900 Subject: [PATCH] Fix a bunch of minor bugs (#4983) --- .../GreenField/GreenfieldLightningNodeApiController.cs | 4 ++-- .../GreenField/GreenfieldPullPaymentController.cs | 2 +- .../Controllers/GreenField/GreenfieldStoresController.cs | 3 +-- BTCPayServer/Controllers/UILNURLController.cs | 5 ----- BTCPayServer/Controllers/UIStoresController.cs | 9 ++++++--- BTCPayServer/HostedServices/BitpayIPNSender.cs | 1 - BTCPayServer/HostedServices/InvoiceWatcher.cs | 3 ++- BTCPayServer/Hosting/BTCpayMiddleware.cs | 3 --- BTCPayServer/Services/Invoices/InvoiceRepository.cs | 5 ----- 9 files changed, 12 insertions(+), 23 deletions(-) diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldLightningNodeApiController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldLightningNodeApiController.cs index 73432b122..ee33803af 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldLightningNodeApiController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldLightningNodeApiController.cs @@ -133,7 +133,7 @@ namespace BTCPayServer.Controllers.Greenfield "A valid node info was not provided to open a channel with"); } - if (request.ChannelAmount == null) + if (request?.ChannelAmount is null) { ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount is missing"); } @@ -142,7 +142,7 @@ namespace BTCPayServer.Controllers.Greenfield ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount must be more than 0"); } - if (request.FeeRate == null) + if (request?.FeeRate is null) { ModelState.AddModelError(nameof(request.FeeRate), "FeeRate is missing"); } diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldPullPaymentController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldPullPaymentController.cs index d554e83b4..d9db98351 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldPullPaymentController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldPullPaymentController.cs @@ -352,7 +352,7 @@ namespace BTCPayServer.Controllers.Greenfield [Authorize(Policy = Policies.CanCreateNonApprovedPullPayments, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] public async Task CreatePayoutThroughStore(string storeId, CreatePayoutThroughStoreRequest request) { - if (request.Approved is true) + if (request?.Approved is true) { if (!(await _authorizationService.AuthorizeAsync(User, null, new PolicyRequirement(Policies.CanCreatePullPayments))).Succeeded) diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs index 2d5ce2ef1..9e8ef7058 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs @@ -164,7 +164,6 @@ namespace BTCPayServer.Controllers.Greenfield { var blob = model.GetStoreBlob(); model.StoreName = restModel.Name; - model.StoreName = restModel.Name; model.StoreWebsite = restModel.Website; model.SpeedPolicy = restModel.SpeedPolicy; model.SetDefaultPaymentId(defaultPaymentMethod); @@ -240,7 +239,7 @@ namespace BTCPayServer.Controllers.Greenfield ModelState.AddModelError(nameof(request.DisplayExpirationTimer), "DisplayExpirationTimer can only be between 1 and 34560 mins"); if (request.MonitoringExpiration < TimeSpan.FromMinutes(10) && request.MonitoringExpiration > TimeSpan.FromMinutes(60 * 24 * 24)) ModelState.AddModelError(nameof(request.MonitoringExpiration), "MonitoringExpiration can only be between 10 and 34560 mins"); - if (request.PaymentTolerance < 0 && request.PaymentTolerance > 100) + if (request.PaymentTolerance < 0 || request.PaymentTolerance > 100) ModelState.AddModelError(nameof(request.PaymentTolerance), "PaymentTolerance can only be between 0 and 100 percent"); if (request.PaymentMethodCriteria?.Any() is true) diff --git a/BTCPayServer/Controllers/UILNURLController.cs b/BTCPayServer/Controllers/UILNURLController.cs index 4d41a4735..ae8ca1c13 100644 --- a/BTCPayServer/Controllers/UILNURLController.cs +++ b/BTCPayServer/Controllers/UILNURLController.cs @@ -361,11 +361,6 @@ namespace BTCPayServer public ConcurrentDictionary Items { get; } = new(); public ConcurrentDictionary StoreToItemMap { get; } = new(); - - public override string ToString() - { - return null; - } } [HttpGet("~/.well-known/lnurlp/{username}")] diff --git a/BTCPayServer/Controllers/UIStoresController.cs b/BTCPayServer/Controllers/UIStoresController.cs index 301c5ed19..da92b07c5 100644 --- a/BTCPayServer/Controllers/UIStoresController.cs +++ b/BTCPayServer/Controllers/UIStoresController.cs @@ -889,8 +889,11 @@ namespace BTCPayServer.Controllers var userId = GetUserId(); if (userId == null) return Challenge(AuthenticationSchemes.Cookie); - storeId = model.StoreId; - var store = CurrentStore ?? await _Repo.FindStore(storeId, userId); + var store = model.StoreId switch + { + null => CurrentStore, + string id => await _Repo.FindStore(storeId, userId) + }; if (store == null) return Challenge(AuthenticationSchemes.Cookie); var tokenRequest = new TokenRequest() @@ -908,7 +911,7 @@ namespace BTCPayServer.Controllers Id = tokenRequest.PairingCode, Label = model.Label, }); - await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId); + await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, store.Id); pairingCode = tokenRequest.PairingCode; } else diff --git a/BTCPayServer/HostedServices/BitpayIPNSender.cs b/BTCPayServer/HostedServices/BitpayIPNSender.cs index 513edd423..37b26ef47 100644 --- a/BTCPayServer/HostedServices/BitpayIPNSender.cs +++ b/BTCPayServer/HostedServices/BitpayIPNSender.cs @@ -261,7 +261,6 @@ namespace BTCPayServer.HostedServices { if (e.Name == InvoiceEvent.Expired || e.Name == InvoiceEvent.PaidInFull || - e.Name == InvoiceEvent.FailedToConfirm || e.Name == InvoiceEvent.MarkedInvalid || e.Name == InvoiceEvent.MarkedCompleted || e.Name == InvoiceEvent.FailedToConfirm || diff --git a/BTCPayServer/HostedServices/InvoiceWatcher.cs b/BTCPayServer/HostedServices/InvoiceWatcher.cs index f92b0df65..f2f721ff8 100644 --- a/BTCPayServer/HostedServices/InvoiceWatcher.cs +++ b/BTCPayServer/HostedServices/InvoiceWatcher.cs @@ -380,7 +380,8 @@ namespace BTCPayServer.HostedServices if ((onChainPaymentData.ConfirmationCount < network.MaxTrackedConfirmation && payment.Accounted) && (onChainPaymentData.Legacy || invoice.MonitoringExpiration < DateTimeOffset.UtcNow)) { - var transactionResult = await _explorerClientProvider.GetExplorerClient(payment.GetCryptoCode())?.GetTransactionAsync(onChainPaymentData.Outpoint.Hash); + var client = _explorerClientProvider.GetExplorerClient(payment.GetCryptoCode()); + var transactionResult = client is null ? null : await client.GetTransactionAsync(onChainPaymentData.Outpoint.Hash); var confirmationCount = transactionResult?.Confirmations ?? 0; onChainPaymentData.ConfirmationCount = confirmationCount; payment.SetCryptoPaymentData(onChainPaymentData); diff --git a/BTCPayServer/Hosting/BTCpayMiddleware.cs b/BTCPayServer/Hosting/BTCpayMiddleware.cs index 3d5bcd810..8ab03bacd 100644 --- a/BTCPayServer/Hosting/BTCpayMiddleware.cs +++ b/BTCPayServer/Hosting/BTCpayMiddleware.cs @@ -60,9 +60,6 @@ namespace BTCPayServer.Hosting { httpContext.Response.SetHeader("Access-Control-Allow-Origin", "*"); httpContext.SetBitpayAuth(bitpayAuth); - } - if (isBitpayAPI) - { await _Next(httpContext); return; } diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index fdd2b2326..a7d022177 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -430,11 +430,6 @@ namespace BTCPayServer.Services.Invoices { using var context = _applicationDbContextFactory.CreateContext(); var items = context.Invoices.Where(a => invoiceIds.Contains(a.Id)); - if (items == null) - { - return; - } - foreach (InvoiceData invoice in items) { invoice.Archived = archive;