From 4a0f10ea999a3fb3c8a3e6af6460acc2a7088002 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Mon, 13 Jun 2022 09:22:26 +0200 Subject: [PATCH] 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 --- BTCPayServer/Hosting/BTCPayServerServices.cs | 2 ++ BTCPayServer/Services/LightningClientFactoryService.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index 274c3131c..0b2dd2c65 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -107,6 +107,8 @@ namespace BTCPayServer.Hosting services.AddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); + services.AddHttpClient(LightningClientFactoryService.OnionNamedClient) + .ConfigurePrimaryHttpMessageHandler(); services.TryAddSingleton(); services.TryAddSingleton(o => o.GetRequiredService>().Value); diff --git a/BTCPayServer/Services/LightningClientFactoryService.cs b/BTCPayServer/Services/LightningClientFactoryService.cs index 9f3e18f73..556949fcc 100644 --- a/BTCPayServer/Services/LightningClientFactoryService.cs +++ b/BTCPayServer/Services/LightningClientFactoryService.cs @@ -13,13 +13,18 @@ namespace BTCPayServer.Services _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 Lightning.LightningClientFactory(network.NBitcoinNetwork) + + return new LightningClientFactory(network.NBitcoinNetwork) { - HttpClient = _httpClientFactory.CreateClient($"{network.CryptoCode}: Lightning client") + HttpClient = _httpClientFactory.CreateClient(lightningConnectionString.BaseUri.IsOnion() + ? OnionNamedClient + : $"{network.CryptoCode}: Lightning client") }.Create(lightningConnectionString); } }