remove donation

This commit is contained in:
XPayServer
2020-09-18 12:30:13 +02:00
parent 7e60328cff
commit 1cf60acb29
4 changed files with 15 additions and 114 deletions

View File

@@ -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 "";

View File

@@ -33,9 +33,10 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services
private readonly Dictionary<int, CancellationTokenSource> _chainHostedServiceCancellationTokenSources =
new Dictionary<int, CancellationTokenSource>();
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<EthereumBTCPayNetwork>()
.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<EthereumLikeConfiguration> 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,

View File

@@ -69,7 +69,7 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.UI
{
var current = await _settingsRepository.GetSettingAsync<EthereumLikeConfiguration>(
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<IActionResult> CreateInvoice(int chainId)
{
var current = await _settingsRepository.GetSettingAsync<EthereumLikeConfiguration>(
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<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("choiceKey", $"license_{chainId}"),
new KeyValuePair<string, string>("posData",
JsonConvert.SerializeObject(new {Host = Request.Host, ChainId = chainId})),
new KeyValuePair<string, string>("orderID", $"eth_{Request.Host}_{chainId}"),
new KeyValuePair<string, string>("email", user.Email),
new KeyValuePair<string, string>("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<bool> 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

View File

@@ -20,7 +20,6 @@
<form method="post">
<div class="form-group">
<input type="hidden" asp-for="ChainId"/>
<input type="hidden" asp-for="InvoiceId"/>
<div class="form-check">
<label asp-for="Web3ProviderUrl" class="form-control-label"></label>
<input asp-for="Web3ProviderUrl" type="text" class="form-control"/>
@@ -45,20 +44,6 @@
<input asp-for="Web3ProviderPassword" type="text" class="form-control"/>
<span asp-validation-for="Web3ProviderPassword" class="text-danger"></span>
</div>
@{
var valid = await EthereumConfigController.CheckValid(HttpClientFactory, BTCPayNetworkProvider.NetworkType, Model.InvoiceId);
if (!valid)
{
<div class="alert alert-warning mt-2">
<span>Support for this feature requires a one-time donation.</span>
@if (!string.IsNullOrEmpty(Model.InvoiceId))
{
<span title="@Model.InvoiceId">The payment instructions associated has not been paid or confirmed yet.</span>
}
<a asp-action="CreateInvoice" asp-controller="EthereumConfig" asp-route-chainId="@Model.ChainId" class="alert-link">Please click here to generate payment instructions.</a>
</div>
}
}
</div>
<button type="submit" class="btn btn-primary" name="command" value="Save" id="saveButton">Save</button>