2021-10-11 05:32:09 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-10-11 10:49:04 +02:00
|
|
|
using System.Threading;
|
2021-10-11 05:32:09 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Configuration;
|
|
|
|
using BTCPayServer.Data;
|
2021-10-11 10:49:04 +02:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-10-11 05:32:09 +02:00
|
|
|
using NBitcoin;
|
|
|
|
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
|
|
|
{
|
|
|
|
private readonly ApplicationDbContextFactory _applicationDbContextFactory;
|
|
|
|
|
|
|
|
public Cheater(BTCPayServerOptions opts, ApplicationDbContextFactory applicationDbContextFactory)
|
|
|
|
{
|
|
|
|
CashCow = new RPCClient(RPCCredentialString.Parse("server=http://127.0.0.1:43782;ceiwHEbqWI83:DwubwWsoo3"), Bitcoin.Instance.GetNetwork(opts.NetworkType));
|
|
|
|
_applicationDbContextFactory = applicationDbContextFactory;
|
|
|
|
}
|
|
|
|
public RPCClient CashCow
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task UpdateInvoiceExpiry(string invoiceId, DateTimeOffset dateTimeOffset)
|
|
|
|
{
|
|
|
|
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 10:49:04 +02:00
|
|
|
|
|
|
|
async Task IHostedService.StartAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
await CashCow.ScanRPCCapabilitiesAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
Task IHostedService.StopAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
2021-10-11 05:32:09 +02:00
|
|
|
}
|
|
|
|
}
|