From 3d21d2724efb27ea4a2c511019ae72c6e2d9c2b5 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Mon, 14 Jun 2021 02:19:52 -0700 Subject: [PATCH] Fix bug with LN payment method API endpoint throwing 500 (#2567) close #2566 --- .../StoreLightningNetworkPaymentMethodsController.cs | 10 +++++++--- .../Lightning/LightningSupportedPaymentMethod.cs | 11 +++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/BTCPayServer/Controllers/GreenField/StoreLightningNetworkPaymentMethodsController.cs b/BTCPayServer/Controllers/GreenField/StoreLightningNetworkPaymentMethodsController.cs index e7fc926d9..1377a17b5 100644 --- a/BTCPayServer/Controllers/GreenField/StoreLightningNetworkPaymentMethodsController.cs +++ b/BTCPayServer/Controllers/GreenField/StoreLightningNetworkPaymentMethodsController.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -11,7 +12,6 @@ using BTCPayServer.Lightning; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; using BTCPayServer.Security; -using BTCPayServer.Services; using BTCPayServer.Services.Stores; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -56,8 +56,12 @@ namespace BTCPayServer.Controllers.GreenField .Where((method) => method.PaymentId.PaymentType == PaymentTypes.LightningLike) .OfType() .Select(paymentMethod => - new LightningNetworkPaymentMethodData(paymentMethod.PaymentId.CryptoCode, - paymentMethod.GetExternalLightningUrl().ToString(), !excludedPaymentMethods.Match(paymentMethod.PaymentId))) + new LightningNetworkPaymentMethodData( + paymentMethod.PaymentId.CryptoCode, + paymentMethod.GetExternalLightningUrl()?.ToString() ?? paymentMethod.GetDisplayableConnectionString(), + !excludedPaymentMethods.Match(paymentMethod.PaymentId) + ) + ) .Where((result) => !enabledOnly || result.Enabled) .ToList() ); diff --git a/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs b/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs index ac0592af8..30331aee9 100644 --- a/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs +++ b/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs @@ -1,24 +1,23 @@ +#nullable enable using System; -using System.Collections.Generic; using BTCPayServer.Lightning; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace BTCPayServer.Payments.Lightning { public class LightningSupportedPaymentMethod : ISupportedPaymentMethod { public const string InternalNode = "Internal Node"; - public string CryptoCode { get; set; } + public string? CryptoCode { get; set; } [JsonIgnore] public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike); [Obsolete("Use Get/SetLightningUrl")] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string LightningConnectionString { get; set; } + public string? LightningConnectionString { get; set; } - public LightningConnectionString GetExternalLightningUrl() + public LightningConnectionString? GetExternalLightningUrl() { #pragma warning disable CS0618 // Type or member is obsolete if (!string.IsNullOrEmpty(LightningConnectionString)) @@ -64,7 +63,7 @@ namespace BTCPayServer.Payments.Lightning } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string InternalNodeRef { get; set; } + public string? InternalNodeRef { get; set; } [JsonIgnore] public bool IsInternalNode {