From 479fc50d9afadbf414dbe2c507b936688455e3e5 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sun, 12 Nov 2017 23:51:14 +0900 Subject: [PATCH] Add PendingInvoice inside CreateInvoice --- BTCPayServer/Controllers/InvoiceController.UI.cs | 4 ++-- BTCPayServer/Controllers/InvoiceController.cs | 3 +-- .../Services/Invoices/InvoiceRepository.cs | 14 ++------------ BTCPayServer/Services/Invoices/InvoiceWatcher.cs | 4 +--- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 44f2f35ca..0f2a25ba6 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -23,11 +23,11 @@ namespace BTCPayServer.Controllers [HttpPost] [Route("invoices/{invoiceId}")] - public async Task Invoice(string invoiceId, string command) + public IActionResult Invoice(string invoiceId, string command) { if (command == "refresh") { - await _Watcher.WatchAsync(invoiceId, true); + _Watcher.Watch(invoiceId); } StatusMessage = "Invoice is state is being refreshed, please refresh the page soon..."; return RedirectToAction(nameof(Invoice), new diff --git a/BTCPayServer/Controllers/InvoiceController.cs b/BTCPayServer/Controllers/InvoiceController.cs index a3b941c17..927a347f4 100644 --- a/BTCPayServer/Controllers/InvoiceController.cs +++ b/BTCPayServer/Controllers/InvoiceController.cs @@ -118,9 +118,8 @@ namespace BTCPayServer.Controllers entity.Rate = (double)await getRate; entity.PosData = invoice.PosData; entity.DepositAddress = await getAddress; - entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity); - await _Watcher.WatchAsync(entity.Id); + _Watcher.Watch(entity.Id); var resp = entity.EntityToDTO(); return new DataWrapper(resp) { Facade = "pos/invoice" }; } diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index db8e3839f..8a3f40d39 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -56,15 +56,6 @@ namespace BTCPayServer.Services.Invoices _ContextFactory = contextFactory; } - public async Task AddPendingInvoice(string invoiceId) - { - using (var ctx = _ContextFactory.CreateContext()) - { - ctx.PendingInvoices.Add(new PendingInvoiceData() { Id = invoiceId }); - await ctx.SaveChangesAsync(); - } - } - public async Task RemovePendingInvoice(string invoiceId) { using (var ctx = _ContextFactory.CreateContext()) @@ -119,7 +110,7 @@ namespace BTCPayServer.Services.Invoices invoice.StoreId = storeId; using (var context = _ContextFactory.CreateContext()) { - context.Add(new InvoiceData() + context.Invoices.Add(new InvoiceData() { StoreDataId = storeId, Id = invoice.Id, @@ -130,20 +121,19 @@ namespace BTCPayServer.Services.Invoices ItemCode = invoice.ProductInformation.ItemCode, CustomerEmail = invoice.RefundMail }); - context.AddressInvoices.Add(new AddressInvoiceData() { Address = invoice.DepositAddress.ScriptPubKey.Hash.ToString(), InvoiceDataId = invoice.Id, CreatedTime = DateTimeOffset.UtcNow, }); - context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData() { InvoiceDataId = invoice.Id, Address = invoice.DepositAddress.ToString(), Assigned = DateTimeOffset.UtcNow }); + context.PendingInvoices.Add(new PendingInvoiceData() { Id = invoice.Id }); await context.SaveChangesAsync().ConfigureAwait(false); } diff --git a/BTCPayServer/Services/Invoices/InvoiceWatcher.cs b/BTCPayServer/Services/Invoices/InvoiceWatcher.cs index c8541ae30..f716f0581 100644 --- a/BTCPayServer/Services/Invoices/InvoiceWatcher.cs +++ b/BTCPayServer/Services/Invoices/InvoiceWatcher.cs @@ -302,12 +302,10 @@ namespace BTCPayServer.Services.Invoices } } - public async Task WatchAsync(string invoiceId, bool singleShot = false) + public void Watch(string invoiceId) { if (invoiceId == null) throw new ArgumentNullException(nameof(invoiceId)); - if (!singleShot) - await _InvoiceRepository.AddPendingInvoice(invoiceId).ConfigureAwait(false); _WatchRequests.Add(invoiceId); }