btcpayserver/BTCPayServer/Services/LightningClientFactoryService.cs

32 lines
1.0 KiB
C#
Raw Normal View History

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;
}
public static string OnionNamedClient { get; set; } = "lightning.onion";
2019-04-11 05:41:38 +02:00
public ILightningClient Create(LightningConnectionString lightningConnectionString, BTCPayNetwork network)
{
ArgumentNullException.ThrowIfNull(lightningConnectionString);
ArgumentNullException.ThrowIfNull(network);
return new LightningClientFactory(network.NBitcoinNetwork)
2019-04-11 05:41:38 +02:00
{
HttpClient = _httpClientFactory.CreateClient(lightningConnectionString.BaseUri.IsOnion()
? OnionNamedClient
: $"{network.CryptoCode}: Lightning client")
2019-04-11 05:41:38 +02:00
}.Create(lightningConnectionString);
}
}
}