Do not provide lnurl method if ln node is dead

fixes #3541
This commit is contained in:
Kukks
2023-03-21 13:48:25 +01:00
parent 5f96d17b8c
commit 55565f1718

View File

@@ -1,6 +1,8 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Client.Models;
using BTCPayServer.Configuration;
@@ -20,16 +22,19 @@ namespace BTCPayServer.Payments.Lightning
private readonly BTCPayNetworkProvider _networkProvider;
private readonly DisplayFormatter _displayFormatter;
private readonly LightningLikePaymentHandler _lightningLikePaymentHandler;
private readonly LightningClientFactoryService _lightningClientFactoryService;
public LNURLPayPaymentHandler(
BTCPayNetworkProvider networkProvider,
DisplayFormatter displayFormatter,
IOptions<LightningNetworkOptions> options,
LightningLikePaymentHandler lightningLikePaymentHandler)
LightningLikePaymentHandler lightningLikePaymentHandler,
LightningClientFactoryService lightningClientFactoryService)
{
_networkProvider = networkProvider;
_displayFormatter = displayFormatter;
_lightningLikePaymentHandler = lightningLikePaymentHandler;
_lightningClientFactoryService = lightningClientFactoryService;
Options = options;
}
@@ -62,6 +67,16 @@ namespace BTCPayServer.Payments.Lightning
{
throw new PaymentMethodUnavailableException("LNURL requires a lightning node to be configured for the store.");
}
using var cts = new CancellationTokenSource(5000);
try
{
var client = lnSupported.CreateLightningClient(network, Options.Value, _lightningClientFactoryService);
await client.GetInfo(cts.Token);
}
catch (OperationCanceledException) when (cts.IsCancellationRequested)
{
throw new PaymentMethodUnavailableException("The lightning node did not reply in a timely manner");
}
return new LNURLPayPaymentMethodDetails()
{