diff --git a/BTCPayServer.Common/Altcoins/Ethereum/BTCPayNetworkProvider.Ethereum.cs b/BTCPayServer.Common/Altcoins/Ethereum/BTCPayNetworkProvider.Ethereum.cs deleted file mode 100644 index 9e78db450..000000000 --- a/BTCPayServer.Common/Altcoins/Ethereum/BTCPayNetworkProvider.Ethereum.cs +++ /dev/null @@ -1,78 +0,0 @@ -#if ALTCOINS -using NBitcoin; - -namespace BTCPayServer -{ - public partial class BTCPayNetworkProvider - { - public void InitEthereum() - { - Add(new EthereumBTCPayNetwork() - { - CryptoCode = "ETH", - DisplayName = "Ethereum", - DefaultRateRules = new[] {"ETH_X = ETH_BTC * BTC_X", "ETH_BTC = kraken(ETH_BTC)"}, - BlockExplorerLink = - NetworkType == ChainName.Mainnet - ? "https://etherscan.io/address/{0}" - : "https://ropsten.etherscan.io/address/{0}", - CryptoImagePath = "/imlegacy/eth.png", - ShowSyncSummary = true, - CoinType = NetworkType == ChainName.Mainnet? 60 : 1, - ChainId = NetworkType == ChainName.Mainnet ? 1 : 3, - Divisibility = 18, - }); - } - - public void InitERC20() - { - if (NetworkType != ChainName.Mainnet) - { - Add(new ERC20BTCPayNetwork() - { - CryptoCode = "FAU", - DisplayName = "Faucet Token", - DefaultRateRules = new[] - { - "FAU_X = FAU_BTC * BTC_X", - "FAU_BTC = 0.01", - }, - BlockExplorerLink = "https://ropsten.etherscan.io/address/{0}#tokentxns", - ShowSyncSummary = false, - CoinType = 1, - ChainId = 3, - //use https://erc20faucet.com for testnet - SmartContractAddress = "0xFab46E002BbF0b4509813474841E0716E6730136", - Divisibility = 18, - CryptoImagePath = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=", - }); - } - else - { - Add(new ERC20BTCPayNetwork() - { - CryptoCode = "USDT20", - DisplayName = "Tether USD (ERC20)", - DefaultRateRules = new[] - { - "USDT20_UST = 1", - "USDT20_X = USDT20_BTC * BTC_X", - "USDT20_BTC = bitfinex(UST_BTC)", - }, - BlockExplorerLink = - NetworkType == ChainName.Mainnet - ? "https://etherscan.io/address/{0}#tokentxns" - : "https://ropsten.etherscan.io/address/{0}#tokentxns", - CryptoImagePath = "/imlegacy/liquid-tether.svg", - ShowSyncSummary = false, - CoinType = NetworkType == ChainName.Mainnet? 60 : 1, - ChainId = NetworkType == ChainName.Mainnet ? 1 : 3, - SmartContractAddress = "0xdAC17F958D2ee523a2206206994597C13D831ec7", - Divisibility = 6 - }); - } - - } - } -} -#endif diff --git a/BTCPayServer.Common/Altcoins/Ethereum/EthereumBTCPayNetwork.cs b/BTCPayServer.Common/Altcoins/Ethereum/EthereumBTCPayNetwork.cs deleted file mode 100644 index d07bce92c..000000000 --- a/BTCPayServer.Common/Altcoins/Ethereum/EthereumBTCPayNetwork.cs +++ /dev/null @@ -1,20 +0,0 @@ -#if ALTCOINS -namespace BTCPayServer -{ - public class EthereumBTCPayNetwork : BTCPayNetworkBase - { - public int ChainId { get; set; } - public int CoinType { get; set; } - - public string GetDefaultKeyPath() - { - return $"m/44'/{CoinType}'/0'/0/x"; - } - } - - public class ERC20BTCPayNetwork : EthereumBTCPayNetwork - { - public string SmartContractAddress { get; set; } - } -} -#endif diff --git a/BTCPayServer.Common/Altcoins/Ethereum/EthereumExtensions.cs b/BTCPayServer.Common/Altcoins/Ethereum/EthereumExtensions.cs deleted file mode 100644 index a61baffd4..000000000 --- a/BTCPayServer.Common/Altcoins/Ethereum/EthereumExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -#if ALTCOINS -using System.Collections.Generic; -using System.Linq; - -namespace BTCPayServer -{ - public static class EthereumExtensions - { - - public static IEnumerable GetAllEthereumSubChains(this BTCPayNetworkProvider networkProvider, BTCPayNetworkProvider unfiltered) - { - var ethBased = networkProvider.GetAll().OfType(); - var chainId = ethBased.Select(network => network.ChainId).Distinct(); - return unfiltered.GetAll().OfType() - .Where(network => chainId.Contains(network.ChainId)) - .Select(network => network.CryptoCode.ToUpperInvariant()); - } - } -} -#endif diff --git a/BTCPayServer.Common/BTCPayNetworkProvider.cs b/BTCPayServer.Common/BTCPayNetworkProvider.cs index c3ca9b664..dd956b363 100644 --- a/BTCPayServer.Common/BTCPayNetworkProvider.cs +++ b/BTCPayServer.Common/BTCPayNetworkProvider.cs @@ -59,8 +59,6 @@ namespace BTCPayServer InitChaincoin(); // InitArgoneum();//their rate source is down 9/15/20. InitMonetaryUnit(); - InitEthereum(); - InitERC20(); // Assume that electrum mappings are same as BTC if not specified foreach (var network in _Networks.Values.OfType()) diff --git a/BTCPayServer.Tests/AltcoinTests/EthereumTests.cs b/BTCPayServer.Tests/AltcoinTests/EthereumTests.cs deleted file mode 100644 index d31b01cb6..000000000 --- a/BTCPayServer.Tests/AltcoinTests/EthereumTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using BTCPayServer.Configuration; -using BTCPayServer.Tests.Logging; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Configuration.Memory; -using NBitcoin; -using OpenQA.Selenium; -using Xunit; -using Xunit.Abstractions; - -namespace BTCPayServer.Tests -{ - public class EthereumTests : UnitTestBase - { - public const int TestTimeout = 60_000; - - public EthereumTests(ITestOutputHelper helper) : base(helper) - { - } - - [Fact] - [Trait("Altcoins", "Altcoins")] - public async Task CanUseEthereum() - { - using var s = CreateSeleniumTester("ETHEREUM", true); - s.Server.ActivateETH(); - await s.StartAsync(); - s.RegisterNewUser(true); - - IWebElement syncSummary = null; - TestUtils.Eventually(() => - { - syncSummary = s.Driver.FindElement(By.Id("modalDialog")); - Assert.True(syncSummary.Displayed); - }); - var web3Link = syncSummary.FindElement(By.LinkText("Configure Web3")); - web3Link.Click(); - s.Driver.FindElement(By.Id("Web3ProviderUrl")).SendKeys("https://ropsten-rpc.linkpool.io"); - s.Driver.FindElement(By.Id("saveButton")).Click(); - s.FindAlertMessage(); - TestUtils.Eventually(() => - { - s.Driver.Navigate().Refresh(); - s.Driver.AssertElementNotFound(By.Id("modalDialog")); - }); - - var store = s.CreateNewStore(); - s.Driver.FindElement(By.LinkText("Ethereum")).Click(); - - var seed = new Mnemonic(Wordlist.English); - s.Driver.FindElement(By.Id("ModifyETH")).Click(); - s.Driver.FindElement(By.Id("Seed")).SendKeys(seed.ToString()); - s.Driver.SetCheckbox(By.Id("StoreSeed"), true); - s.Driver.SetCheckbox(By.Id("Enabled"), true); - s.Driver.FindElement(By.Id("SaveButton")).Click(); - s.FindAlertMessage(); - s.Driver.FindElement(By.Id("ModifyUSDT20")).Click(); - s.Driver.FindElement(By.Id("Seed")).SendKeys(seed.ToString()); - s.Driver.SetCheckbox(By.Id("StoreSeed"), true); - s.Driver.SetCheckbox(By.Id("Enabled"), true); - s.Driver.FindElement(By.Id("SaveButton")).Click(); - s.FindAlertMessage(); - - var invoiceId = s.CreateInvoice(store.storeName, 10); - s.GoToInvoiceCheckout(invoiceId); - var currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies")); - Assert.Contains("ETH", currencyDropdownButton.Text); - s.Driver.FindElement(By.Id("copy-tab")).Click(); - - var ethAddress = s.Driver.FindElements(By.ClassName("copySectionBox")) - .Single(element => element.FindElement(By.TagName("label")).Text - .Contains("Address", StringComparison.InvariantCultureIgnoreCase)).FindElement(By.TagName("input")) - .GetAttribute("value"); - currencyDropdownButton.Click(); - var elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem")); - Assert.Equal(2, elements.Count); - - elements.Single(element => element.Text.Contains("USDT20")).Click(); - s.Driver.FindElement(By.Id("copy-tab")).Click(); - var usdtAddress = s.Driver.FindElements(By.ClassName("copySectionBox")) - .Single(element => element.FindElement(By.TagName("label")).Text - .Contains("Address", StringComparison.InvariantCultureIgnoreCase)).FindElement(By.TagName("input")) - .GetAttribute("value"); - Assert.Equal(usdtAddress, ethAddress); - } - } -} diff --git a/BTCPayServer.Tests/FastTests.cs b/BTCPayServer.Tests/FastTests.cs index fd6787eaf..db541466d 100644 --- a/BTCPayServer.Tests/FastTests.cs +++ b/BTCPayServer.Tests/FastTests.cs @@ -1442,13 +1442,11 @@ namespace BTCPayServer.Tests new MemoryConfigurationProvider(new MemoryConfigurationSource() { InitialData = new[] { - new KeyValuePair("chains", "usdt20,usdt")} + new KeyValuePair("chains", "usdt")} }) }); var networkProvider = config.ConfigureNetworkProvider(BTCPayLogs); - Assert.NotNull(networkProvider.GetNetwork("ETH")); - Assert.NotNull(networkProvider.GetNetwork("USDT20")); Assert.NotNull(networkProvider.GetNetwork("LBTC")); Assert.NotNull(networkProvider.GetNetwork("USDT")); } diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 605a1c400..beb076095 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -37,18 +37,10 @@ - - - - - - - - diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index cac419a7b..579970bf1 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -468,12 +468,18 @@ namespace BTCPayServer var supportedChains = configuration.GetOrDefault("chains", "btc") .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(t => t.ToUpperInvariant()).ToHashSet(); - + foreach (var c in supportedChains.ToList()) + { + if (new[] { "ETH", "USDT20", "FAU" }.Contains(c, StringComparer.OrdinalIgnoreCase)) + { + logs.Configuration.LogWarning($"'{c}' is not anymore supported, please remove it from 'chains'"); + supportedChains.Remove(c); + } + } var networkProvider = new BTCPayNetworkProvider(_networkType); var filtered = networkProvider.Filter(supportedChains.ToArray()); #if ALTCOINS supportedChains.AddRange(filtered.GetAllElementsSubChains(networkProvider)); - supportedChains.AddRange(filtered.GetAllEthereumSubChains(networkProvider)); #endif #if !ALTCOINS var onlyBTC = supportedChains.Count == 1 && supportedChains.First() == "BTC"; diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index 6fd93490e..ab825a359 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -59,7 +59,6 @@ using Serilog; using NBitcoin.RPC; #if ALTCOINS using BTCPayServer.Services.Altcoins.Monero; -using BTCPayServer.Services.Altcoins.Ethereum; #endif namespace BTCPayServer.Hosting { @@ -90,7 +89,6 @@ namespace BTCPayServer.Hosting services.AddPayJoinServices(); #if ALTCOINS services.AddMoneroLike(); - services.AddEthereumLike(); #endif services.TryAddSingleton(); services.TryAddSingleton(provider => provider.GetService()); diff --git a/BTCPayServer/Payments/PaymentTypes.cs b/BTCPayServer/Payments/PaymentTypes.cs index 77a1d6aef..cc227b4cb 100644 --- a/BTCPayServer/Payments/PaymentTypes.cs +++ b/BTCPayServer/Payments/PaymentTypes.cs @@ -1,7 +1,6 @@ using System; using System.Linq; #if ALTCOINS -using BTCPayServer.Services.Altcoins.Ethereum.Payments; using BTCPayServer.Services.Altcoins.Monero.Payments; #endif using BTCPayServer.Services.Invoices; @@ -20,7 +19,6 @@ namespace BTCPayServer.Payments BTCLike, LightningLike, LNURLPay, #if ALTCOINS MoneroLike, - EthereumPaymentType.Instance #endif }; /// diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json index b924b9383..fd3b01a55 100644 --- a/BTCPayServer/Properties/launchSettings.json +++ b/BTCPayServer/Properties/launchSettings.json @@ -86,7 +86,7 @@ "BTCPAY_ALLOW-ADMIN-REGISTRATION": "true", "BTCPAY_DISABLE-REGISTRATION": "false", "ASPNETCORE_ENVIRONMENT": "Development", - "BTCPAY_CHAINS": "btc,ltc,lbtc,eth", + "BTCPAY_CHAINS": "btc,ltc,lbtc", "BTCPAY_POSTGRES": "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver", "BTCPAY_EXTERNALSERVICES": "totoservice:totolink;", "BTCPAY_SSHCONNECTION": "root@127.0.0.1:21622", diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs b/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs deleted file mode 100644 index 03ef79b90..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs +++ /dev/null @@ -1,29 +0,0 @@ -#if ALTCOINS -using System.ComponentModel.DataAnnotations; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Configuration -{ - public class EthereumLikeConfiguration - { - public static string SettingsKey(int chainId) - { - return $"{nameof(EthereumLikeConfiguration)}_{chainId}"; - } - public int ChainId { get; set; } - [Display(Name = "Web3 provider url")] - public string Web3ProviderUrl { get; set; } - - [Display(Name = "Web3 provider username (can be left blank)")] - public string Web3ProviderUsername { get; set; } - - [Display(Name = "Web3 provider password (can be left blank)")] - public string Web3ProviderPassword { get; set; } - - public override string ToString() - { - return ""; - } - } -} -#endif - diff --git a/BTCPayServer/Services/Altcoins/Ethereum/EthereumLikeExtensions.cs b/BTCPayServer/Services/Altcoins/Ethereum/EthereumLikeExtensions.cs deleted file mode 100644 index 40e53649d..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/EthereumLikeExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -#if ALTCOINS -using System.Net; -using System.Net.Http; -using BTCPayServer.Abstractions.Contracts; -using BTCPayServer.Abstractions.Services; -using BTCPayServer.HostedServices; -using BTCPayServer.Payments; -using BTCPayServer.Services.Altcoins.Ethereum.Payments; -using BTCPayServer.Services.Altcoins.Ethereum.Services; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace BTCPayServer.Services.Altcoins.Ethereum -{ - public static class EthereumLikeExtensions - { - public const string EthereumInvoiceCheckHttpClient = "EthereumCheck"; - public const string EthereumInvoiceCreateHttpClient = "EthereumCreate"; - public static IServiceCollection AddEthereumLike(this IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(); - serviceCollection.AddSingleton(provider => provider.GetService()); - serviceCollection.AddSingleton(); - serviceCollection.AddSingleton(provider => provider.GetService()); - - serviceCollection.AddSingleton(new UIExtension("Ethereum/StoreNavEthereumExtension", "store-nav")); - serviceCollection.AddTransient(); - serviceCollection.AddSingleton(); - serviceCollection.AddHttpClient(EthereumInvoiceCreateHttpClient) - .ConfigurePrimaryHttpMessageHandler(); - return serviceCollection; - } - } - - public class NoRedirectHttpClientHandler : HttpClientHandler - { - public NoRedirectHttpClientHandler() - { - this.AllowAutoRedirect = false; - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Filters/OnlyIfSupportEth.cs b/BTCPayServer/Services/Altcoins/Ethereum/Filters/OnlyIfSupportEth.cs deleted file mode 100644 index f63725200..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Filters/OnlyIfSupportEth.cs +++ /dev/null @@ -1,26 +0,0 @@ -#if ALTCOINS -using System; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Filters -{ - public class OnlyIfSupportEthAttribute : Attribute, IAsyncActionFilter - { - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var options = context.HttpContext.RequestServices.GetService(); - if (!options.GetAll().OfType().Any()) - { - context.Result = new NotFoundResult(); - return; - } - - await next(); - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikeOnChainPaymentMethodDetails.cs b/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikeOnChainPaymentMethodDetails.cs deleted file mode 100644 index cf87b45fc..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikeOnChainPaymentMethodDetails.cs +++ /dev/null @@ -1,44 +0,0 @@ -#if ALTCOINS -using BTCPayServer.Payments; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Payments -{ - public class EthereumLikeOnChainPaymentMethodDetails : IPaymentMethodDetails - { - public PaymentType GetPaymentType() - { - return EthereumPaymentType.Instance; - } - - public string GetPaymentDestination() - { - return DepositAddress; - } - - public decimal GetNextNetworkFee() - { - return 0; - } - - public decimal GetFeeRate() - { - return 0; - } - - public void SetPaymentDetails(IPaymentMethodDetails newPaymentMethodDetails) - { - throw new System.NotImplementedException(); - } - - public void SetPaymentDestination(string newPaymentDestination) - { - DepositAddress = newPaymentDestination; - } - - public bool Activated { get; set; } - public long Index { get; set; } - public string XPub { get; set; } - public string DepositAddress { get; set; } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikePaymentData.cs b/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikePaymentData.cs deleted file mode 100644 index 7bda8793e..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikePaymentData.cs +++ /dev/null @@ -1,77 +0,0 @@ -#if ALTCOINS -using System.Globalization; -using System.Numerics; -using BTCPayServer.Client.Models; -using BTCPayServer.Payments; -using BTCPayServer.Services.Invoices; -using Nethereum.Hex.HexTypes; -using Nethereum.Web3; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Payments -{ - public class EthereumLikePaymentData : CryptoPaymentData - { - public long Amount { get; set; } - public string CryptoCode { get; set; } - public string Address { get; set; } - public long AccountIndex { get; set; } - public string XPub { get; set; } - public long ConfirmationCount { get; set; } - public BTCPayNetworkBase Network { get; set; } - public long? BlockNumber { get; set; } - - public string GetPaymentId() - { - return GetPaymentId(CryptoCode,Address, Amount); - } - - public static string GetPaymentId(string cryptoCode, string address, long amount) - { - return $"{cryptoCode}#{address}#{amount}"; - } - - public string[] GetSearchTerms() - { - return new[] {Address}; - } - - public decimal GetValue() - { - return decimal.Parse(Web3.Convert.FromWeiToBigDecimal(Amount, Network.Divisibility).ToString(), - CultureInfo.InvariantCulture); - } - - public bool PaymentCompleted(PaymentEntity entity) - { - return ConfirmationCount >= 25; - } - - public bool PaymentConfirmed(PaymentEntity entity, SpeedPolicy speedPolicy) - { - switch (speedPolicy) - { - case SpeedPolicy.HighSpeed: - return ConfirmationCount >= 2; - case SpeedPolicy.MediumSpeed: - return ConfirmationCount >= 6; - case SpeedPolicy.LowMediumSpeed: - return ConfirmationCount >= 12; - case SpeedPolicy.LowSpeed: - return ConfirmationCount >= 20; - default: - return false; - } - } - - public PaymentType GetPaymentType() - { - return EthereumPaymentType.Instance; - } - - public string GetDestination() - { - return Address; - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikePaymentMethodHandler.cs b/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikePaymentMethodHandler.cs deleted file mode 100644 index c230bc185..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumLikePaymentMethodHandler.cs +++ /dev/null @@ -1,133 +0,0 @@ -#if ALTCOINS -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using BTCPayServer.Data; -using BTCPayServer.Logging; -using BTCPayServer.Models; -using BTCPayServer.Models.InvoicingModels; -using BTCPayServer.Payments; -using BTCPayServer.Rating; -using BTCPayServer.Services.Altcoins.Ethereum.Services; -using BTCPayServer.Services.Invoices; -using BTCPayServer.Services.Rates; -using NBitcoin; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Payments -{ - public class - EthereumLikePaymentMethodHandler : PaymentMethodHandlerBase - { - private readonly BTCPayNetworkProvider _networkProvider; - private readonly EthereumService _ethereumService; - - public EthereumLikePaymentMethodHandler(BTCPayNetworkProvider networkProvider, EthereumService ethereumService) - { - _networkProvider = networkProvider; - _ethereumService = ethereumService; - } - - public override PaymentType PaymentType => EthereumPaymentType.Instance; - - public override async Task CreatePaymentMethodDetails(InvoiceLogs logs, - EthereumSupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, - StoreData store, EthereumBTCPayNetwork network, object preparePaymentObject) - { - if (preparePaymentObject is null) - { - return new EthereumLikeOnChainPaymentMethodDetails() - { - Activated = false - }; - } - if (!_ethereumService.IsAvailable(network.CryptoCode, out var error)) - throw new PaymentMethodUnavailableException(error??$"Not configured yet"); - var invoice = paymentMethod.ParentEntity; - if (!(preparePaymentObject is Prepare ethPrepare)) throw new ArgumentException(); - var address = await ethPrepare.ReserveAddress(invoice.Id); - if (address is null || address.Failed) - { - throw new PaymentMethodUnavailableException($"could not generate address"); - } - - return new EthereumLikeOnChainPaymentMethodDetails() - { - DepositAddress = address.Address, Index = address.Index, XPub = address.XPub, Activated = true - }; - } - - public override object PreparePayment(EthereumSupportedPaymentMethod supportedPaymentMethod, StoreData store, - BTCPayNetworkBase network) - { - return new Prepare() - { - ReserveAddress = s => - _ethereumService.ReserveNextAddress( - new EthereumService.ReserveEthereumAddress() - { - StoreId = store.Id, CryptoCode = network.CryptoCode - }) - }; - } - - class Prepare - { - public Func> ReserveAddress; - } - - public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, - StoreBlob storeBlob, IPaymentMethod paymentMethod) - { - var paymentMethodId = paymentMethod.GetId(); - var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId); - var network = _networkProvider.GetNetwork(model.CryptoCode); - model.PaymentMethodName = GetPaymentMethodName(network); - model.CryptoImage = GetCryptoImage(network); - model.InvoiceBitcoinUrl = ""; - model.InvoiceBitcoinUrlQR = cryptoInfo.Address ?? ""; - } - - public override string GetCryptoImage(PaymentMethodId paymentMethodId) - { - var network = _networkProvider.GetNetwork(paymentMethodId.CryptoCode); - return GetCryptoImage(network); - } - - public override string GetPaymentMethodName(PaymentMethodId paymentMethodId) - { - var network = _networkProvider.GetNetwork(paymentMethodId.CryptoCode); - return GetPaymentMethodName(network); - } - - public override IEnumerable GetSupportedPaymentMethods() - { - return _networkProvider.GetAll().OfType() - .Select(network => new PaymentMethodId(network.CryptoCode, PaymentType)); - } - - public override CheckoutUIPaymentMethodSettings GetCheckoutUISettings() - { - return new CheckoutUIPaymentMethodSettings() - { - ExtensionPartial = "Ethereum/EthereumLikeMethodCheckout", - CheckoutBodyVueComponentName = "EthereumLikeMethodCheckout", - CheckoutHeaderVueComponentName = "EthereumLikeMethodCheckoutHeader", - NoScriptPartialName = "Bitcoin/BitcoinLikeMethodCheckoutNoScript" - }; - } - - private string GetCryptoImage(EthereumBTCPayNetwork network) - { - return network.CryptoImagePath; - } - - - private string GetPaymentMethodName(EthereumBTCPayNetwork network) - { - return $"{network.DisplayName}"; - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumPaymentType.cs b/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumPaymentType.cs deleted file mode 100644 index 8807f0606..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumPaymentType.cs +++ /dev/null @@ -1,75 +0,0 @@ -#if ALTCOINS -using System.Globalization; -using BTCPayServer.Payments; -using BTCPayServer.Services.Invoices; -using NBitcoin; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Payments -{ - public class EthereumPaymentType: PaymentType - { - public static EthereumPaymentType Instance { get; } = new EthereumPaymentType(); - public override string ToPrettyString() => "On-Chain"; - - public override string GetId()=> "EthereumLike"; - - - public override CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str) - { - return JsonConvert.DeserializeObject(str); - } - - public override string SerializePaymentData(BTCPayNetworkBase network, CryptoPaymentData paymentData) - { - return JsonConvert.SerializeObject(paymentData); - } - - public override IPaymentMethodDetails DeserializePaymentMethodDetails(BTCPayNetworkBase network, string str) - { - return JsonConvert.DeserializeObject(str); - } - - public override string SerializePaymentMethodDetails(BTCPayNetworkBase network, IPaymentMethodDetails details) - { - return JsonConvert.SerializeObject(details); - } - - public override ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network, JToken value) - { - return JsonConvert.DeserializeObject(value.ToString()); - } - - public override string GetTransactionLink(BTCPayNetworkBase network, string txId) - { - return string.Format(CultureInfo.InvariantCulture, network.BlockExplorerLink, txId); - } - - public override string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails, Money cryptoInfoDue, - string serverUri) - { - return ""; - } - - public override string InvoiceViewPaymentPartialName { get; }= "Ethereum/ViewEthereumLikePaymentData"; - public override object GetGreenfieldData(ISupportedPaymentMethod supportedPaymentMethod, bool canModifyStore) - { - if (supportedPaymentMethod is EthereumSupportedPaymentMethod ethereumSupportedPaymentMethod) - { - return new - { - ethereumSupportedPaymentMethod.XPub - //no clue what all those properties saved are and don't care. - }; - } - - return null; - } - - public override void PopulateCryptoInfo(PaymentMethod details, InvoiceCryptoInfo invoiceCryptoInfo, string serverUrl) - { - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumSupportedPaymentMethod.cs b/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumSupportedPaymentMethod.cs deleted file mode 100644 index 93effb06a..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Payments/EthereumSupportedPaymentMethod.cs +++ /dev/null @@ -1,41 +0,0 @@ -#if ALTCOINS -using System; -using BTCPayServer.Payments; -using NBitcoin; -using Nethereum.HdWallet; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Payments -{ - public class EthereumSupportedPaymentMethod : ISupportedPaymentMethod - { - public string CryptoCode { get; set; } - public string Seed { get; set; } - public string Password { get; set; } - public string XPub { get; set; } - public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, EthereumPaymentType.Instance); - public long CurrentIndex { get; set; } - public string KeyPath { get; set; } - - public Func GetWalletDerivator() - { - if (!string.IsNullOrEmpty(XPub)) - { - try - { - return new PublicWallet(XPub).GetAddress; - } - catch (Exception) - { - return new PublicWallet(new BitcoinExtPubKey(XPub, Network.Main).ExtPubKey).GetAddress; - } - } - else if (!string.IsNullOrEmpty(XPub)) - { - return i => new Wallet(Seed, Password, KeyPath).GetAccount(i).Address; - } - - return null; - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs b/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs deleted file mode 100644 index 0e4cca423..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs +++ /dev/null @@ -1,317 +0,0 @@ -#if ALTCOINS -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using BTCPayServer.Data; -using BTCPayServer.Events; -using BTCPayServer.HostedServices; -using BTCPayServer.Logging; -using BTCPayServer.Services.Altcoins.Ethereum.Payments; -using BTCPayServer.Services.Stores; -using BTCPayServer.Services.Altcoins.Ethereum.Configuration; -using BTCPayServer.Services.Altcoins.Ethereum.UI; -using BTCPayServer.Services.Invoices; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using NBitcoin; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Services -{ - public class EthereumService : EventHostedServiceBase - { - private readonly IHttpClientFactory _httpClientFactory; - private readonly EventAggregator _eventAggregator; - private readonly StoreRepository _storeRepository; - private readonly BTCPayNetworkProvider _btcPayNetworkProvider; - private readonly SettingsRepository _settingsRepository; - private readonly InvoiceRepository _invoiceRepository; - private readonly IConfiguration _configuration; - private readonly PaymentService _paymentService; - private readonly Dictionary _chainHostedServices = new Dictionary(); - - private readonly Dictionary _chainHostedServiceCancellationTokenSources = - new Dictionary(); - - public EthereumService( - IHttpClientFactory httpClientFactory, - EventAggregator eventAggregator, - StoreRepository storeRepository, - BTCPayNetworkProvider btcPayNetworkProvider, - SettingsRepository settingsRepository, - InvoiceRepository invoiceRepository, - IConfiguration configuration, - PaymentService paymentService, - Logs logs) : base(eventAggregator, logs) - { - _httpClientFactory = httpClientFactory; - _eventAggregator = eventAggregator; - _storeRepository = storeRepository; - _btcPayNetworkProvider = btcPayNetworkProvider; - _settingsRepository = settingsRepository; - _invoiceRepository = invoiceRepository; - _configuration = configuration; - _paymentService = paymentService; - } - - public override async Task StartAsync(CancellationToken cancellationToken) - { - var chainIds = _btcPayNetworkProvider.GetAll().OfType() - .Select(network => network.ChainId).Distinct().ToList(); - if (!chainIds.Any()) - { - return; - } - - await base.StartAsync(cancellationToken); - _ = Task.Run(async () => - { - while (!cancellationToken.IsCancellationRequested) - { - _eventAggregator.Publish(new CheckWatchers()); - await Task.Delay(IsAllAvailable() ? TimeSpan.FromDays(1) : TimeSpan.FromSeconds(5), - cancellationToken); - } - }, cancellationToken); - } - - private static bool First = true; - - private async Task LoopThroughChainWatchers(CancellationToken cancellationToken) - { - var chainIds = _btcPayNetworkProvider.GetAll().OfType() - .Select(network => network.ChainId).Distinct().ToList(); - foreach (var chainId in chainIds) - { - try - { - var settings = await _settingsRepository.GetSettingAsync( - EthereumLikeConfiguration.SettingsKey(chainId)); - if (settings is null || string.IsNullOrEmpty(settings.Web3ProviderUrl)) - { - var val = _configuration.GetValue($"chain{chainId}_web3", null); - var valUser = _configuration.GetValue($"chain{chainId}_web3_user", null); - var valPass = _configuration.GetValue($"chain{chainId}_web3_password", null); - if (val != null && First) - { - Logs.PayServer.LogInformation($"Setting eth chain {chainId} web3 to {val}"); - settings ??= new EthereumLikeConfiguration() - { - ChainId = chainId, - Web3ProviderUrl = val, - Web3ProviderPassword = valPass, - Web3ProviderUsername = valUser - }; - await _settingsRepository.UpdateSetting(settings, - EthereumLikeConfiguration.SettingsKey(chainId)); - } - } - - var currentlyRunning = _chainHostedServices.ContainsKey(chainId); - if (!currentlyRunning || (currentlyRunning)) - { - await HandleChainWatcher(settings, cancellationToken); - } - } - catch (Exception) - { - // ignored - } - } - - First = false; - } - - public override Task StopAsync(CancellationToken cancellationToken) - { - foreach (var chainHostedService in _chainHostedServices.Values) - { - _ = chainHostedService.StopAsync(cancellationToken); - } - - return base.StopAsync(cancellationToken); - } - - protected override void SubscribeToEvents() - { - base.SubscribeToEvents(); - - Subscribe(); - Subscribe>(); - Subscribe(); - } - - protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken) - { - if (evt is ReserveEthereumAddress reserveEthereumAddress) - { - await HandleReserveNextAddress(reserveEthereumAddress); - } - - if (evt is SettingsChanged settingsChangedEthConfig) - { - await HandleChainWatcher(settingsChangedEthConfig.Settings, cancellationToken); - } - - if (evt is CheckWatchers) - { - await LoopThroughChainWatchers(cancellationToken); - } - - await base.ProcessEvent(evt, cancellationToken); - } - - private async Task HandleChainWatcher(EthereumLikeConfiguration ethereumLikeConfiguration, - CancellationToken cancellationToken) - { - if (ethereumLikeConfiguration is null) - { - return; - } - - if (_chainHostedServiceCancellationTokenSources.ContainsKey(ethereumLikeConfiguration.ChainId)) - { - _chainHostedServiceCancellationTokenSources[ethereumLikeConfiguration.ChainId].Cancel(); - _chainHostedServiceCancellationTokenSources.Remove(ethereumLikeConfiguration.ChainId); - } - - if (_chainHostedServices.ContainsKey(ethereumLikeConfiguration.ChainId)) - { - await _chainHostedServices[ethereumLikeConfiguration.ChainId].StopAsync(cancellationToken); - _chainHostedServices.Remove(ethereumLikeConfiguration.ChainId); - } - - if (!string.IsNullOrWhiteSpace(ethereumLikeConfiguration.Web3ProviderUrl)) - { - var cts = new CancellationTokenSource(); - _chainHostedServiceCancellationTokenSources.AddOrReplace(ethereumLikeConfiguration.ChainId, cts); - _chainHostedServices.AddOrReplace(ethereumLikeConfiguration.ChainId, - new EthereumWatcher(ethereumLikeConfiguration.ChainId, ethereumLikeConfiguration, - _btcPayNetworkProvider, _eventAggregator, _invoiceRepository, _paymentService, Logs)); - await _chainHostedServices[ethereumLikeConfiguration.ChainId].StartAsync(CancellationTokenSource - .CreateLinkedTokenSource(cancellationToken, cts.Token).Token); - } - } - - private async Task HandleReserveNextAddress(ReserveEthereumAddress reserveEthereumAddress) - { - var store = await _storeRepository.FindStore(reserveEthereumAddress.StoreId); - var ethereumSupportedPaymentMethod = store.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType() - .SingleOrDefault(method => method.PaymentId.CryptoCode == reserveEthereumAddress.CryptoCode); - if (ethereumSupportedPaymentMethod == null) - { - _eventAggregator.Publish(new ReserveEthereumAddressResponse() - { - OpId = reserveEthereumAddress.OpId, Failed = true - }); - return; - } - - ethereumSupportedPaymentMethod.CurrentIndex++; - var address = ethereumSupportedPaymentMethod.GetWalletDerivator()? - .Invoke((int)ethereumSupportedPaymentMethod.CurrentIndex); - - if (string.IsNullOrEmpty(address)) - { - _eventAggregator.Publish(new ReserveEthereumAddressResponse() - { - OpId = reserveEthereumAddress.OpId, Failed = true - }); - return; - } - store.SetSupportedPaymentMethod(ethereumSupportedPaymentMethod.PaymentId, - ethereumSupportedPaymentMethod); - await _storeRepository.UpdateStore(store); - _eventAggregator.Publish(new ReserveEthereumAddressResponse() - { - Address = address, - Index = ethereumSupportedPaymentMethod.CurrentIndex, - CryptoCode = ethereumSupportedPaymentMethod.CryptoCode, - OpId = reserveEthereumAddress.OpId, - StoreId = reserveEthereumAddress.StoreId, - XPub = ethereumSupportedPaymentMethod.XPub - }); - } - - public async Task ReserveNextAddress(ReserveEthereumAddress address) - { - address.OpId = string.IsNullOrEmpty(address.OpId) ? Guid.NewGuid().ToString() : address.OpId; - var tcs = new TaskCompletionSource(); - var subscription = _eventAggregator.Subscribe(response => - { - if (response.OpId == address.OpId) - { - tcs.SetResult(response); - } - }); - _eventAggregator.Publish(address); - - if (tcs.Task.Wait(TimeSpan.FromSeconds(60))) - { - subscription?.Dispose(); - return await tcs.Task; - } - - subscription?.Dispose(); - return null; - } - - public class CheckWatchers - { - public override string ToString() - { - return ""; - } - } - - public class ReserveEthereumAddressResponse - { - public string StoreId { get; set; } - public string CryptoCode { get; set; } - public string Address { get; set; } - public long Index { get; set; } - public string OpId { get; set; } - public string XPub { get; set; } - public bool Failed { get; set; } - - public override string ToString() - { - return $"Reserved {CryptoCode} address {Address} for store {StoreId}"; - } - } - - public class ReserveEthereumAddress - { - public string StoreId { get; set; } - public string CryptoCode { get; set; } - public string OpId { get; set; } - - public override string ToString() - { - return $"Reserving {CryptoCode} address for store {StoreId}"; - } - } - - public bool IsAllAvailable() - { - return _btcPayNetworkProvider.GetAll().OfType() - .All(network => IsAvailable(network.CryptoCode, out _)); - } - - public bool IsAvailable(string networkCryptoCode, out string error) - { - error = null; - var chainId = _btcPayNetworkProvider.GetNetwork(networkCryptoCode)?.ChainId; - if (chainId != null && _chainHostedServices.TryGetValue(chainId.Value, out var watcher)) - { - error = watcher.GlobalError; - return string.IsNullOrEmpty(watcher.GlobalError); - } - return false; - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumSyncSummaryProvider.cs b/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumSyncSummaryProvider.cs deleted file mode 100644 index f706610af..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumSyncSummaryProvider.cs +++ /dev/null @@ -1,45 +0,0 @@ -#if ALTCOINS -using System.Collections.Generic; -using System.Linq; -using BTCPayServer.Abstractions.Contracts; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Services -{ - public class EthereumSyncSummaryProvider : ISyncSummaryProvider - { - private readonly EthereumService _ethereumService; - private readonly BTCPayNetworkProvider _btcPayNetworkProvider; - - public EthereumSyncSummaryProvider(EthereumService ethereumService, BTCPayNetworkProvider btcPayNetworkProvider) - { - _ethereumService = ethereumService; - _btcPayNetworkProvider = btcPayNetworkProvider; - } - - public bool AllAvailable() - { - return _ethereumService.IsAllAvailable(); - } - - public string Partial { get; } = "Ethereum/ETHSyncSummary"; - public IEnumerable GetStatuses() - { - return _btcPayNetworkProvider - .GetAll() - .OfType() - .Where(network => !(network is ERC20BTCPayNetwork)) - .Select(network => network.CryptoCode).Select(network => new SyncStatus() - { - CryptoCode = network, - Available = _ethereumService.IsAvailable(network, out _) - }); - } - - public class SyncStatus : ISyncStatus - { - public string CryptoCode { get; set; } - public bool Available { get; set; } - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumWatcher.cs b/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumWatcher.cs deleted file mode 100644 index 14ed1244d..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumWatcher.cs +++ /dev/null @@ -1,381 +0,0 @@ -#if ALTCOINS -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http.Headers; -using System.Numerics; -using System.Threading; -using System.Threading.Tasks; -using BTCPayServer.Events; -using BTCPayServer.HostedServices; -using BTCPayServer.Payments; -using BTCPayServer.Services.Altcoins.Ethereum.Configuration; -using BTCPayServer.Services.Altcoins.Ethereum.Payments; -using BTCPayServer.Services.Invoices; -using Microsoft.Extensions.Logging; -using NBitcoin.Logging; -using Nethereum.RPC.Eth.DTOs; -using Nethereum.StandardTokenEIP20.ContractDefinition; -using Nethereum.Web3; - -namespace BTCPayServer.Services.Altcoins.Ethereum.Services -{ - public class EthereumWatcher : EventHostedServiceBase - { - private readonly EventAggregator _eventAggregator; - private readonly InvoiceRepository _invoiceRepository; - private readonly PaymentService _paymentService; - private int ChainId { get; } - private readonly HashSet PaymentMethods; - - private readonly Web3 Web3; - private readonly List Networks; - public string GlobalError { get; private set; } = "The chain watcher is still starting."; - - public override async Task StartAsync(CancellationToken cancellationToken) - { - Logs.PayServer.LogInformation($"Starting EthereumWatcher for chain {ChainId}"); - var result = await Web3.Eth.ChainId.SendRequestAsync(); - if (result.Value != ChainId) - { - GlobalError = - $"The web3 client is connected to a different chain id. Expected {ChainId} but Web3 returned {result.Value}"; - return; - } - - await base.StartAsync(cancellationToken); - _eventAggregator.Publish(new CatchUp()); - GlobalError = null; - } - - protected override void SubscribeToEvents() - { - Subscribe(); - Subscribe(); - Subscribe(); - base.SubscribeToEvents(); - } - - protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken) - { - if (evt is CatchUp) - { - DateTimeOffset start = DateTimeOffset.Now; - await UpdateAnyPendingEthLikePaymentAndAddressWatchList(cancellationToken); - - TimeSpan diff = start - DateTimeOffset.Now; - if (diff.TotalSeconds < 5) - { - _ = Task.Delay(TimeSpan.FromSeconds(5 - diff.TotalSeconds), cancellationToken).ContinueWith(task => - { - _eventAggregator.Publish(new CatchUp()); - return Task.CompletedTask; - }, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Current); - } - } - - if (evt is EthereumAddressBalanceFetched response) - { - if (response.ChainId != ChainId) - { - return; - } - - var network = Networks.SingleOrDefault(payNetwork => - payNetwork.CryptoCode.Equals(response.CryptoCode, StringComparison.InvariantCultureIgnoreCase)); - - if (network is null) - { - return; - } - - var invoice = response.InvoiceEntity; - if (invoice is null) - { - return; - } - - var existingPayment = response.MatchedExistingPayment; - - if (existingPayment is null && response.Amount > 0) - { - //new payment - var paymentData = new EthereumLikePaymentData() - { - Address = response.Address, - CryptoCode = response.CryptoCode, - Amount = response.Amount, - Network = network, - BlockNumber = - response.BlockParameter.ParameterType == BlockParameter.BlockParameterType.blockNumber - ? (long?)response.BlockParameter.BlockNumber.Value - : (long?)null, - ConfirmationCount = 0, - AccountIndex = response.PaymentMethodDetails.Index, - XPub = response.PaymentMethodDetails.XPub - }; - var payment = await _paymentService.AddPayment(invoice.Id, DateTimeOffset.UtcNow, - paymentData, network, true); - if (payment != null) ReceivedPayment(invoice, payment); - } - else if (existingPayment != null) - { - var cd = (EthereumLikePaymentData)existingPayment.GetCryptoPaymentData(); - //existing payment amount was changed. Set to unaccounted and register as a new payment. - if (response.Amount == 0 || response.Amount != cd.Amount) - { - existingPayment.Accounted = false; - - await _paymentService.UpdatePayments(new List() {existingPayment}); - if (response.Amount > 0) - { - var paymentData = new EthereumLikePaymentData() - { - Address = response.Address, - CryptoCode = response.CryptoCode, - Amount = response.Amount, - Network = network, - BlockNumber = - response.BlockParameter.ParameterType == - BlockParameter.BlockParameterType.blockNumber - ? (long?)response.BlockParameter.BlockNumber.Value - : null, - ConfirmationCount = - response.BlockParameter.ParameterType == - BlockParameter.BlockParameterType.blockNumber - ? 1 - : 0, - - AccountIndex = cd.AccountIndex, - XPub = cd.XPub - }; - var payment = await _paymentService.AddPayment(invoice.Id, DateTimeOffset.UtcNow, - paymentData, network, true); - if (payment != null) ReceivedPayment(invoice, payment); - } - } - else if (response.Amount == cd.Amount) - { - //transition from pending to 1 confirmed - if (cd.BlockNumber is null && response.BlockParameter.ParameterType == - BlockParameter.BlockParameterType.blockNumber) - { - cd.ConfirmationCount = 1; - cd.BlockNumber = (long?)response.BlockParameter.BlockNumber.Value; - - existingPayment.SetCryptoPaymentData(cd); - await _paymentService.UpdatePayments(new List() {existingPayment}); - - _eventAggregator.Publish(new Events.InvoiceNeedUpdateEvent(invoice.Id)); - } - //increment confirm count - else if (response.BlockParameter.ParameterType == - BlockParameter.BlockParameterType.blockNumber) - { - if (response.BlockParameter.BlockNumber.Value > cd.BlockNumber.Value) - { - cd.ConfirmationCount = - (long)(response.BlockParameter.BlockNumber.Value - cd.BlockNumber.Value); - } - else - { - cd.BlockNumber = (long?)response.BlockParameter.BlockNumber.Value; - cd.ConfirmationCount = 1; - } - - existingPayment.SetCryptoPaymentData(cd); - await _paymentService.UpdatePayments(new List() {existingPayment}); - - _eventAggregator.Publish(new Events.InvoiceNeedUpdateEvent(invoice.Id)); - } - } - } - } - } - - class CatchUp - { - public override string ToString() - { - return ""; - } - } - - public override Task StopAsync(CancellationToken cancellationToken) - { - Logs.PayServer.LogInformation($"Stopping EthereumWatcher for chain {ChainId}"); - return base.StopAsync(cancellationToken); - } - - - private async Task UpdateAnyPendingEthLikePaymentAndAddressWatchList(CancellationToken cancellationToken) - { - var invoiceIds = await _invoiceRepository.GetPendingInvoices(); - if (!invoiceIds.Any()) - { - return; - } - - var invoices = await _invoiceRepository.GetInvoices(new InvoiceQuery() {InvoiceId = invoiceIds}); - invoices = invoices - .Where(entity => PaymentMethods.Any(id => entity.GetPaymentMethod(id)?.GetPaymentMethodDetails()?.Activated is true)) - .ToArray(); - - await UpdatePaymentStates(invoices, cancellationToken); - } - - private long? LastBlock = null; - - private async Task UpdatePaymentStates(InvoiceEntity[] invoices, CancellationToken cancellationToken) - { - if (!invoices.Any()) - { - return; - } - - var currentBlock = await Web3.Eth.Blocks.GetBlockNumber.SendRequestAsync(); - - foreach (var network in Networks) - { - var erc20Network = network as ERC20BTCPayNetwork; - var paymentMethodId = new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance); - var expandedInvoices = invoices - .Select(entity => ( - Invoice: entity, - PaymentMethodDetails: entity.GetPaymentMethods().TryGet(paymentMethodId), - ExistingPayments: entity.GetPayments(network, true).Select(paymentEntity => (Payment: paymentEntity, - PaymentData: (EthereumLikePaymentData)paymentEntity.GetCryptoPaymentData(), - Invoice: entity)) - )).Where(tuple => tuple.PaymentMethodDetails?.GetPaymentMethodDetails()?.Activated is true).ToList(); - - var existingPaymentData = expandedInvoices.SelectMany(tuple => - tuple.ExistingPayments.Where(valueTuple => valueTuple.Payment.Accounted)).ToList(); - - var noAccountedPaymentInvoices = expandedInvoices.Where(tuple => - tuple.ExistingPayments.All(valueTuple => !valueTuple.Payment.Accounted)).ToList(); - - var tasks = new List(); - if (existingPaymentData.Any() && currentBlock.Value != LastBlock) - { - Logs.PayServer.LogInformation( - $"Checking {existingPaymentData.Count} existing payments on {expandedInvoices.Count} invoices on {network.CryptoCode}"); - var blockParameter = new BlockParameter(currentBlock); - - tasks.Add(Task.WhenAll(existingPaymentData.Select(async tuple => - { - var bal = await GetBalance(network, blockParameter, tuple.PaymentData.Address); - _eventAggregator.Publish(new EthereumAddressBalanceFetched() - { - Address = tuple.PaymentData.Address, - CryptoCode = network.CryptoCode, - Amount = bal, - MatchedExistingPayment = tuple.Payment, - BlockParameter = blockParameter, - ChainId = ChainId, - InvoiceEntity = tuple.Invoice, - }); - })).ContinueWith(task => - { - LastBlock = (long?)currentBlock.Value; - }, TaskScheduler.Current)); - } - - if (noAccountedPaymentInvoices.Any()) - { - Logs.PayServer.LogInformation( - $"Checking {noAccountedPaymentInvoices.Count} addresses for new payments on {network.CryptoCode}"); - var blockParameter = BlockParameter.CreatePending(); - tasks.AddRange(noAccountedPaymentInvoices.Select(async tuple => - { - var bal = await GetBalance(network, blockParameter, - tuple.PaymentMethodDetails.GetPaymentMethodDetails().GetPaymentDestination()); - _eventAggregator.Publish(new EthereumAddressBalanceFetched() - { - Address = tuple.PaymentMethodDetails.GetPaymentMethodDetails().GetPaymentDestination(), - CryptoCode = network.CryptoCode, - Amount = bal, - MatchedExistingPayment = null, - BlockParameter = blockParameter, - ChainId = ChainId, - InvoiceEntity = tuple.Invoice, - PaymentMethodDetails = (EthereumLikeOnChainPaymentMethodDetails) tuple.PaymentMethodDetails.GetPaymentMethodDetails() - }); - })); - } - - await Task.WhenAll(tasks); - } - } - - public class EthereumAddressBalanceFetched - { - public BlockParameter BlockParameter { get; set; } - public int ChainId { get; set; } - public string Address { get; set; } - public string CryptoCode { get; set; } - public long Amount { get; set; } - public InvoiceEntity InvoiceEntity { get; set; } - public PaymentEntity MatchedExistingPayment { get; set; } - public EthereumLikeOnChainPaymentMethodDetails PaymentMethodDetails { get; set; } - - public override string ToString() - { - return ""; - } - } - - private void ReceivedPayment(InvoiceEntity invoice, PaymentEntity payment) - { - _eventAggregator.Publish( - new InvoiceEvent(invoice, InvoiceEvent.ReceivedPayment) {Payment = payment}); - } - - private async Task GetBalance(EthereumBTCPayNetwork network, BlockParameter blockParameter, - string address) - { - if (network is ERC20BTCPayNetwork erc20BTCPayNetwork) - { - return (long)(await Web3.Eth.GetContractHandler(erc20BTCPayNetwork.SmartContractAddress) - .QueryAsync(new BalanceOfFunction() {Owner = address})); - } - else - { - return (long)(await Web3.Eth.GetBalance.SendRequestAsync(address, blockParameter)).Value; - } - } - - public EthereumWatcher(int chainId, EthereumLikeConfiguration config, - BTCPayNetworkProvider btcPayNetworkProvider, - EventAggregator eventAggregator, InvoiceRepository invoiceRepository, PaymentService paymentService, - BTCPayServer.Logging.Logs logs) : - base(eventAggregator, logs) - { - _eventAggregator = eventAggregator; - _invoiceRepository = invoiceRepository; - _paymentService = paymentService; - ChainId = chainId; - AuthenticationHeaderValue headerValue = null; - if (!string.IsNullOrEmpty(config.Web3ProviderUsername)) - { - var val = config.Web3ProviderUsername; - if (!string.IsNullOrEmpty(config.Web3ProviderUsername)) - { - val += $":{config.Web3ProviderUsername}"; - } - - headerValue = new AuthenticationHeaderValue( - "Basic", Convert.ToBase64String( - System.Text.Encoding.ASCII.GetBytes(val))); - } - Web3 = new Web3(config.Web3ProviderUrl, null, headerValue); - Networks = btcPayNetworkProvider.GetAll() - .OfType() - .Where(network => network.ChainId == chainId) - .ToList(); - PaymentMethods = Networks - .Select(network => new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance)) - .ToHashSet(); - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs b/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs deleted file mode 100644 index 97df2d729..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs +++ /dev/null @@ -1,89 +0,0 @@ -#if ALTCOINS -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using BTCPayServer.Abstractions.Constants; -using BTCPayServer.Abstractions.Extensions; -using BTCPayServer.Abstractions.Models; -using BTCPayServer.Client; -using BTCPayServer.Data; -using BTCPayServer.Models; -using BTCPayServer.Security; -using BTCPayServer.Services.Altcoins.Ethereum.Configuration; -using BTCPayServer.Services.Altcoins.Ethereum.Filters; -using BTCPayServer.Services.Altcoins.Ethereum.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using NBitcoin; -using Nethereum.Hex.HexConvertors.Extensions; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace BTCPayServer.Services.Altcoins.Ethereum.UI -{ - [Route("ethconfig")] - [OnlyIfSupportEth] - [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] - [Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] - public class EthereumConfigController : Controller - { - private readonly IHttpClientFactory _httpClientFactory; - private readonly SettingsRepository _settingsRepository; - private readonly UserManager _userManager; - private readonly EventAggregator _eventAggregator; - - public EthereumConfigController(IHttpClientFactory httpClientFactory, SettingsRepository settingsRepository, - UserManager userManager, - EventAggregator eventAggregator) - { - _httpClientFactory = httpClientFactory; - _settingsRepository = settingsRepository; - _userManager = userManager; - _eventAggregator = eventAggregator; - } - - [HttpGet("{chainId}")] - public async Task UpdateChainConfig(int chainId) - { - return View("Ethereum/UpdateChainConfig", - (await _settingsRepository.GetSettingAsync( - EthereumLikeConfiguration.SettingsKey(chainId))) ?? new EthereumLikeConfiguration() - { - ChainId = chainId, Web3ProviderUrl = "" - }); - } - - [HttpGet("{chainId}/cb")] - public IActionResult Callback(int chainId) - { - _eventAggregator.Publish(new EthereumService.CheckWatchers()); - TempData.SetStatusMessageModel(new StatusMessageModel() - { - Message = "If the invoice was paid successfully and confirmed, the system will be enabled momentarily" - }); - return RedirectToAction("UpdateChainConfig", new {chainId}); - } - - [HttpPost("{chainId}")] - public async Task UpdateChainConfig(int chainId, EthereumLikeConfiguration vm) - { - var current = await _settingsRepository.GetSettingAsync( - EthereumLikeConfiguration.SettingsKey(chainId)); - if (current?.Web3ProviderUrl != vm.Web3ProviderUrl) - { - vm.ChainId = chainId; - await _settingsRepository.UpdateSetting(vm, EthereumLikeConfiguration.SettingsKey(chainId)); - } - - TempData.SetStatusMessageModel(new StatusMessageModel() - { - Severity = StatusMessageModel.StatusSeverity.Success, Message = $"Chain {chainId} updated" - }); - return RedirectToAction(nameof(UpdateChainConfig)); - } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumLikeStoreController.cs b/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumLikeStoreController.cs deleted file mode 100644 index 0b0a15723..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumLikeStoreController.cs +++ /dev/null @@ -1,281 +0,0 @@ -#if ALTCOINS -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using BTCPayServer.Abstractions.Constants; -using BTCPayServer.Abstractions.Extensions; -using BTCPayServer.Abstractions.Models; -using BTCPayServer.Client; -using BTCPayServer.Data; -using BTCPayServer.Models; -using BTCPayServer.Payments; -using BTCPayServer.Security; -using BTCPayServer.Services.Altcoins.Ethereum.Filters; -using BTCPayServer.Services.Altcoins.Ethereum.Payments; -using BTCPayServer.Services.Stores; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using NBitcoin; -using Nethereum.HdWallet; -using Nethereum.Hex.HexConvertors.Extensions; - -namespace BTCPayServer.Services.Altcoins.Ethereum.UI -{ - [Route("stores/{storeId}/ethlike")] - [OnlyIfSupportEth] - [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] - [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] - public class EthereumLikeStoreController : Controller - { - private readonly StoreRepository _storeRepository; - private readonly BTCPayNetworkProvider _btcPayNetworkProvider; - - public EthereumLikeStoreController(StoreRepository storeRepository, - BTCPayNetworkProvider btcPayNetworkProvider) - { - _storeRepository = storeRepository; - _btcPayNetworkProvider = btcPayNetworkProvider; - } - - private StoreData StoreData => HttpContext.GetStoreData(); - - [HttpGet()] - public IActionResult GetStoreEthereumLikePaymentMethods() - { - var eth = StoreData.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType(); - - var excludeFilters = StoreData.GetStoreBlob().GetExcludedPaymentMethods(); - var ethNetworks = _btcPayNetworkProvider.GetAll().OfType(); - - var vm = new ViewEthereumStoreOptionsViewModel() { }; - - foreach (var network in ethNetworks) - { - var paymentMethodId = new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance); - var matchedPaymentMethod = eth.SingleOrDefault(method => - method.PaymentId == paymentMethodId); - vm.Items.Add(new ViewEthereumStoreOptionItemViewModel() - { - CryptoCode = network.CryptoCode, - Enabled = matchedPaymentMethod != null && !excludeFilters.Match(paymentMethodId), - IsToken = network is ERC20BTCPayNetwork, - RootAddress = matchedPaymentMethod?.GetWalletDerivator()?.Invoke(0) ?? "not configured" - }); - } - - return View(vm); - } - - [HttpGet("{cryptoCode}")] - public IActionResult GetStoreEthereumLikePaymentMethod(string cryptoCode) - { - var eth = StoreData.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType(); - - var network = _btcPayNetworkProvider.GetNetwork(cryptoCode); - if (network is null) - { - return NotFound(); - } - - var excludeFilters = StoreData.GetStoreBlob().GetExcludedPaymentMethods(); - var paymentMethodId = new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance); - var matchedPaymentMethod = eth.SingleOrDefault(method => - method.PaymentId == paymentMethodId); - - return View(new EditEthereumPaymentMethodViewModel() - { - Enabled = !excludeFilters.Match(paymentMethodId), - XPub = matchedPaymentMethod?.XPub, - Index = matchedPaymentMethod?.CurrentIndex ?? 0, - Passphrase = matchedPaymentMethod?.Password, - Seed = matchedPaymentMethod?.Seed, - StoreSeed = !string.IsNullOrEmpty(matchedPaymentMethod?.Seed), - OriginalIndex = matchedPaymentMethod?.CurrentIndex ?? 0, - KeyPath = string.IsNullOrEmpty(matchedPaymentMethod?.KeyPath) - ? network.GetDefaultKeyPath() - : matchedPaymentMethod?.KeyPath - }); - } - - [HttpPost("{cryptoCode}")] - public async Task GetStoreEthereumLikePaymentMethod(string cryptoCode, - EditEthereumPaymentMethodViewModel viewModel) - { - var network = _btcPayNetworkProvider.GetNetwork(cryptoCode); - if (network is null) - { - return NotFound(); - } - - var store = StoreData; - var blob = StoreData.GetStoreBlob(); - var paymentMethodId = new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance); - - var currentPaymentMethod = StoreData.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType().SingleOrDefault(method => - method.PaymentId == paymentMethodId); - - if (currentPaymentMethod != null && currentPaymentMethod.CurrentIndex != viewModel.Index && - viewModel.OriginalIndex == viewModel.Index) - { - viewModel.Index = currentPaymentMethod.CurrentIndex; - viewModel.OriginalIndex = currentPaymentMethod.CurrentIndex; - } - else if (currentPaymentMethod != null && currentPaymentMethod.CurrentIndex != viewModel.Index && - viewModel.OriginalIndex != currentPaymentMethod.CurrentIndex) - { - ModelState.AddModelError(nameof(viewModel.Index), - $"You tried to update the index (to {viewModel.Index}) but new derivations in the background updated the index (to {currentPaymentMethod.CurrentIndex}) "); - viewModel.Index = currentPaymentMethod.CurrentIndex; - viewModel.OriginalIndex = currentPaymentMethod.CurrentIndex; - } - - Wallet wallet = null; - try - { - if (!string.IsNullOrEmpty(viewModel.Seed)) - { - wallet = new Wallet(viewModel.Seed, viewModel.Passphrase, - string.IsNullOrEmpty(viewModel.KeyPath) ? network.GetDefaultKeyPath() : viewModel.KeyPath); - } - } - catch (Exception) - { - ModelState.AddModelError(nameof(viewModel.Seed), $"seed was incorrect"); - } - - if (wallet != null) - { - try - { - wallet.GetAccount(0); - } - catch (Exception) - { - ModelState.AddModelError(nameof(viewModel.KeyPath), $"keypath was incorrect"); - } - } - - PublicWallet publicWallet = null; - try - { - if (!string.IsNullOrEmpty(viewModel.XPub)) - { - try - { - publicWallet = new PublicWallet(viewModel.XPub); - } - catch (Exception) - { - publicWallet = new PublicWallet(new BitcoinExtPubKey(viewModel.XPub, Network.Main).ExtPubKey); - } - - if (wallet != null && !publicWallet.ExtPubKey.Equals(wallet.GetMasterPublicWallet().ExtPubKey)) - { - ModelState.AddModelError(nameof(viewModel.XPub), - $"The xpub does not match the seed/pass/key path provided"); - } - } - } - catch (Exception) - { - ModelState.AddModelError(nameof(viewModel.XPub), $"xpub was incorrect"); - } - - if (!string.IsNullOrEmpty(viewModel.AddressCheck)) - { - int index = -1; - if (wallet != null) - { - index = Array.IndexOf(wallet.GetAddresses(1000), viewModel.AddressCheck); - } - else if (publicWallet != null) - { - index = Array.IndexOf(publicWallet.GetAddresses(1000), viewModel.AddressCheck); - } - - if (viewModel.AddressCheckLastUsed && index > -1) - { - viewModel.Index = index; - } - - if (index == -1) - { - ModelState.AddModelError(nameof(viewModel.AddressCheck), - "Could not confirm address belongs to configured wallet"); - } - } - - if (!ModelState.IsValid) - { - return View(viewModel); - } - - currentPaymentMethod ??= new EthereumSupportedPaymentMethod(); - currentPaymentMethod.Password = viewModel.StoreSeed ? viewModel.Passphrase : ""; - currentPaymentMethod.Seed = viewModel.StoreSeed ? viewModel.Seed : ""; - currentPaymentMethod.XPub = string.IsNullOrEmpty(viewModel.XPub) && wallet != null - ? wallet.GetMasterPublicWallet().ExtPubKey.ToBytes().ToHex() - : viewModel.XPub; - currentPaymentMethod.CryptoCode = cryptoCode; - currentPaymentMethod.KeyPath = string.IsNullOrEmpty(viewModel.KeyPath) - ? network.GetDefaultKeyPath() - : viewModel.KeyPath; - currentPaymentMethod.CurrentIndex = viewModel.Index; - - blob.SetExcluded(paymentMethodId, !viewModel.Enabled); - store.SetSupportedPaymentMethod(currentPaymentMethod); - store.SetStoreBlob(blob); - await _storeRepository.UpdateStore(store); - - TempData.SetStatusMessageModel(new StatusMessageModel() - { - Message = $"updated {cryptoCode}", Severity = StatusMessageModel.StatusSeverity.Success - }); - - return RedirectToAction("GetStoreEthereumLikePaymentMethods", new {storeId = store.Id}); - } - } - - public class EditEthereumPaymentMethodViewModel - { - public string XPub { get; set; } - public string Seed { get; set; } - public string Passphrase { get; set; } - - public string KeyPath { get; set; } - public long OriginalIndex { get; set; } - - [Display(Name = "Current address index")] - - public long Index { get; set; } - - public bool Enabled { get; set; } - - [Display(Name = "Hot wallet")] public bool StoreSeed { get; set; } - - [Display(Name ="Address Check")] - public string AddressCheck { get; set; } - - public bool AddressCheckLastUsed { get; set; } - } - - public class ViewEthereumStoreOptionsViewModel - { - public List Items { get; set; } = - new List(); - } - - public class ViewEthereumStoreOptionItemViewModel - { - public string CryptoCode { get; set; } - public bool IsToken { get; set; } - public bool Enabled { get; set; } - public string RootAddress { get; set; } - } -} -#endif diff --git a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumPaymentViewModel.cs b/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumPaymentViewModel.cs deleted file mode 100644 index 3a3f3f1be..000000000 --- a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumPaymentViewModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -#if ALTCOINS -using System; - -namespace BTCPayServer.Services.Altcoins.Ethereum.UI -{ - public class EthereumPaymentViewModel - { - public string Crypto { get; set; } - public string Confirmations { get; set; } - public string DepositAddress { get; set; } - public string Amount { get; set; } - public DateTimeOffset ReceivedTime { get; set; } - public long? BlockNumber { get; set; } - public string BalanceLink { get; set; } - public bool Replaced { get; set; } - public long Index { get; set; } - } -} -#endif diff --git a/BTCPayServer/Views/EthereumLikeStore/GetStoreEthereumLikePaymentMethod.cshtml b/BTCPayServer/Views/EthereumLikeStore/GetStoreEthereumLikePaymentMethod.cshtml deleted file mode 100644 index 39d4b3b7b..000000000 --- a/BTCPayServer/Views/EthereumLikeStore/GetStoreEthereumLikePaymentMethod.cshtml +++ /dev/null @@ -1,92 +0,0 @@ -@using BTCPayServer.Views.Stores -@using BTCPayServer.Abstractions.Extensions -@model BTCPayServer.Services.Altcoins.Ethereum.UI.EditEthereumPaymentMethodViewModel - -@{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData["NavPartialName"] = "../Stores/_Nav"; - ViewData.SetActivePageAndTitle(StoreNavPages.ActivePage, $"{Context.GetRouteValue("cryptoCode")} Settings", Context.GetStoreData().StoreName); -} - -
-
-
DO NOT USE THE WALLET TO ACCEPT PAYMENTS OUTSIDE OF THIS STORE.
If you spend funds received on invoices which have not been marked complete yet, the invoice will be marked as unpaid. -
-
-
- - -
- - - -
-
- - - -
- -
- - - Please see this article. - -
- -
- - - Store the seed/password on server if provided. If not checked, will generate the xpub and erase the seed/pass from server - -
- -
- - - The public master key derived from a seed/pass/keypath. This allows you to generate addresses without private keys on the server. - -
- -
- - - The index to generate the next address from. If you are using a wallet that you have used before, be sure to set this to the last index +1 - -
-
- -
- -
- -
-
- Check wallet by providing an address it can generate within the first 1000 indexes - -
-
- - - -
-
- - - - Back to list - -
-
-
-
- -@section PageFootContent { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/BTCPayServer/Views/EthereumLikeStore/GetStoreEthereumLikePaymentMethods.cshtml b/BTCPayServer/Views/EthereumLikeStore/GetStoreEthereumLikePaymentMethods.cshtml deleted file mode 100644 index ce0e476e7..000000000 --- a/BTCPayServer/Views/EthereumLikeStore/GetStoreEthereumLikePaymentMethods.cshtml +++ /dev/null @@ -1,66 +0,0 @@ - -@using BTCPayServer.Views.Stores -@using BTCPayServer.Abstractions.Extensions -@model BTCPayServer.Services.Altcoins.Ethereum.UI.ViewEthereumStoreOptionsViewModel -@inject SignInManager SignInManager; -@inject BTCPayNetworkProvider BTCPayNetworkProvider; -@{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData.SetActivePageAndTitle(StoreNavPages.ActivePage, "Ethereum Settings", Context.GetStoreData().StoreName); - ViewData["NavPartialName"] = "../Stores/_Nav"; -} - -
-
-
-
- - - - - - - - - - - @foreach (var item in Model.Items) - { - - - - - - - } - -
CryptoRoot addressEnabledActions
@item.CryptoCode@item.RootAddress - @if (item.Enabled) - { - - } - else - { - - } - - - Modify - -
-
-
-
-@if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.ServerAdmin)) -{ - var chains = BTCPayNetworkProvider.GetAll().OfType().Select(network => network.ChainId).Distinct(); - foreach (var chain in chains) - { - Configure Web3 for chain @chain - } -} -@section PageFootContent { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/BTCPayServer/Views/Shared/Ethereum/ETHSyncSummary.cshtml b/BTCPayServer/Views/Shared/Ethereum/ETHSyncSummary.cshtml deleted file mode 100644 index 07f1d5d34..000000000 --- a/BTCPayServer/Views/Shared/Ethereum/ETHSyncSummary.cshtml +++ /dev/null @@ -1,27 +0,0 @@ -@using BTCPayServer.Services.Altcoins.Ethereum.Services -@inject BTCPayNetworkProvider BTCPayNetworkProvider -@inject EthereumService EthereumService; - -@inject SignInManager SignInManager; -@{ - var networks = BTCPayNetworkProvider.GetAll().OfType().OrderBy(network => network.ChainId).Where(network => network.ShowSyncSummary); -} - -@foreach (var network in networks) -{ -

@network.CryptoCode (Chain ID: @network.ChainId) @(network is ERC20BTCPayNetwork is true ? "(ERC20)" : "")

-
    - @if (!EthereumService.IsAvailable(network.CryptoCode, out var error)) - { -
  • - @(error??"Web3 has not yet been configured") - - - @if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.ServerAdmin)) - { - Configure Web3 - } -
  • - } -
