Lightning: Fix connection display name in LN settings (#5569)

* Lightning: Fix connection display name in LN settings

Builds on btcpayserver/BTCPayServer.Lightning#153.

* Upgrade Lightning lib
This commit is contained in:
d11n 2023-12-20 11:26:24 +01:00 committed by GitHub
parent 93ab219124
commit 5114a3a2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

View File

@ -94,20 +94,21 @@ namespace BTCPayServer
public static string GetDisplayName(this ILightningClient client)
{
LightningConnectionStringHelper.ExtractValues(client.ToString(), out var type);
var field = typeof(LightningConnectionType).GetField(type, BindingFlags.Public | BindingFlags.Static);
var lncType = typeof(LightningConnectionType);
var fields = lncType.GetFields(BindingFlags.Public | BindingFlags.Static);
var field = fields.FirstOrDefault(f => f.GetValue(lncType)?.ToString() == type);
if (field == null) return type;
DisplayAttribute attr = field.GetCustomAttribute<DisplayAttribute>();
return attr?.Name ?? type;
}
public static bool IsSafe(this ILightningClient connectionString)
public static bool IsSafe(this ILightningClient client)
{
var kv = LightningConnectionStringHelper.ExtractValues(connectionString.ToString(), out var type);
if (kv.TryGetValue("cookiefilepath", out var cookieFilePath) ||
kv.TryGetValue("macaroondirectorypath", out var macaroonDirectoryPath) ||
kv.TryGetValue("macaroonfilepath", out var macaroonFilePath) )
var kv = LightningConnectionStringHelper.ExtractValues(client.ToString(), out var type);
if (kv.TryGetValue("cookiefilepath", out _) ||
kv.TryGetValue("macaroondirectorypath", out _) ||
kv.TryGetValue("macaroonfilepath", out _) )
return false;
if (!kv.TryGetValue("server", out var server))
@ -117,7 +118,7 @@ namespace BTCPayServer
var uri = new Uri(server, UriKind.Absolute);
if (uri.Scheme.Equals("unix", StringComparison.OrdinalIgnoreCase))
return false;
if (!Utils.TryParseEndpoint(uri.DnsSafeHost, 80, out var endpoint))
if (!Utils.TryParseEndpoint(uri.DnsSafeHost, 80, out _))
return false;
return !IsLocalNetwork(uri.DnsSafeHost);
}

View File

@ -30,11 +30,11 @@ namespace BTCPayServer.Payments.Lightning
#pragma warning restore CS0618 // Type or member is obsolete
}
public void SetLightningUrl(ILightningClient connectionString)
public void SetLightningUrl(ILightningClient client)
{
ArgumentNullException.ThrowIfNull(connectionString);
ArgumentNullException.ThrowIfNull(client);
#pragma warning disable CS0618 // Type or member is obsolete
LightningConnectionString = connectionString.ToString();
LightningConnectionString = client.ToString();
#pragma warning restore CS0618 // Type or member is obsolete
}

View File

@ -20,7 +20,7 @@
@try
{
var client = LightningClientFactoryService.Create(Model.ConnectionString, NetworkProvider.GetNetwork<BTCPayNetwork>(Model.CryptoCode));
client.GetDisplayName();
<span>@client.GetDisplayName()</span>
var uri = client.GetServerUri();
if (uri is not null)
{

View File

@ -20,7 +20,7 @@
@try
{
var client = LightningClientFactoryService.Create(Model.ConnectionString, NetworkProvider.GetNetwork<BTCPayNetwork>(Model.CryptoCode));
client.GetDisplayName();
<span>@client.GetDisplayName()</span>
var uri = client.GetServerUri();
if (uri is not null)
{