mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
Fix spot not using HttpClient created by the httpclientfactory
This commit is contained in:
parent
cd6ce401e1
commit
274533bfdf
7 changed files with 16 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using BTCPayServer.Models.StoreViewModels;
|
using BTCPayServer.Models.StoreViewModels;
|
||||||
|
@ -77,7 +78,7 @@ namespace BTCPayServer.Controllers
|
||||||
case "test":
|
case "test":
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = new Changelly(_httpClientFactory, changellySettings.ApiKey, changellySettings.ApiSecret,
|
var client = new Changelly(_httpClientFactory.CreateClient(), changellySettings.ApiKey, changellySettings.ApiSecret,
|
||||||
changellySettings.ApiUrl);
|
changellySettings.ApiUrl);
|
||||||
var result = await client.GetCurrenciesFull();
|
var result = await client.GetCurrenciesFull();
|
||||||
vm.StatusMessage = "Test Successful";
|
vm.StatusMessage = "Test Successful";
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -7,6 +8,7 @@ using BTCPayServer.Configuration;
|
||||||
using BTCPayServer.Logging;
|
using BTCPayServer.Logging;
|
||||||
using NBXplorer;
|
using NBXplorer;
|
||||||
using BTCPayServer.HostedServices;
|
using BTCPayServer.HostedServices;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace BTCPayServer
|
namespace BTCPayServer
|
||||||
{
|
{
|
||||||
|
@ -17,7 +19,7 @@ namespace BTCPayServer
|
||||||
|
|
||||||
public BTCPayNetworkProvider NetworkProviders => _NetworkProviders;
|
public BTCPayNetworkProvider NetworkProviders => _NetworkProviders;
|
||||||
NBXplorerDashboard _Dashboard;
|
NBXplorerDashboard _Dashboard;
|
||||||
public ExplorerClientProvider(BTCPayNetworkProvider networkProviders, BTCPayServerOptions options, NBXplorerDashboard dashboard)
|
public ExplorerClientProvider(IHttpClientFactory httpClientFactory, BTCPayNetworkProvider networkProviders, BTCPayServerOptions options, NBXplorerDashboard dashboard)
|
||||||
{
|
{
|
||||||
_Dashboard = dashboard;
|
_Dashboard = dashboard;
|
||||||
_NetworkProviders = networkProviders;
|
_NetworkProviders = networkProviders;
|
||||||
|
@ -32,14 +34,15 @@ namespace BTCPayServer
|
||||||
Logs.Configuration.LogInformation($"{setting.CryptoCode}: Cookie file is {(setting.CookieFile ?? "not set")}");
|
Logs.Configuration.LogInformation($"{setting.CryptoCode}: Cookie file is {(setting.CookieFile ?? "not set")}");
|
||||||
if (setting.ExplorerUri != null)
|
if (setting.ExplorerUri != null)
|
||||||
{
|
{
|
||||||
_Clients.TryAdd(setting.CryptoCode, CreateExplorerClient(_NetworkProviders.GetNetwork(setting.CryptoCode), setting.ExplorerUri, setting.CookieFile));
|
_Clients.TryAdd(setting.CryptoCode, CreateExplorerClient(httpClientFactory.CreateClient($"NBXPLORER_{setting.CryptoCode}"), _NetworkProviders.GetNetwork(setting.CryptoCode), setting.ExplorerUri, setting.CookieFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExplorerClient CreateExplorerClient(BTCPayNetwork n, Uri uri, string cookieFile)
|
private static ExplorerClient CreateExplorerClient(HttpClient httpClient, BTCPayNetwork n, Uri uri, string cookieFile)
|
||||||
{
|
{
|
||||||
var explorer = new ExplorerClient(n.NBXplorerNetwork, uri);
|
var explorer = new ExplorerClient(n.NBXplorerNetwork, uri);
|
||||||
|
explorer.SetClient(httpClient);
|
||||||
if (cookieFile == null)
|
if (cookieFile == null)
|
||||||
{
|
{
|
||||||
Logs.Configuration.LogWarning($"{n.CryptoCode}: Not using cookie authentication");
|
Logs.Configuration.LogWarning($"{n.CryptoCode}: Not using cookie authentication");
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace BTCPayServer.Payments.Changelly
|
||||||
private readonly bool _showFiat;
|
private readonly bool _showFiat;
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
public Changelly(IHttpClientFactory httpClientFactory, string apiKey, string apiSecret, string apiUrl, bool showFiat = true)
|
public Changelly(HttpClient httpClient, string apiKey, string apiSecret, string apiUrl, bool showFiat = true)
|
||||||
{
|
{
|
||||||
_apisecret = apiSecret;
|
_apisecret = apiSecret;
|
||||||
_showFiat = showFiat;
|
_showFiat = showFiat;
|
||||||
_httpClient = httpClientFactory.CreateClient();
|
_httpClient = httpClient;
|
||||||
_httpClient.BaseAddress = new Uri(apiUrl);
|
_httpClient.BaseAddress = new Uri(apiUrl);
|
||||||
_httpClient.DefaultRequestHeaders.Add("api-key", apiKey);
|
_httpClient.DefaultRequestHeaders.Add("api-key", apiKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace BTCPayServer.Payments.Changelly
|
||||||
throw new ChangellyException("Changelly not enabled for this store");
|
throw new ChangellyException("Changelly not enabled for this store");
|
||||||
}
|
}
|
||||||
|
|
||||||
var changelly = new Changelly(_httpClientFactory, changellySettings.ApiKey, changellySettings.ApiSecret,
|
var changelly = new Changelly(_httpClientFactory.CreateClient("Changelly"), changellySettings.ApiKey, changellySettings.ApiSecret,
|
||||||
changellySettings.ApiUrl, changellySettings.ShowFiat);
|
changellySettings.ApiUrl, changellySettings.ShowFiat);
|
||||||
_clientCache.AddOrReplace(storeId, changelly);
|
_clientCache.AddOrReplace(storeId, changelly);
|
||||||
return changelly;
|
return changelly;
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace BTCPayServer.Services.Rates
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_LocalClient = null;
|
_LocalClient = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HttpClient _LocalClient;
|
HttpClient _LocalClient;
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace BTCPayServer.Services.Rates
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_LocalClient = null;
|
_LocalClient = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,9 +110,9 @@ namespace BTCPayServer.Services.Rates
|
||||||
|
|
||||||
// Handmade providers
|
// Handmade providers
|
||||||
Providers.Add(QuadrigacxRateProvider.QuadrigacxName, new QuadrigacxRateProvider());
|
Providers.Add(QuadrigacxRateProvider.QuadrigacxName, new QuadrigacxRateProvider());
|
||||||
Providers.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider() { Exchange = CoinAverageRateProvider.CoinAverageName, HttpClient = _httpClientFactory?.CreateClient(), Authenticator = _CoinAverageSettings });
|
Providers.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider() { Exchange = CoinAverageRateProvider.CoinAverageName, HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_COINAVERAGE"), Authenticator = _CoinAverageSettings });
|
||||||
Providers.Add("kraken", new KrakenExchangeRateProvider() { HttpClient = _httpClientFactory?.CreateClient() });
|
Providers.Add("kraken", new KrakenExchangeRateProvider() { HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_KRAKEN") });
|
||||||
Providers.Add("bylls", new ByllsRateProvider(_httpClientFactory?.CreateClient()));
|
Providers.Add("bylls", new ByllsRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BYLLS")));
|
||||||
|
|
||||||
// Those exchanges make multiple requests when calling GetTickers so we remove them
|
// Those exchanges make multiple requests when calling GetTickers so we remove them
|
||||||
//DirectProviders.Add("gdax", new ExchangeSharpRateProvider("gdax", new ExchangeGdaxAPI()));
|
//DirectProviders.Add("gdax", new ExchangeSharpRateProvider("gdax", new ExchangeGdaxAPI()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue