Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move altcoins out of btcpay #5521

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
docker buildx create --use
DOCKER_BUILDX_OPTS="--platform linux/amd64,linux/arm64,linux/arm/v7 --build-arg GIT_COMMIT=${GIT_COMMIT} --push"
docker buildx build $DOCKER_BUILDX_OPTS -t $DOCKERHUB_REPO:$LATEST_TAG .
docker buildx build $DOCKER_BUILDX_OPTS -t $DOCKERHUB_REPO:$LATEST_TAG-altcoins --build-arg CONFIGURATION_NAME=Altcoins-Release .
workflows:
version: 2
build_and_test:
Expand Down
21 changes: 21 additions & 0 deletions .run/BTCPayServer_ Altcoins-HTTPS.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BTCPayServer: Altcoins-HTTPS" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BTCPayServer/BTCPayServer.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net6.0" />
<option name="LAUNCH_PROFILE_NAME" value="Altcoins-HTTPS" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
<option name="Build" default="false" projectName="BTCPayServer.Plugins.Zcash" projectPath="$PROJECT_DIR$/Plugins/BTCPayServer.Plugins.Zcash/BTCPayServer.Plugins.Zcash.csproj" />
<option name="Build" default="false" projectName="BTCPayServer.Plugins.Monero" projectPath="$PROJECT_DIR$/Plugins/BTCPayServer.Plugins.Monero/BTCPayServer.Plugins.Monero.csproj" />
<option name="Build" default="false" projectName="BTCPayServer.Plugins.Liquid" projectPath="$PROJECT_DIR$/Plugins/BTCPayServer.Plugins.Liquid/BTCPayServer.Plugins.Liquid.csproj" />
<option name="Build" default="false" projectName="BTCPayServer.Plugins.Altcoins" projectPath="$PROJECT_DIR$/Plugins/BTCPayServer.Plugins.Altcoins/BTCPayServer.Plugins.Altcoins.csproj" />
</method>
</configuration>
</component>
2 changes: 1 addition & 1 deletion BTCPayServer.Client/BTCPayServer.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/btcpayserver/btcpayserver</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Configurations>Debug;Release;Altcoins-Debug;Altcoins-Release</Configurations>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<PropertyGroup>
Expand Down
18 changes: 18 additions & 0 deletions BTCPayServer.Common/BTCPayNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ public virtual List<TransactionInformation> FilterValidTransactions(List<Transac
{
return transactionInformationSet;
}

public virtual decimal GetValue(IMoney m)
{
switch (m)
{
case Money money:
return money.ToDecimal(MoneyUnit.BTC);
case MoneyBag mb:
return mb.Sum(GetValue);
default:
throw new NotSupportedException("IMoney type not supported");
}
}

public virtual string GetAssetId()
{
return null;
}
}

public abstract class BTCPayNetworkBase
Expand Down
22 changes: 1 addition & 21 deletions BTCPayServer.Common/BTCPayNetworkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,25 @@
using System.Linq;
using BTCPayServer.Configuration;
using BTCPayServer.Logging;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using NBitcoin;
using NBXplorer;
using StandardConfiguration;

