Fix bug with LN payment method API endpoint throwing 500 (#2567)

close #2566
This commit is contained in:
Umar Bolatov 2021-06-14 02:19:52 -07:00 committed by GitHub
parent df64a93808
commit 3d21d2724e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View file

@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,7 +12,6 @@ using BTCPayServer.Lightning;
using BTCPayServer.Payments; using BTCPayServer.Payments;
using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.Lightning;
using BTCPayServer.Security; using BTCPayServer.Security;
using BTCPayServer.Services;
using BTCPayServer.Services.Stores; using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -56,8 +56,12 @@ namespace BTCPayServer.Controllers.GreenField
.Where((method) => method.PaymentId.PaymentType == PaymentTypes.LightningLike) .Where((method) => method.PaymentId.PaymentType == PaymentTypes.LightningLike)
.OfType<LightningSupportedPaymentMethod>() .OfType<LightningSupportedPaymentMethod>()
.Select(paymentMethod => .Select(paymentMethod =>
new LightningNetworkPaymentMethodData(paymentMethod.PaymentId.CryptoCode, new LightningNetworkPaymentMethodData(
paymentMethod.GetExternalLightningUrl().ToString(), !excludedPaymentMethods.Match(paymentMethod.PaymentId))) paymentMethod.PaymentId.CryptoCode,
paymentMethod.GetExternalLightningUrl()?.ToString() ?? paymentMethod.GetDisplayableConnectionString(),
!excludedPaymentMethods.Match(paymentMethod.PaymentId)
)
)
.Where((result) => !enabledOnly || result.Enabled) .Where((result) => !enabledOnly || result.Enabled)
.ToList() .ToList()
); );

View file

@ -1,24 +1,23 @@
#nullable enable
using System; using System;
using System.Collections.Generic;
using BTCPayServer.Lightning; using BTCPayServer.Lightning;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Payments.Lightning namespace BTCPayServer.Payments.Lightning
{ {
public class LightningSupportedPaymentMethod : ISupportedPaymentMethod public class LightningSupportedPaymentMethod : ISupportedPaymentMethod
{ {
public const string InternalNode = "Internal Node"; public const string InternalNode = "Internal Node";
public string CryptoCode { get; set; } public string? CryptoCode { get; set; }
[JsonIgnore] [JsonIgnore]
public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike); public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike);
[Obsolete("Use Get/SetLightningUrl")] [Obsolete("Use Get/SetLightningUrl")]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] [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 #pragma warning disable CS0618 // Type or member is obsolete
if (!string.IsNullOrEmpty(LightningConnectionString)) if (!string.IsNullOrEmpty(LightningConnectionString))
@ -64,7 +63,7 @@ namespace BTCPayServer.Payments.Lightning
} }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string InternalNodeRef { get; set; } public string? InternalNodeRef { get; set; }
[JsonIgnore] [JsonIgnore]
public bool IsInternalNode public bool IsInternalNode
{ {