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
|
|
|
|
2023-11-21 10:55:02 +01:00
|
|
|
public string? GetExternalLightningUrl()
|
2018-02-26 00:48:12 +09:00
|
|
|
{
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2023-01-06 14:18:07 +01:00
|
|
|
if (string.IsNullOrEmpty(LightningConnectionString))
|
|
|
|
return null;
|
2023-11-21 10:55:02 +01:00
|
|
|
// if (!BTCPayServer.Lightning.LightningConnectionString.TryParse(LightningConnectionString, false, out var connectionString, out var error))
|
|
|
|
// {
|
|
|
|
// throw new FormatException(error);
|
|
|
|
// }
|
|
|
|
return LightningConnectionString;
|
2018-02-26 00:48:12 +09:00
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
}
|
|
|
|
|
2023-12-20 11:26:24 +01:00
|
|
|
public void SetLightningUrl(ILightningClient client)
|
2018-02-26 00:48:12 +09:00
|
|
|
{
|
2023-12-20 11:26:24 +01:00
|
|
|
ArgumentNullException.ThrowIfNull(client);
|
2018-02-26 00:48:12 +09:00
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2023-12-20 11:26:24 +01:00
|
|
|
LightningConnectionString = client.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
|
2023-11-21 10:55:02 +01:00
|
|
|
if (!string.IsNullOrEmpty(LightningConnectionString))
|
|
|
|
return LightningConnectionString;
|
2021-03-02 11:11:58 +09:00
|
|
|
#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
|
|
|
}
|
|
|
|
}
|