2020-06-29 04:44:35 +02:00
|
|
|
using System;
|
2019-04-11 05:41:38 +02:00
|
|
|
using System.Net.Http;
|
|
|
|
using BTCPayServer.Lightning;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services
|
|
|
|
{
|
|
|
|
public class LightningClientFactoryService
|
|
|
|
{
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
|
|
|
|
public LightningClientFactoryService(IHttpClientFactory httpClientFactory)
|
|
|
|
{
|
|
|
|
_httpClientFactory = httpClientFactory;
|
|
|
|
}
|
|
|
|
|
2022-06-13 09:22:26 +02:00
|
|
|
public static string OnionNamedClient { get; set; } = "lightning.onion";
|
|
|
|
|
2019-04-11 05:41:38 +02:00
|
|
|
public ILightningClient Create(LightningConnectionString lightningConnectionString, BTCPayNetwork network)
|
|
|
|
{
|
2021-12-28 09:39:54 +01:00
|
|
|
ArgumentNullException.ThrowIfNull(lightningConnectionString);
|
|
|
|
ArgumentNullException.ThrowIfNull(network);
|
2022-06-13 09:22:26 +02:00
|
|
|
|
|
|
|
return new LightningClientFactory(network.NBitcoinNetwork)
|
2019-04-11 05:41:38 +02:00
|
|
|
{
|
2022-06-13 09:22:26 +02:00
|
|
|
HttpClient = _httpClientFactory.CreateClient(lightningConnectionString.BaseUri.IsOnion()
|
|
|
|
? OnionNamedClient
|
|
|
|
: $"{network.CryptoCode}: Lightning client")
|
2019-04-11 05:41:38 +02:00
|
|
|
}.Create(lightningConnectionString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|