mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
025da0261d
* new feature: Wallet Receive Page closes #965 * Conserve addresses by waiting till address is spent before generating each run * fix tests * Filter by cryptocode before matching outpoint * fix build * fix edge case issue * use address in keypathinfo directly * rebase fixes * rebase fixes * remove duplicate code * fix messy condition * fixes * fix e2e * fix
52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Events;
|
|
using BTCPayServer.Services.Wallets;
|
|
using Microsoft.Extensions.Hosting;
|
|
using NBXplorer;
|
|
|
|
namespace BTCPayServer.HostedServices
|
|
{
|
|
public class WalletReceiveCacheUpdater : IHostedService
|
|
{
|
|
private readonly EventAggregator _EventAggregator;
|
|
private readonly WalletReceiveStateService _WalletReceiveStateService;
|
|
|
|
private readonly CompositeDisposable _Leases = new CompositeDisposable();
|
|
|
|
public WalletReceiveCacheUpdater(EventAggregator eventAggregator,
|
|
WalletReceiveStateService walletReceiveStateService)
|
|
{
|
|
_EventAggregator = eventAggregator;
|
|
_WalletReceiveStateService = walletReceiveStateService;
|
|
}
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
_Leases.Add(_EventAggregator.Subscribe<WalletChangedEvent>(evt =>
|
|
_WalletReceiveStateService.Remove(evt.WalletId)));
|
|
|
|
_Leases.Add(_EventAggregator.Subscribe<NewOnChainTransactionEvent>(evt =>
|
|
{
|
|
var matching = _WalletReceiveStateService
|
|
.GetByDerivation(evt.CryptoCode, evt.NewTransactionEvent.DerivationStrategy).Where(pair =>
|
|
evt.NewTransactionEvent.Outputs.Any(output => output.ScriptPubKey == pair.Value.ScriptPubKey));
|
|
|
|
foreach (var keyValuePair in matching)
|
|
{
|
|
_WalletReceiveStateService.Remove(keyValuePair.Key);
|
|
}
|
|
}));
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_Leases.Dispose();
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|