2021-10-18 05:37:59 +02:00
|
|
|
using BTCPayServer.Configuration;
|
|
|
|
using BTCPayServer.Lightning;
|
|
|
|
using BTCPayServer.Services;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Payments.Lightning
|
|
|
|
{
|
2021-12-31 16:59:02 +09:00
|
|
|
public static class LightningExtensions
|
2021-10-18 05:37:59 +02:00
|
|
|
{
|
|
|
|
|
2024-05-01 10:22:07 +09:00
|
|
|
public static bool IsConfigured(this LightningPaymentMethodConfig supportedPaymentMethod, BTCPayNetwork network, LightningNetworkOptions options)
|
|
|
|
{
|
|
|
|
return supportedPaymentMethod.GetExternalLightningUrl() is not null || (supportedPaymentMethod.IsInternalNode && options.InternalLightningByCryptoCode.ContainsKey(network.CryptoCode));
|
|
|
|
}
|
2024-04-04 16:31:04 +09:00
|
|
|
public static ILightningClient CreateLightningClient(this LightningPaymentMethodConfig supportedPaymentMethod, BTCPayNetwork network, LightningNetworkOptions options, LightningClientFactoryService lightningClientFactory)
|
2021-10-18 05:37:59 +02:00
|
|
|
{
|
|
|
|
var external = supportedPaymentMethod.GetExternalLightningUrl();
|
|
|
|
if (external != null)
|
|
|
|
{
|
|
|
|
return lightningClientFactory.Create(external, network);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-01 10:22:07 +09:00
|
|
|
if (!supportedPaymentMethod.IsInternalNode || !options.InternalLightningByCryptoCode.TryGetValue(network.CryptoCode, out var connectionString))
|
2021-10-18 05:37:59 +02:00
|
|
|
throw new PaymentMethodUnavailableException("No internal node configured");
|
2023-11-21 10:55:02 +01:00
|
|
|
return connectionString;
|
2021-10-18 05:37:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|