From 1cf60acb29ae7b3fcc96f10eec1eec809a8dab4f Mon Sep 17 00:00:00 2001 From: XPayServer Date: Fri, 18 Sep 2020 12:30:13 +0200 Subject: [PATCH] remove donation --- .../EthereumLikeConfiguration.cs | 2 - .../Ethereum/Services/EthereumService.cs | 27 +++--- .../Ethereum/UI/EthereumConfigController.cs | 85 +------------------ .../Shared/Ethereum/UpdateChainConfig.cshtml | 15 ---- 4 files changed, 15 insertions(+), 114 deletions(-) diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs b/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs index aad53cc2b..03ef79b90 100644 --- a/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs +++ b/BTCPayServer/Services/Altcoins/Ethereum/Configuration/EthereumLikeConfiguration.cs @@ -19,8 +19,6 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Configuration [Display(Name = "Web3 provider password (can be left blank)")] public string Web3ProviderPassword { get; set; } - public string InvoiceId { get; set; } - public override string ToString() { return ""; diff --git a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs b/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs index 10b77ae15..8360e233b 100644 --- a/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs +++ b/BTCPayServer/Services/Altcoins/Ethereum/Services/EthereumService.cs @@ -33,9 +33,10 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services private readonly Dictionary _chainHostedServiceCancellationTokenSources = new Dictionary(); + public EthereumService( IHttpClientFactory httpClientFactory, - EventAggregator eventAggregator, + EventAggregator eventAggregator, StoreRepository storeRepository, BTCPayNetworkProvider btcPayNetworkProvider, SettingsRepository settingsRepository, @@ -67,14 +68,15 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services while (!cancellationToken.IsCancellationRequested) { _eventAggregator.Publish(new CheckWatchers()); - await Task.Delay(IsAllAvailable()? TimeSpan.FromDays(1): TimeSpan.FromSeconds(5) , cancellationToken); + await Task.Delay(IsAllAvailable() ? TimeSpan.FromDays(1) : TimeSpan.FromSeconds(5), + cancellationToken); } }, cancellationToken); - } private static bool First = true; - private async Task LoopThroughChainWatchers(CancellationToken cancellationToken) + + private async Task LoopThroughChainWatchers(CancellationToken cancellationToken) { var chainIds = _btcPayNetworkProvider.GetAll().OfType() .Select(network => network.ChainId).Distinct().ToList(); @@ -99,14 +101,15 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services Web3ProviderPassword = valPass, Web3ProviderUsername = valUser }; - await _settingsRepository.UpdateSetting(settings, EthereumLikeConfiguration.SettingsKey(chainId)); + await _settingsRepository.UpdateSetting(settings, + EthereumLikeConfiguration.SettingsKey(chainId)); } } + var currentlyRunning = _chainHostedServices.ContainsKey(chainId); - var valid = await EthereumConfigController.CheckValid(_httpClientFactory, _btcPayNetworkProvider.NetworkType, settings?.InvoiceId); - if (!currentlyRunning || (currentlyRunning && !valid)) + if (!currentlyRunning || (currentlyRunning)) { - await HandleChainWatcher(settings, valid, cancellationToken); + await HandleChainWatcher(settings, cancellationToken); } } catch (Exception) @@ -146,8 +149,7 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services if (evt is SettingsChanged settingsChangedEthConfig) { - var valid = await EthereumConfigController.CheckValid(_httpClientFactory, _btcPayNetworkProvider.NetworkType, settingsChangedEthConfig?.Settings?.InvoiceId); - await HandleChainWatcher(settingsChangedEthConfig.Settings, valid, cancellationToken); + await HandleChainWatcher(settingsChangedEthConfig.Settings, cancellationToken); } if (evt is CheckWatchers) @@ -158,7 +160,7 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services await base.ProcessEvent(evt, cancellationToken); } - private async Task HandleChainWatcher(EthereumLikeConfiguration ethereumLikeConfiguration, bool valid, + private async Task HandleChainWatcher(EthereumLikeConfiguration ethereumLikeConfiguration, CancellationToken cancellationToken) { if (ethereumLikeConfiguration is null) @@ -178,9 +180,8 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services _chainHostedServices.Remove(ethereumLikeConfiguration.ChainId); } - if (!string.IsNullOrWhiteSpace(ethereumLikeConfiguration.Web3ProviderUrl) && valid) + if (!string.IsNullOrWhiteSpace(ethereumLikeConfiguration.Web3ProviderUrl)) { - var cts = new CancellationTokenSource(); _chainHostedServiceCancellationTokenSources.AddOrReplace(ethereumLikeConfiguration.ChainId, cts); _chainHostedServices.AddOrReplace(ethereumLikeConfiguration.ChainId, diff --git a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs b/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs index 5b5c5edfb..39f344ae0 100644 --- a/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs +++ b/BTCPayServer/Services/Altcoins/Ethereum/UI/EthereumConfigController.cs @@ -69,7 +69,7 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.UI { var current = await _settingsRepository.GetSettingAsync( EthereumLikeConfiguration.SettingsKey(chainId)); - if (current?.Web3ProviderUrl != vm.Web3ProviderUrl || current?.InvoiceId != vm.InvoiceId) + if (current?.Web3ProviderUrl != vm.Web3ProviderUrl) { vm.ChainId = chainId; await _settingsRepository.UpdateSetting(vm, EthereumLikeConfiguration.SettingsKey(chainId)); @@ -81,89 +81,6 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.UI }); return RedirectToAction(nameof(UpdateChainConfig)); } - - [HttpGet("{chainId}/p")] - [HttpPost("{chainId}/p")] - public async Task CreateInvoice(int chainId) - { - var current = await _settingsRepository.GetSettingAsync( - EthereumLikeConfiguration.SettingsKey(chainId)); - current ??= new EthereumLikeConfiguration() {ChainId = chainId}; - if (!string.IsNullOrEmpty(current?.InvoiceId) && - Request.Method.Equals("get", StringComparison.InvariantCultureIgnoreCase)) - { - return View("Confirm", - new ConfirmModel() - { - Title = $"Generate new donation link?", - Description = - "This previously linked donation instructions will be erased. If you paid anything to it, you will lose access.", - Action = "Confirm and generate", - }); - } - - var user = await _userManager.GetUserAsync(User); - var httpClient = _httpClientFactory.CreateClient(EthereumLikeExtensions.EthereumInvoiceCreateHttpClient); - string invoiceUrl; - var response = await httpClient.PostAsync($"{Server.HexToUTF8String()}{invoiceEndpoint.HexToUTF8String()}", - new FormUrlEncodedContent(new List>() - { - new KeyValuePair("choiceKey", $"license_{chainId}"), - new KeyValuePair("posData", - JsonConvert.SerializeObject(new {Host = Request.Host, ChainId = chainId})), - new KeyValuePair("orderID", $"eth_{Request.Host}_{chainId}"), - new KeyValuePair("email", user.Email), - new KeyValuePair("redirectUrl", - Url.Action("Callback", "EthereumConfig", new {chainId}, Request.Scheme)), - })); - if (response.StatusCode == System.Net.HttpStatusCode.Found) - { - HttpResponseHeaders headers = response.Headers; - if (headers != null && headers.Location != null) - { - invoiceUrl = $"{Server.HexToUTF8String()}{headers.Location}"; - current.InvoiceId = headers.Location.ToString() - .Replace("/i/", string.Empty, StringComparison.InvariantCultureIgnoreCase); - await UpdateChainConfig(chainId, current); - return Redirect(invoiceUrl); - } - } - - TempData.SetStatusMessageModel(new StatusMessageModel() - { - Severity = StatusMessageModel.StatusSeverity.Error, Message = $"Couldn't connect to donation server, try again later." - }); - return RedirectToAction("UpdateChainConfig", new { chainId}); - } - - private string invoiceEndpoint = "0x2f617070732f3262706f754e74576b4b3543636e426d374833456a3346505a756f412f706f73"; - private static string Server = "0x68747470733a2f2f787061797365727665722e636f6d"; - public static NetworkType InvoiceEnforced = NetworkType.Mainnet; - - public static async Task CheckValid(IHttpClientFactory httpClientFactory, NetworkType networkType, string invoiceId) - { - if (networkType != InvoiceEnforced) - { - return true; - } - if (string.IsNullOrEmpty(invoiceId)) - { - return false; - } - - var httpClient = httpClientFactory.CreateClient(EthereumLikeExtensions.EthereumInvoiceCheckHttpClient); - var url = $"{Server.HexToUTF8String()}/i/{invoiceId}/status"; - var response = await httpClient.GetAsync(url); - if (!response.IsSuccessStatusCode) - { - return false; - } - var raw = await response.Content.ReadAsStringAsync(); - var status = JObject.Parse(raw)["status"].ToString(); - return (status.Equals("complete", StringComparison.InvariantCultureIgnoreCase) || - status.Equals("confirmed", StringComparison.InvariantCultureIgnoreCase)); - ; - } } } #endif diff --git a/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml b/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml index fdc0efd0c..f569c8d0f 100644 --- a/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml +++ b/BTCPayServer/Views/Shared/Ethereum/UpdateChainConfig.cshtml @@ -20,7 +20,6 @@
-
@@ -45,20 +44,6 @@
- @{ - var valid = await EthereumConfigController.CheckValid(HttpClientFactory, BTCPayNetworkProvider.NetworkType, Model.InvoiceId); - if (!valid) - { -
- Support for this feature requires a one-time donation. - @if (!string.IsNullOrEmpty(Model.InvoiceId)) - { - The payment instructions associated has not been paid or confirmed yet. - } - Please click here to generate payment instructions. -
- } - }