From 08beffb0051ff9d0e2aafef69bc0e12f827bf2e7 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sun, 5 Apr 2020 16:50:19 +0900 Subject: [PATCH] Make sure FindPaymentViaPolling does not requests over and over the same coins --- BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs index e6b1b8eff..52fe3b2c0 100644 --- a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs +++ b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs @@ -320,6 +320,8 @@ namespace BTCPayServer.Payments.Bitcoin { int totalPayment = 0; var invoices = await _InvoiceRepository.GetPendingInvoices(); + var coinsPerDerivationStrategy = + new Dictionary(); foreach (var invoiceId in invoices) { var invoice = await _InvoiceRepository.GetInvoice(invoiceId, true); @@ -334,8 +336,13 @@ namespace BTCPayServer.Payments.Bitcoin if (!invoice.Support(cryptoId)) continue; - var coins = (await wallet.GetUnspentCoins(strategy)) - .Where(c => invoice.AvailableAddressHashes.Contains(c.ScriptPubKey.Hash.ToString() + cryptoId)) + + if (!coinsPerDerivationStrategy.TryGetValue(strategy, out var coins)) + { + coins = await wallet.GetUnspentCoins(strategy); + coinsPerDerivationStrategy.Add(strategy, coins); + } + coins = coins.Where(c => invoice.AvailableAddressHashes.Contains(c.ScriptPubKey.Hash.ToString() + cryptoId)) .ToArray(); foreach (var coin in coins.Where(c => !alreadyAccounted.Contains(c.OutPoint))) {