diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj
index 4462ab7ad..da0db7209 100644
--- a/BTCPayServer/BTCPayServer.csproj
+++ b/BTCPayServer/BTCPayServer.csproj
@@ -2,7 +2,7 @@
Exe
netcoreapp2.0
- 1.0.1.2
+ 1.0.1.3
diff --git a/BTCPayServer/HostedServices/InvoiceWatcher.cs b/BTCPayServer/HostedServices/InvoiceWatcher.cs
index ebaee1f13..96569e541 100644
--- a/BTCPayServer/HostedServices/InvoiceWatcher.cs
+++ b/BTCPayServer/HostedServices/InvoiceWatcher.cs
@@ -408,11 +408,23 @@ namespace BTCPayServer.HostedServices
}
}
- private void Watch(string invoiceId)
+ private async Task Watch(string invoiceId)
{
if (invoiceId == null)
throw new ArgumentNullException(nameof(invoiceId));
_WatchRequests.Add(invoiceId);
+ var invoice = await _InvoiceRepository.GetInvoice(null, invoiceId);
+ try
+ {
+ var now = DateTimeOffset.UtcNow;
+ if (invoice.ExpirationTime > now)
+ {
+ await Task.Delay(invoice.ExpirationTime - now, _Cts.Token);
+ _WatchRequests.Add(invoiceId);
+ }
+ }
+ catch when (_Cts.IsCancellationRequested)
+ { }
}
BlockingCollection _WatchRequests = new BlockingCollection(new ConcurrentQueue());
@@ -430,7 +442,7 @@ namespace BTCPayServer.HostedServices
leases.Add(_EventAggregator.Subscribe(async b => { await NotifyBlock(); }));
leases.Add(_EventAggregator.Subscribe(async b => { await NotifyReceived(b.ScriptPubKey, b.Network); }));
- leases.Add(_EventAggregator.Subscribe(b => { Watch(b.InvoiceId); }));
+ leases.Add(_EventAggregator.Subscribe(async b => { await Watch(b.InvoiceId); }));
return Task.CompletedTask;
}