mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
fixes
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Abstractions.Models;
|
||||
using BTCPayServer.Abstractions.Services;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Hosting;
|
||||
using BTCPayServer.Payments;
|
||||
using BTCPayServer.Plugins.Altcoins;
|
||||
using BTCPayServer.Plugins.LiquidPlus.Services;
|
||||
using BTCPayServer.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NBitcoin;
|
||||
using NBXplorer;
|
||||
|
||||
namespace BTCPayServer.Plugins.LiquidPlus
|
||||
{
|
||||
@@ -16,78 +22,75 @@ namespace BTCPayServer.Plugins.LiquidPlus
|
||||
{
|
||||
public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } =
|
||||
{
|
||||
new() { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" }
|
||||
new() {Identifier = nameof(BTCPayServer), Condition = ">=1.12.0"}
|
||||
};
|
||||
public override void Execute(IServiceCollection services)
|
||||
|
||||
public override void Execute(IServiceCollection applicationBuilder)
|
||||
{
|
||||
var services = (PluginServiceCollection) applicationBuilder;
|
||||
if (services.BootstrapServices.GetRequiredService<NBXplorerNetworkProvider>()
|
||||
.GetFromCryptoCode("LBTC") is null || !services.BootstrapServices.GetRequiredService<SelectedChains>().Contains("LBTC"))
|
||||
return;
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("LiquidNav", "store-integrations-nav"));
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("OnChainWalletSetupLiquidExtension", "onchain-wallet-setup-post-body"));
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("OnChainWalletSetupLiquidExtension",
|
||||
"onchain-wallet-setup-post-body"));
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("CustomLiquidAssetsNavExtension", "server-nav"));
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("StoreNavLiquidExtension", "store-nav"));
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("StoreNavLiquidExtension", "store-nav"));
|
||||
services.AddSingleton<CustomLiquidAssetsRepository>();
|
||||
|
||||
var originalImplementationFactory = services.Single(descriptor =>
|
||||
descriptor.Lifetime == ServiceLifetime.Singleton &&
|
||||
descriptor.ServiceType == typeof(BTCPayNetworkProvider));
|
||||
services.Replace(ServiceDescriptor.Singleton(provider =>
|
||||
{
|
||||
var _customLiquidAssetsRepository = provider.GetService<CustomLiquidAssetsRepository>();
|
||||
var _logger = provider.GetService<ILogger<LiquidPlusPlugin>>();
|
||||
var networkProvider =
|
||||
(originalImplementationFactory.ImplementationInstance ??
|
||||
originalImplementationFactory.ImplementationFactory.Invoke(provider)) as BTCPayNetworkProvider;
|
||||
if (networkProvider.Support("LBTC"))
|
||||
{
|
||||
var settings = _customLiquidAssetsRepository.Get();
|
||||
var template = networkProvider.GetNetwork<ElementsBTCPayNetwork>("LBTC");
|
||||
var additionalNetworks = settings.Items.Select(configuration => new ElementsBTCPayNetwork()
|
||||
|
||||
var config = services.BootstrapServices.GetRequiredService<IConfiguration>();
|
||||
DataDirectories dataDirectories = new DataDirectories();
|
||||
dataDirectories.Configure(config);
|
||||
|
||||
var repo = new CustomLiquidAssetsRepository(new NullLogger<CustomLiquidAssetsRepository>(),
|
||||
new OptionsWrapper<DataDirectories>(dataDirectories));
|
||||
var settings = repo.Get();
|
||||
var template = (ElementsBTCPayNetwork) services.Single(descriptor =>
|
||||
descriptor.ServiceType == typeof(BTCPayNetworkBase) &&
|
||||
descriptor.ImplementationInstance is ElementsBTCPayNetwork
|
||||
{
|
||||
CryptoCode = configuration.CryptoCode
|
||||
.Replace("-", "")
|
||||
.Replace("_", ""),
|
||||
DefaultRateRules = configuration.DefaultRateRules ?? Array.Empty<string>(),
|
||||
AssetId = uint256.Parse(configuration.AssetId),
|
||||
Divisibility = configuration.Divisibility,
|
||||
DisplayName = configuration.DisplayName,
|
||||
CryptoImagePath = configuration.CryptoImagePath,
|
||||
NetworkCryptoCode = template.NetworkCryptoCode,
|
||||
DefaultSettings = template.DefaultSettings,
|
||||
ElectrumMapping = template.ElectrumMapping,
|
||||
BlockExplorerLink = template.BlockExplorerLink,
|
||||
ReadonlyWallet = template.ReadonlyWallet,
|
||||
SupportLightning = false,
|
||||
SupportPayJoin = false,
|
||||
ShowSyncSummary = false,
|
||||
WalletSupported = template.WalletSupported,
|
||||
LightningImagePath = "",
|
||||
NBXplorerNetwork = template.NBXplorerNetwork,
|
||||
CoinType = template.CoinType,
|
||||
VaultSupported = template.VaultSupported,
|
||||
MaxTrackedConfirmation = template.MaxTrackedConfirmation,
|
||||
BlockExplorerLinkDefault = template.BlockExplorerLinkDefault,
|
||||
SupportRBF = template.SupportRBF
|
||||
});
|
||||
var newCryptoCodes = settings.Items.Select(configuration => configuration.CryptoCode).ToArray();
|
||||
_logger.LogInformation($"Loaded {newCryptoCodes.Length} " +
|
||||
$"{(!newCryptoCodes.Any()?string.Empty: $"({string.Join(',', newCryptoCodes)})")} additional liquid assets");
|
||||
var newSupportedChains = networkProvider.GetAll().Select(b => b.CryptoCode).Concat(newCryptoCodes).ToArray();
|
||||
return new BTCPayNetworkProviderOverride(networkProvider.NetworkType, additionalNetworks).Filter(newSupportedChains);
|
||||
}
|
||||
CryptoCode: "LBTC"
|
||||
})
|
||||
.ImplementationInstance;
|
||||
var tlProvider = (TransactionLinkProviders.Entry) services.Single(descriptor =>
|
||||
descriptor.ServiceType == typeof(TransactionLinkProviders.Entry) &&
|
||||
descriptor.ImplementationInstance is TransactionLinkProviders.Entry
|
||||
{
|
||||
PaymentMethodId: {CryptoCode: "LBTC"}
|
||||
})
|
||||
.ImplementationInstance;
|
||||
settings.Items.ForEach(configuration =>
|
||||
|
||||
return networkProvider;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public class BTCPayNetworkProviderOverride : BTCPayNetworkProvider
|
||||
{
|
||||
public BTCPayNetworkProviderOverride(ChainName networkType,
|
||||
IEnumerable<ElementsBTCPayNetwork> elementsBTCPayNetworks) : base(networkType)
|
||||
{
|
||||
foreach (ElementsBTCPayNetwork elementsBTCPayNetwork in elementsBTCPayNetworks)
|
||||
{
|
||||
_Networks.TryAdd(elementsBTCPayNetwork.CryptoCode.ToUpperInvariant(), elementsBTCPayNetwork);
|
||||
}
|
||||
var code = configuration.CryptoCode
|
||||
.Replace("-", "")
|
||||
.Replace("_", "");
|
||||
services.AddBTCPayNetwork(new ElementsBTCPayNetwork()
|
||||
{
|
||||
CryptoCode = code,
|
||||
DefaultRateRules = configuration.DefaultRateRules ?? Array.Empty<string>(),
|
||||
AssetId = uint256.Parse(configuration.AssetId),
|
||||
Divisibility = configuration.Divisibility,
|
||||
DisplayName = configuration.DisplayName,
|
||||
CryptoImagePath = configuration.CryptoImagePath,
|
||||
NetworkCryptoCode = template.NetworkCryptoCode,
|
||||
DefaultSettings = template.DefaultSettings,
|
||||
ElectrumMapping = template.ElectrumMapping,
|
||||
BlockExplorerLink = template.BlockExplorerLink,
|
||||
ReadonlyWallet = template.ReadonlyWallet,
|
||||
SupportLightning = false,
|
||||
SupportPayJoin = false,
|
||||
ShowSyncSummary = false,
|
||||
WalletSupported = template.WalletSupported,
|
||||
LightningImagePath = "",
|
||||
NBXplorerNetwork = template.NBXplorerNetwork,
|
||||
CoinType = template.CoinType,
|
||||
VaultSupported = template.VaultSupported,
|
||||
MaxTrackedConfirmation = template.MaxTrackedConfirmation,
|
||||
SupportRBF = template.SupportRBF
|
||||
}).AddTransactionLinkProvider(new PaymentMethodId(code, PaymentTypes.BTCLike), tlProvider.Provider);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user