Pluginify BTCPayNetworkProvider (#5331)

This commit is contained in:
Nicolas Dorier
2023-11-29 18:51:40 +09:00
committed by GitHub
parent 1081eab9db
commit 04292d09e1
139 changed files with 1251 additions and 1075 deletions

View File

@@ -5,41 +5,35 @@ using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Services;
using Microsoft.Extensions.Configuration;
namespace BTCPayServer.Hosting
{
public class BlockExplorerLinkStartupTask : IStartupTask
{
private readonly SettingsRepository _settingsRepository;
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
private readonly TransactionLinkProviders _transactionLinksProviders;
private readonly IConfiguration _configuration;
public BlockExplorerLinkStartupTask(SettingsRepository settingsRepository,
BTCPayNetworkProvider btcPayNetworkProvider)
public BlockExplorerLinkStartupTask(
BTCPayNetworkProvider btcPayNetworkProvider,
TransactionLinkProviders transactionLinksProviders,
IConfiguration configuration)
{
_settingsRepository = settingsRepository;
_btcPayNetworkProvider = btcPayNetworkProvider;
_transactionLinksProviders = transactionLinksProviders;
_configuration = configuration;
}
public async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
var settings = await _settingsRepository.GetSettingAsync<PoliciesSettings>();
if (settings?.BlockExplorerLinks?.Any() is true)
var blockExplorerLink = _configuration["blockexplorerlink"];
if (!string.IsNullOrEmpty(blockExplorerLink))
{
SetLinkOnNetworks(settings.BlockExplorerLinks, _btcPayNetworkProvider);
}
}
public static void SetLinkOnNetworks(List<PoliciesSettings.BlockExplorerOverrideItem> links,
BTCPayNetworkProvider networkProvider)
{
var networks = networkProvider.GetAll();
foreach (var network in networks)
{
var overrideLink = links.SingleOrDefault(item =>
item.CryptoCode.Equals(network.CryptoCode, StringComparison.InvariantCultureIgnoreCase));
network.BlockExplorerLink = overrideLink?.Link ?? network.BlockExplorerLinkDefault;
foreach (var prov in _transactionLinksProviders.Values)
prov.OverrideBlockExplorerLink = blockExplorerLink;
}
await _transactionLinksProviders.RefreshTransactionLinkTemplates();
}
}
}