btcpayserver/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs
d11n d5d0be5824
Code formatting updates (#4502)
* Editorconfig: Add space_before_self_closing setting

This was a difference between the way dotnet-format and Rider format code. See https://www.jetbrains.com/help/rider/EditorConfig_Index.html

* Editorconfig: Keep 4 spaces indentation for Swagger JSON files

They are all formatted that way, let's keep it like that.

* Apply dotnet-format, mostly white-space related changes
2023-01-06 22:18:07 +09:00

76 lines
2.8 KiB
C#

#nullable enable
using System;
using BTCPayServer.Lightning;
using Newtonsoft.Json;
namespace BTCPayServer.Payments.Lightning
{
public class LightningSupportedPaymentMethod : ISupportedPaymentMethod
{
public const string InternalNode = "Internal Node";
public string CryptoCode { get; set; } = string.Empty;
[JsonIgnore]
public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike);
[Obsolete("Use Get/SetLightningUrl")]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string? LightningConnectionString { get; set; }
public bool DisableBOLT11PaymentOption { get; set; } = false;
public LightningConnectionString? GetExternalLightningUrl()
{
#pragma warning disable CS0618 // Type or member is obsolete
if (string.IsNullOrEmpty(LightningConnectionString))
return null;
if (!BTCPayServer.Lightning.LightningConnectionString.TryParse(LightningConnectionString, false, out var connectionString, out var error))
{
throw new FormatException(error);
}
return connectionString;
#pragma warning restore CS0618 // Type or member is obsolete
}
public void SetLightningUrl(LightningConnectionString connectionString)
{
ArgumentNullException.ThrowIfNull(connectionString);
#pragma warning disable CS0618 // Type or member is obsolete
LightningConnectionString = connectionString.ToString();
#pragma warning restore CS0618 // Type or member is obsolete
}
public string GetDisplayableConnectionString()
{
#pragma warning disable CS0618 // Type or member is obsolete
if (!string.IsNullOrEmpty(LightningConnectionString) &&
BTCPayServer.Lightning.LightningConnectionString.TryParse(LightningConnectionString, false, out var conn))
return conn.ToString();
#pragma warning restore CS0618 // Type or member is obsolete
if (InternalNodeRef is string s)
return s;
return "Invalid connection string";
}
public void SetInternalNode()
{
#pragma warning disable CS0618 // Type or member is obsolete
LightningConnectionString = null;
InternalNodeRef = InternalNode;
#pragma warning restore CS0618 // Type or member is obsolete
}
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string? InternalNodeRef { get; set; }
[JsonIgnore]
public bool IsInternalNode
{
get
{
#pragma warning disable CS0618 // Type or member is obsolete
return InternalNodeRef == InternalNode;
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
}