-} diff --git a/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml b/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml deleted file mode 100644 index 5d8303f93..000000000 --- a/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml +++ /dev/null @@ -1,224 +0,0 @@ -@model BTCPayServer.Models.InvoicingModels.PaymentModel -@inject BTCPayNetworkProvider BTCPayNetworkProvider -@{ - var chains = BTCPayNetworkProvider.GetAll().OfType().ToDictionary(network => network.CryptoCode.ToLowerInvariant(), network => new - { - ChainId = network.ChainId, - SmartContractAddress = (network as ERC20BTCPayNetwork)?.SmartContractAddress, - Divisibility = network.Divisibility - }); -} - - - - - diff --git a/BTCPayServer/Views/Shared/Ethereum/StoreNavEthereumExtension.cshtml b/BTCPayServer/Views/Shared/Ethereum/StoreNavEthereumExtension.cshtml deleted file mode 100644 index 93e9e7473..000000000 --- a/BTCPayServer/Views/Shared/Ethereum/StoreNavEthereumExtension.cshtml +++ /dev/null @@ -1,11 +0,0 @@ -@using BTCPayServer.Services.Altcoins.Ethereum.UI -@inject SignInManager SignInManager; -@inject BTCPayNetworkProvider BTCPayNetworkProvider; -@{ - var controller = ViewContext.RouteData.Values["Controller"].ToString(); - var isEthereum = controller.Equals(nameof(EthereumLikeStoreController), StringComparison.InvariantCultureIgnoreCase); -} -@if (SignInManager.IsSignedIn(User) && BTCPayNetworkProvider.GetAll().OfType().Any()) -{ - Ethereum -} diff --git a/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml b/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml deleted file mode 100644 index ec6b75280..000000000 --- a/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml +++ /dev/null @@ -1,49 +0,0 @@ -@using BTCPayServer.Views.Server -@using System.Net.Http -@using BTCPayServer.Abstractions.Extensions -@model BTCPayServer.Services.Altcoins.Ethereum.Configuration.EthereumLikeConfiguration -@inject BTCPayNetworkProvider BTCPayNetworkProvider; -@inject IHttpClientFactory HttpClientFactory; -@{ - Layout = "../_NavLayout.cshtml"; - ViewData["NavPartialName"] = "../Server/_Nav"; - ViewBag.MainTitle = "Server settings"; - ViewData.SetActivePageAndTitle(ServerNavPages.Policies, $"ETH Chain {Model.ChainId} Configuration"); -} - -@if (!ViewContext.ModelState.IsValid) -{ -
-} - -
-
- -
- - - -
- Possible free options are -
    -
  • linkpool.io - Free, just set the url to https://main-rpc.linkpool.io
  • -
  • chainstack.com - Free plan, choose shared public node
  • -
  • infura.io - Free tier but limited calls per day
  • -
  • Your own geth/openethereum node
  • -
