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
This commit is contained in:
Andrew Camilleri 2022-06-13 09:22:26 +02:00 committed by GitHub
parent 9a24e4ade1
commit 4a0f10ea99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -107,6 +107,8 @@ namespace BTCPayServer.Hosting
services.AddSingleton<ISwaggerProvider, DefaultSwaggerProvider>(); services.AddSingleton<ISwaggerProvider, DefaultSwaggerProvider>();
services.TryAddSingleton<SocketFactory>(); services.TryAddSingleton<SocketFactory>();
services.TryAddSingleton<LightningClientFactoryService>(); services.TryAddSingleton<LightningClientFactoryService>();
services.AddHttpClient(LightningClientFactoryService.OnionNamedClient)
.ConfigurePrimaryHttpMessageHandler<Socks5HttpClientHandler>();
services.TryAddSingleton<InvoicePaymentNotification>(); services.TryAddSingleton<InvoicePaymentNotification>();
services.TryAddSingleton<BTCPayServerOptions>(o => services.TryAddSingleton<BTCPayServerOptions>(o =>
o.GetRequiredService<IOptions<BTCPayServerOptions>>().Value); o.GetRequiredService<IOptions<BTCPayServerOptions>>().Value);

View File

@ -13,13 +13,18 @@ namespace BTCPayServer.Services
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;
} }
public static string OnionNamedClient { get; set; } = "lightning.onion";
public ILightningClient Create(LightningConnectionString lightningConnectionString, BTCPayNetwork network) public ILightningClient Create(LightningConnectionString lightningConnectionString, BTCPayNetwork network)
{ {
ArgumentNullException.ThrowIfNull(lightningConnectionString); ArgumentNullException.ThrowIfNull(lightningConnectionString);
ArgumentNullException.ThrowIfNull(network); 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); }.Create(lightningConnectionString);
} }
} }