namespace BTCPayServer
{
public partial class BTCPayNetworkProvider
{
protected readonly Dictionary<string, BTCPayNetworkBase> _Networks = new Dictionary<string, BTCPayNetworkBase>();

private readonly NBXplorerNetworkProvider _NBXplorerNetworkProvider;
public NBXplorerNetworkProvider NBXplorerNetworkProvider
{
get
{
return _NBXplorerNetworkProvider;
}
}

public ChainName NetworkType { get; private set; }
public BTCPayNetworkProvider(
IEnumerable<BTCPayNetworkBase> networks,
SelectedChains selectedChains,
NBXplorerNetworkProvider nbxplorerNetworkProvider,
Logs logs)
{
var networksList = networks.ToList();
#if !ALTCOINS
var onlyBTC = networksList.Count == 1 && networksList.First().IsBTC;
if (!onlyBTC)
throw new ConfigException($"This build of BTCPay Server does not support altcoins. Configured networks: {string.Join(',', networksList.Select(n => n.CryptoCode).ToArray())}");
#endif
_NBXplorerNetworkProvider = nbxplorerNetworkProvider;
NetworkType = nbxplorerNetworkProvider.NetworkType;
foreach (var network in networksList)
foreach (var network in networks)
{
_Networks.Add(network.CryptoCode.ToUpperInvariant(), network);
}
Expand Down
6 changes: 0 additions & 6 deletions BTCPayServer.Common/BTCPayServer.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
<PackageReference Include="NBXplorer.Client" Version="4.3.0" />
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="2.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(Altcoins)' != 'true'">
<Compile Remove="Altcoins\**\*.cs"></Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Altcoins\" />
</ItemGroup>
</Project>
7 changes: 1 addition & 6 deletions BTCPayServer.Tests/AltcoinTests/ElementsTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Configuration;
using BTCPayServer.Controllers;
using BTCPayServer.Models.WalletViewModels;
using BTCPayServer.Plugins.Altcoins;
using BTCPayServer.Plugins.Liquid;
using BTCPayServer.Services.Wallets;
using BTCPayServer.Tests.Logging;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using NBitcoin;
using NBitcoin.Payment;
using NBitpayClient;
Expand Down
7 changes: 4 additions & 3 deletions BTCPayServer.Tests/BTCPayServer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(Altcoins)' != 'true'">
<Compile Remove="AltcoinTests\**\*.cs"></Compile>
</ItemGroup>
<ItemGroup>
<None Update=".dockerignore">
<DependentUpon>Dockerfile</DependentUpon>
Expand All @@ -52,6 +49,10 @@
<ItemGroup>
<ProjectReference Include="..\BTCPayServer.Rating\BTCPayServer.Rating.csproj" />
<ProjectReference Include="..\BTCPayServer\BTCPayServer.csproj" />
<ProjectReference Include="..\Plugins\BTCPayServer.Plugins.Altcoins\BTCPayServer.Plugins.Altcoins.csproj" />
<ProjectReference Include="..\Plugins\BTCPayServer.Plugins.Liquid\BTCPayServer.Plugins.Liquid.csproj" />
<ProjectReference Include="..\Plugins\BTCPayServer.Plugins.Monero\BTCPayServer.Plugins.Monero.csproj" />
<ProjectReference Include="..\Plugins\BTCPayServer.Plugins.Zcash\BTCPayServer.Plugins.Zcash.csproj" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions BTCPayServer.Tests/BTCPayServerTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public async Task StartAsync()
var confBuilder = new DefaultConfiguration() { Logger = LoggerProvider.CreateLogger("Console") }.CreateConfigurationBuilder(new[] { "--datadir", _Directory, "--conf", confPath, "--disable-registration", DisableRegistration ? "true" : "false" });
#if DEBUG
confBuilder.AddJsonFile("appsettings.dev.json", true, false);
confBuilder.AddInMemoryCollection( new Dictionary<string, string>()
{
{ "DEV_PLUGINS", Directory.GetCurrentDirectory() +"/../../../../Plugins"}
});
#endif
var conf = confBuilder.Build();
_Host = new WebHostBuilder()
Expand Down
11 changes: 1 addition & 10 deletions BTCPayServer.Tests/FastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,6 @@ public void CanParsePaymentMethodId()
Assert.Equal(id, id2);
Assert.Equal("LTC_LightningLike", id.ToString());
Assert.Equal("LTC-LightningNetwork", id.ToStringNormalized());
#if ALTCOINS
id = PaymentMethodId.Parse("XMR");
id1 = PaymentMethodId.Parse("XMR-MoneroLike");
Assert.Equal(id, id1);
Assert.Equal("XMR_MoneroLike", id.ToString());
Assert.Equal("XMR", id.ToStringNormalized());
#endif
}

[Fact]
Expand Down Expand Up @@ -495,7 +488,6 @@ public void CanCalculateDust()

#pragma warning restore CS0618
}
#if ALTCOINS
[Fact]
public void CanCalculateCryptoDue()
{
Expand Down Expand Up @@ -661,7 +653,6 @@ public void CanCalculateCryptoDue()
Assert.Equal(accounting.Paid, accounting.TotalDue);
#pragma warning restore CS0618
}
#endif

[Fact]
public void DeterministicUTXOSorter()
Expand Down Expand Up @@ -1997,7 +1988,7 @@ public void LoadSubChainsAlways()
new MemoryConfigurationProvider(new MemoryConfigurationSource()
{
InitialData = new[] {
new KeyValuePair<string, string>("chains", "usdt")}
new KeyValuePair<string, string>("chains", "lbtc")}
})
});
var networkProvider = CreateNetworkProvider(config);
Expand Down
6 changes: 1 addition & 5 deletions BTCPayServer.Tests/ServerTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public ServerTester(string scope, bool newDb, ILog testLogs, ILoggerProvider log
PayTester.SSHConnection = GetEnvironment("TESTS_SSHCONNECTION", "[email protected]:21622");
PayTester.SocksEndpoint = GetEnvironment("TESTS_SOCKSENDPOINT", "localhost:9050");
}
#if ALTCOINS
public void ActivateLTC()
{
LTCExplorerNode = new RPCClient(RPCCredentialString.Parse(GetEnvironment("TESTS_LTCRPCCONNECTION", "server=http://127.0.0.1:43783;ceiwHEbqWI83:DwubwWsoo3")), NetworkProvider.GetNetwork<BTCPayNetwork>("LTC").NBitcoinNetwork);
Expand All @@ -91,8 +90,7 @@ public void ActivateETH()
{
PayTester.Chains.Add("ETH");
}

#endif

public void ActivateLightning()
{
ActivateLightning(LightningConnectionType.CLightning);
Expand Down Expand Up @@ -226,7 +224,6 @@ public RPCClient ExplorerNode
{
get; set;
}
#if ALTCOINS
public RPCClient LTCExplorerNode
{
get; set;
Expand All @@ -235,7 +232,6 @@ public RPCClient LTCExplorerNode
public RPCClient LBTCExplorerNode { get; set; }
public ExplorerClient LTCExplorerClient { get; set; }
public ExplorerClient LBTCExplorerClient { get; set; }
#endif

public ExplorerClient ExplorerClient
{
Expand Down
11 changes: 8 additions & 3 deletions BTCPayServer.Tests/UnitTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
using BTCPayServer.Logging;
using BTCPayServer.Plugins.Bitcoin;
using BTCPayServer.Plugins;
using BTCPayServer.Plugins.Altcoins;
using BTCPayServer.Plugins.Liquid;
using BTCPayServer.Plugins.Monero;
using BTCPayServer.Plugins.Zcash;
using BTCPayServer.Tests.Logging;
using Microsoft.Extensions.DependencyInjection;
using NBXplorer;
Expand Down Expand Up @@ -58,9 +62,10 @@ public BTCPayNetworkProvider CreateNetworkProvider(IConfiguration conf = null)
var bootstrap = Startup.CreateBootstrap(conf);
var services = new PluginServiceCollection(new ServiceCollection(), bootstrap);
var plugins = new List<BaseBTCPayServerPlugin>() { new BitcoinPlugin() };
#if ALTCOINS
plugins.Add(new BTCPayServer.Plugins.Altcoins.AltcoinsPlugin());
#endif
plugins.Add(new LiquidPlugin());
plugins.Add(new MoneroPlugin());
plugins.Add(new ZcashPlugin());
plugins.Add(new AltcoinsPlugin());
foreach (var p in plugins)
{
p.Execute(services);
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer.Tests/docker-compose.altcoins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
context: ..
dockerfile: BTCPayServer.Tests/Dockerfile
args:
CONFIGURATION_NAME: Altcoins-Release
CONFIGURATION_NAME: Release
environment:
TESTS_BTCRPCCONNECTION: server=http://bitcoind:43782;ceiwHEbqWI83:DwubwWsoo3
TESTS_LTCRPCCONNECTION: server=http://litecoind:43782;ceiwHEbqWI83:DwubwWsoo3
Expand Down
10 changes: 0 additions & 10 deletions BTCPayServer/BTCPayServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@
<ItemGroup>
<None Remove="Currencies.txt" />
</ItemGroup>

<ItemGroup Condition="'$(Altcoins)' != 'true'">
<Content Remove="Services\Altcoins\**\*" />
<Compile Remove="Plugins\Altcoins\**\*" />
<Content Remove="Views\UIMoneroLikeStore\**\*" />
<Content Remove="Views\UIZcashLikeStore\**\*" />
<Content Remove="Views\Shared\Monero\**\*" />
<Content Remove="Views\Shared\Zcash\**\*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BTCPayServer.NTag424" Version="1.0.22" />
<PackageReference Include="YamlDotNet" Version="8.0.0" />
Expand Down
4 changes: 1 addition & 3 deletions BTCPayServer/Components/MainNav/MainNav.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public async Task<IViewComponentResult> InvokeAsync()
{
var store = ViewContext.HttpContext.GetStoreData();
var vm = new MainNavViewModel { Store = store };
#if ALTCOINS
vm.AltcoinsBuild = true;
#endif
vm.AltcoinsBuild = _networkProvider.GetAll().Count() > 1;
if (store != null)
{
var storeBlob = store.GetStoreBlob();
Expand Down
6 changes: 0 additions & 6 deletions BTCPayServer/Configuration/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand All @@ -11,7 +10,6 @@
using BTCPayServer.Plugins.Bitcoin;
using CommandLine;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.DependencyInjection;
using NBitcoin;
using NBXplorer;
Expand Down Expand Up @@ -167,10 +165,6 @@ private BTCPayNetworkProvider CreateBTCPayNetworkProvider(ChainName networkType)
var services = new PluginServiceCollection(collection, Startup.CreateBootstrap(conf));
var p1 = new BitcoinPlugin();
p1.Execute(services);
#if ALTCOINS
var p2 = new Plugins.Altcoins.AltcoinsPlugin();
p2.Execute(services);
#endif
services.AddSingleton(services.BootstrapServices.GetRequiredService<SelectedChains>());
services.AddSingleton(services.BootstrapServices.GetRequiredService<NBXplorerNetworkProvider>());
services.AddSingleton(services.BootstrapServices.GetRequiredService<Logs>());
Expand Down
5 changes: 1 addition & 4 deletions BTCPayServer/Controllers/UIInvoiceController.UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,7 @@ public async Task<IActionResult> CheckoutNoScript(string? invoiceId, string? id
Request.Host,
Request.PathBase) : null;

var isAltcoinsBuild = false;
#if ALTCOINS
isAltcoinsBuild = true;
#endif
var isAltcoinsBuild = _NetworkProvider.GetAll().Count() > 1;;

var orderId = invoice.Metadata.OrderId;
var supportUrl = !string.IsNullOrEmpty(storeBlob.StoreSupportUrl)
Expand Down
4 changes: 1 addition & 3 deletions BTCPayServer/Controllers/UIStoresController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,7 @@ public async Task<IActionResult> CheckoutAppearance(CheckoutAppearanceViewModel
Value = value,
WalletId = new WalletId(store.Id, paymentMethodId.CryptoCode),
Enabled = !excludeFilters.Match(paymentMethodId) && strategy != null,
#if ALTCOINS
Collapsed = network is Plugins.Altcoins.ElementsBTCPayNetwork elementsBTCPayNetwork && elementsBTCPayNetwork.NetworkCryptoCode != elementsBTCPayNetwork.CryptoCode && string.IsNullOrEmpty(value)
#endif
Collapsed = string.IsNullOrEmpty(value) && network.GetAssetId() is not null
});
break;

Expand Down
6 changes: 0 additions & 6 deletions BTCPayServer/Controllers/UIWalletsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,6 @@ private async Task SendFreeMoney(Cheater cheater, WalletId walletId, DerivationS
{
var c = this.ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode);
var cashCow = cheater.GetCashCow(walletId.CryptoCode);
#if ALTCOINS
if (walletId.CryptoCode == "LBTC")
{
await cashCow.SendCommandAsync("rescanblockchain");
}
#endif
var addresses = Enumerable.Range(0, 200).Select(_ => c.GetUnusedAsync(paymentMethod.AccountDerivation, DerivationFeature.Deposit, reserve: true)).ToArray();

await Task.WhenAll(addresses);
Expand Down