2021-10-11 12:32:09 +09:00
|
|
|
using System;
|
2021-10-11 17:49:04 +09:00
|
|
|
using System.Threading;
|
2021-10-11 12:32:09 +09:00
|
|
|
using System.Threading.Tasks;
|
2022-11-24 00:53:32 +01:00
|
|
|
using BTCPayServer.Services.Invoices;
|
2021-10-11 17:49:04 +09:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-10-11 12:32:09 +09:00
|
|
|
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
|
|
|
{
|
2022-11-24 00:53:32 +01:00
|
|
|
private readonly InvoiceRepository _invoiceRepository;
|
|
|
|
public RPCClient CashCow { get; set; }
|
2021-10-11 12:32:09 +09:00
|
|
|
|
2022-11-24 00:53:32 +01:00
|
|
|
public Cheater(
|
|
|
|
ExplorerClientProvider prov,
|
|
|
|
InvoiceRepository invoiceRepository)
|
2021-10-11 12:32:09 +09:00
|
|
|
{
|
2022-08-15 20:21:20 +02:00
|
|
|
CashCow = prov.GetExplorerClient("BTC")?.RPCClient;
|
2022-11-24 00:53:32 +01:00
|
|
|
_invoiceRepository = invoiceRepository;
|
2021-10-11 12:32:09 +09:00
|
|
|
}
|
|
|
|
|
2022-11-24 00:53:32 +01:00
|
|
|
public async Task UpdateInvoiceExpiry(string invoiceId, TimeSpan seconds)
|
2021-10-11 12:32:09 +09:00
|
|
|
{
|
2022-11-24 00:53:32 +01:00
|
|
|
await _invoiceRepository.UpdateInvoiceExpiry(invoiceId, seconds);
|
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
|
|
|
{
|
2022-11-24 00:53:32 +01:00
|
|
|
_ = CashCow?.ScanRPCCapabilitiesAsync(cancellationToken);
|
2021-10-12 15:45:55 +09:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|