2021-10-11 12:32:09 +09:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-10-11 17:49:04 +09:00
|
|
|
using System.Threading;
|
2021-10-11 12:32:09 +09:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Configuration;
|
|
|
|
using BTCPayServer.Data;
|
2021-10-11 17:49:04 +09:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-10-11 12:32:09 +09:00
|
|
|
using NBitcoin;
|
|
|
|
using NBitcoin.RPC;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services
|
|
|
|
{
|
2021-10-11 17:49:04 +09:00
|
|
|
public class Cheater : IHostedService
|
2021-10-11 12:32:09 +09:00
|
|
|
{
|
|
|
|
private readonly ApplicationDbContextFactory _applicationDbContextFactory;
|
|
|
|
|
2021-11-26 18:34:40 +09:00
|
|
|
public Cheater(BTCPayServerOptions opts, ExplorerClientProvider prov, ApplicationDbContextFactory applicationDbContextFactory)
|
2021-10-11 12:32:09 +09:00
|
|
|
{
|
2021-11-26 18:34:40 +09:00
|
|
|
CashCow = prov.GetExplorerClient("BTC").RPCClient;
|
2021-10-11 12:32:09 +09:00
|
|
|
_applicationDbContextFactory = applicationDbContextFactory;
|
|
|
|
}
|
|
|
|
public RPCClient CashCow
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task UpdateInvoiceExpiry(string invoiceId, DateTimeOffset dateTimeOffset)
|
|
|
|
{
|
2022-01-14 17:50:29 +09:00
|
|
|
using var ctx = _applicationDbContextFactory.CreateContext();
|
|
|
|
var invoiceData = await ctx.Invoices.FindAsync(invoiceId).ConfigureAwait(false);
|
|
|
|
if (invoiceData == null)
|
|
|
|
return;
|
|
|
|
// TODO change the expiry time. But how?
|
|
|
|
await ctx.SaveChangesAsync().ConfigureAwait(false);
|
2021-10-11 12:32:09 +09:00
|
|
|
}
|
2021-10-11 17:49:04 +09:00
|
|
|
|
2021-10-12 15:45:55 +09:00
|
|
|
Task IHostedService.StartAsync(CancellationToken cancellationToken)
|
2021-10-11 17:49:04 +09:00
|
|
|
{
|
2021-10-12 15:45:55 +09:00
|
|
|
_ = CashCow.ScanRPCCapabilitiesAsync();
|
|
|
|
return Task.CompletedTask;
|
2021-10-11 17:49:04 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
Task IHostedService.StopAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
2021-10-11 12:32:09 +09:00
|
|
|
}
|
|
|
|
}
|