-
-
-
- - - -
-
- - - -
-
- - -
diff --git a/BTCPayServer/Views/Shared/Ethereum/ViewEthereumLikePaymentData.cshtml b/BTCPayServer/Views/Shared/Ethereum/ViewEthereumLikePaymentData.cshtml deleted file mode 100644 index 482cb0771..000000000 --- a/BTCPayServer/Views/Shared/Ethereum/ViewEthereumLikePaymentData.cshtml +++ /dev/null @@ -1,64 +0,0 @@ -@using System.Globalization -@using BTCPayServer.Services.Altcoins.Ethereum.Payments -@using BTCPayServer.Services.Altcoins.Ethereum.UI -@model IEnumerable - -@{ - var onchainPayments = Model.Where(entity => entity.GetPaymentMethodId().PaymentType == EthereumPaymentType.Instance).Select(payment => - { - var m = new EthereumPaymentViewModel(); - var onChainPaymentData = payment.GetCryptoPaymentData() as EthereumLikePaymentData; - m.Crypto = payment.GetPaymentMethodId().CryptoCode; - m.DepositAddress = onChainPaymentData.GetDestination(); - - m.Amount = onChainPaymentData.GetValue().ToString(CultureInfo.InvariantCulture); - m.Confirmations = onChainPaymentData.BlockNumber.HasValue ? $"{onChainPaymentData.ConfirmationCount} (block {onChainPaymentData.BlockNumber})" : "pending"; - m.Amount = onChainPaymentData.GetValue().ToString(CultureInfo.InvariantCulture); - m.BlockNumber = onChainPaymentData.BlockNumber; - m.ReceivedTime = payment.ReceivedTime; - m.BalanceLink = string.Format(CultureInfo.InvariantCulture, payment.Network.BlockExplorerLink, m.DepositAddress); - m.Replaced = !payment.Accounted; - m.Index = onChainPaymentData.AccountIndex; - return m; - }); -} - -@if (onchainPayments.Any()) -{ -
-
-

Ethereum/ERC-20 payments

- - - - - - - - - - - - @foreach (var payment in onchainPayments) - { - - - - - - - - - } - -
CryptoAmountAddressIndexConfirmations
@payment.Crypto@payment.Amount - - @payment.Index@payment.Confirmations
-
-
-} diff --git a/BTCPayServer/wwwroot/imlegacy/eth.png b/BTCPayServer/wwwroot/imlegacy/eth.png deleted file mode 100644 index b3b8fce4f..000000000 Binary files a/BTCPayServer/wwwroot/imlegacy/eth.png and /dev/null differ