2021-06-14 02:19:52 -07:00
|
|
|
#nullable enable
|
2020-06-28 21:44:35 -05:00
|
|
|
using System;
|
2018-08-30 11:50:39 +09:00
|
|
|
using BTCPayServer.Lightning;
|
2021-03-02 11:11:58 +09:00
|
|
|
using Newtonsoft.Json;
|
2018-02-26 00:48:12 +09:00
|
|
|
|
|
|
|
namespace BTCPayServer.Payments.Lightning
|
|
|
|
{
|
|
|
|
public class LightningSupportedPaymentMethod : ISupportedPaymentMethod
|
|
|
|
{
|
2021-03-02 11:11:58 +09:00
|
|
|
public const string InternalNode = "Internal Node";
|
2021-06-14 18:22:00 +09:00
|
|
|
public string CryptoCode { get; set; } = string.Empty;
|
2018-02-26 00:48:12 +09:00
|
|
|
|
2021-03-02 11:11:58 +09:00
|
|
|
[JsonIgnore]
|
2018-07-01 21:41:06 +09:00
|
|
|
public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike);
|
|
|
|
|
2018-03-21 00:31:19 +09:00
|
|
|
[Obsolete("Use Get/SetLightningUrl")]
|
2021-03-02 11:11:58 +09:00
|
|
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2021-06-14 02:19:52 -07:00
|
|
|
public string? LightningConnectionString { get; set; }
|
2018-07-01 15:45:08 +09:00
|
|
|
|
2021-08-16 10:07:49 +02:00
|
|
|
public bool DisableBOLT11PaymentOption { get; set; } = false;
|
|
|
|
|
2021-06-14 02:19:52 -07:00
|
|
|
public LightningConnectionString? GetExternalLightningUrl()
|
2018-02-26 00:48:12 +09:00
|
|
|
{
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2018-07-01 15:45:08 +09:00
|
|
|
if (!string.IsNullOrEmpty(LightningConnectionString))
|
|
|
|
{
|
2018-08-30 11:50:39 +09:00
|
|
|
if (!BTCPayServer.Lightning.LightningConnectionString.TryParse(LightningConnectionString, false, out var connectionString, out var error))
|
2018-07-01 15:45:08 +09:00
|
|
|
{
|
|
|
|
throw new FormatException(error);
|
|
|
|
}
|
|
|
|
return connectionString;
|
|
|
|
}
|
|
|
|
else
|
2021-03-02 11:11:58 +09:00
|
|
|
return null;
|
2018-02-26 00:48:12 +09:00
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:31:19 +09:00
|
|
|
public void SetLightningUrl(LightningConnectionString connectionString)
|
2018-02-26 00:48:12 +09:00
|
|
|
{
|
2021-12-28 17:39:54 +09:00
|
|
|
ArgumentNullException.ThrowIfNull(connectionString);
|
2018-02-26 00:48:12 +09:00
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2018-07-01 15:45:08 +09:00
|
|
|
LightningConnectionString = connectionString.ToString();
|
2018-02-26 00:48:12 +09:00
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
}
|
2021-03-02 11:11:58 +09:00
|
|
|
|
|
|
|
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)]
|
2021-06-14 02:19:52 -07:00
|
|
|
public string? InternalNodeRef { get; set; }
|
2021-03-02 11:11:58 +09:00
|
|
|
[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
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 00:48:12 +09:00
|
|
|
}
|
|
|
|
}
|