btcpayserver/BTCPayServer/Services/Altcoins/Monero/MoneroLikeExtensions.cs
Andrew Camilleri 5979fe5eef
BTCPay Extensions Part 2 (#2001)
* BTCPay Extensions Part 2

This PR cleans up the extension system a bit in that:
 * It renames the test extension to a more uniform name
 * Allows yo uto have system extensions, which are extensions but bundled by default with the release (and cannot be removed)
 * Adds a tool to help you generate an extension package from a csproj
 * Refactors the UI extension points to a view component
 * Moves some more interfaces to the Abstractions csproj

* Rename to plugins
2020-10-21 14:02:20 +02:00

72 lines
3.4 KiB
C#

#if ALTCOINS
using System;
using System.Linq;
using BTCPayServer.Configuration;
using BTCPayServer.Contracts;
using BTCPayServer.Payments;
using BTCPayServer.Services.Altcoins.Monero.Configuration;
using BTCPayServer.Services.Altcoins.Monero.Payments;
using BTCPayServer.Services.Altcoins.Monero.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace BTCPayServer.Services.Altcoins.Monero
{
public static class MoneroLikeExtensions
{
public static IServiceCollection AddMoneroLike(this IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton(provider =>
provider.ConfigureMoneroLikeConfiguration());
serviceCollection.AddSingleton<MoneroRPCProvider>();
serviceCollection.AddHostedService<MoneroLikeSummaryUpdaterHostedService>();
serviceCollection.AddHostedService<MoneroListener>();
serviceCollection.AddSingleton<MoneroLikePaymentMethodHandler>();
serviceCollection.AddSingleton<IPaymentMethodHandler>(provider => provider.GetService<MoneroLikePaymentMethodHandler>());
serviceCollection.AddSingleton<IUIExtension>(new UIExtension("Monero/StoreNavMoneroExtension", "store-nav"));
serviceCollection.AddSingleton<ISyncSummaryProvider, MoneroSyncSummaryProvider>();
return serviceCollection;
}
private static MoneroLikeConfiguration ConfigureMoneroLikeConfiguration(this IServiceProvider serviceProvider)
{
var configuration = serviceProvider.GetService<IConfiguration>();
var btcPayNetworkProvider = serviceProvider.GetService<BTCPayNetworkProvider>();
var result = new MoneroLikeConfiguration();
var supportedChains = configuration.GetOrDefault<string>("chains", string.Empty)
.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(t => t.ToUpperInvariant());
var supportedNetworks = btcPayNetworkProvider.Filter(supportedChains.ToArray()).GetAll()
.OfType<MoneroLikeSpecificBtcPayNetwork>();
foreach (var moneroLikeSpecificBtcPayNetwork in supportedNetworks)
{
var daemonUri =
configuration.GetOrDefault<Uri>($"{moneroLikeSpecificBtcPayNetwork.CryptoCode}_daemon_uri",
null);
var walletDaemonUri =
configuration.GetOrDefault<Uri>(
$"{moneroLikeSpecificBtcPayNetwork.CryptoCode}_wallet_daemon_uri", null);
var walletDaemonWalletDirectory =
configuration.GetOrDefault<string>(
$"{moneroLikeSpecificBtcPayNetwork.CryptoCode}_wallet_daemon_walletdir", null);
if (daemonUri == null || walletDaemonUri == null)
{
throw new ConfigException($"{moneroLikeSpecificBtcPayNetwork.CryptoCode} is misconfigured");
}
result.MoneroLikeConfigurationItems.Add(moneroLikeSpecificBtcPayNetwork.CryptoCode, new MoneroLikeConfigurationItem()
{
DaemonRpcUri = daemonUri,
InternalWalletRpcUri = walletDaemonUri,
WalletDirectory = walletDaemonWalletDirectory
});
}
return result;
}
}
}
#endif