btcpayserver/BTCPayServer/Services/LightningClientFactoryService.cs
Andrew Camilleri 4a0f10ea99
Support LN connection string with onion http client (#3845)
I'm not sure if onion based ln conenction strings ever worked in btcpay? closes #1648
2022-06-13 16:22:26 +09:00

32 lines
1.0 KiB
C#

using System;
using System.Net.Http;
using BTCPayServer.Lightning;
namespace BTCPayServer.Services
{
public class LightningClientFactoryService
{
private readonly IHttpClientFactory _httpClientFactory;
public LightningClientFactoryService(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public static string OnionNamedClient { get; set; } = "lightning.onion";
public ILightningClient Create(LightningConnectionString lightningConnectionString, BTCPayNetwork network)
{
ArgumentNullException.ThrowIfNull(lightningConnectionString);
ArgumentNullException.ThrowIfNull(network);
return new LightningClientFactory(network.NBitcoinNetwork)
{
HttpClient = _httpClientFactory.CreateClient(lightningConnectionString.BaseUri.IsOnion()
? OnionNamedClient
: $"{network.CryptoCode}: Lightning client")
}.Create(lightningConnectionString);
}
}
}