2021-10-11 05:32:09 +02:00
|
|
|
using System;
|
2021-10-11 10:49:04 +02:00
|
|
|
using System.Threading;
|
2021-10-11 05:32:09 +02:00
|
|
|
using System.Threading.Tasks;
|
2022-11-24 00:53:32 +01:00
|
|
|
using BTCPayServer.Services.Invoices;
|
2021-10-11 10:49:04 +02:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-10-11 05:32:09 +02:00
|
|
|
using NBitcoin.RPC;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services
|
|
|
|
{
|
2021-10-11 10:49:04 +02:00
|
|
|
public class Cheater : IHostedService
|
2021-10-11 05:32:09 +02:00
|
|
|
{
|
2022-11-24 00:53:32 +01:00
|
|
|
private readonly InvoiceRepository _invoiceRepository;
|
|
|
|
public RPCClient CashCow { get; set; }
|
2021-10-11 05:32:09 +02:00
|
|
|
|
2022-11-24 00:53:32 +01:00
|
|
|
public Cheater(
|
|
|
|
ExplorerClientProvider prov,
|
|
|
|
InvoiceRepository invoiceRepository)
|
2021-10-11 05:32:09 +02: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 05:32:09 +02:00
|
|
|
}
|
|
|
|
|
2022-11-24 00:53:32 +01:00
|
|
|
public async Task UpdateInvoiceExpiry(string invoiceId, TimeSpan seconds)
|
2021-10-11 05:32:09 +02:00
|
|
|
{
|
2022-11-24 00:53:32 +01:00
|
|
|
await _invoiceRepository.UpdateInvoiceExpiry(invoiceId, seconds);
|
2021-10-11 05:32:09 +02:00
|
|
|
}
|
2021-10-11 10:49:04 +02:00
|
|
|
|
2021-10-12 08:45:55 +02:00
|
|
|
Task IHostedService.StartAsync(CancellationToken cancellationToken)
|
2021-10-11 10:49:04 +02:00
|
|
|
{
|
2022-11-24 00:53:32 +01:00
|
|
|
_ = CashCow?.ScanRPCCapabilitiesAsync(cancellationToken);
|
2021-10-12 08:45:55 +02:00
|
|
|
return Task.CompletedTask;
|
2021-10-11 10:49:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Task IHostedService.StopAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
2021-10-11 05:32:09 +02:00
|
|
|
}
|
|
|
|
}
|