From 2b349bfc8a2fb69a1adae30ccaad57828bfd68f0 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 23 Jul 2024 10:24:12 +0200 Subject: [PATCH] fixes --- BTCPayApp.CommonServer/IBTCPayAppHubClient.cs | 2 +- BTCPayServer/App/BTCPayAppHub.cs | 2 +- BTCPayServer/App/BTCPayAppState.cs | 34 ++++++++++++------- BTCPayServer/App/LN.cs | 2 -- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/BTCPayApp.CommonServer/IBTCPayAppHubClient.cs b/BTCPayApp.CommonServer/IBTCPayAppHubClient.cs index 12e5a76c5..7ccd81fd6 100644 --- a/BTCPayApp.CommonServer/IBTCPayAppHubClient.cs +++ b/BTCPayApp.CommonServer/IBTCPayAppHubClient.cs @@ -43,7 +43,7 @@ public interface IBTCPayAppHubServer Task GetUTXOs(string[] identifiers); Task> GetTransactions(string[] identifiers); - Task SendPaymentUpdate(string identifier, LightningPayment lightningPayment); + Task SendInvoiceUpdate(string identifier, LightningInvoice lightningInvoice); } public class ServerEvent(string type) diff --git a/BTCPayServer/App/BTCPayAppHub.cs b/BTCPayServer/App/BTCPayAppHub.cs index ddfaf655f..7407313f1 100644 --- a/BTCPayServer/App/BTCPayAppHub.cs +++ b/BTCPayServer/App/BTCPayAppHub.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BTCPayApp.CommonServer; -using BTCPayApp.CommonServer.Models; using BTCPayServer.Abstractions.Constants; using BTCPayServer.Data; using BTCPayServer.Events; using BTCPayServer.HostedServices; +using BTCPayServer.Lightning; using BTCPayServer.Services; using BTCPayServer.Services.Stores; using BTCPayServer.Services.Wallets; diff --git a/BTCPayServer/App/BTCPayAppState.cs b/BTCPayServer/App/BTCPayAppState.cs index 2f82c95c7..2ff5d5b60 100644 --- a/BTCPayServer/App/BTCPayAppState.cs +++ b/BTCPayServer/App/BTCPayAppState.cs @@ -36,9 +36,9 @@ public class BTCPayAppState : IHostedService private DerivationSchemeParser _derivationSchemeParser; public readonly ConcurrentDictionary GroupToConnectionId = new(StringComparer.InvariantCultureIgnoreCase); private CancellationTokenSource? _cts; - // private readonly ConcurrentDictionary _connectionScheme = new(); - public event EventHandler<(string,LightningInvoice)>? OnInvoiceUpdate; + public event EventHandler<(string, LightningInvoice)>? OnInvoiceUpdate; + public BTCPayAppState( IHubContext hubContext, ILogger logger, @@ -90,7 +90,7 @@ public class BTCPayAppState : IHostedService await _hubContext.Clients.Group(arg.StoreId).NotifyServerEvent(new ServerEvent("store-created") { StoreId = arg.StoreId }); } - private async Task StoreUpdatedEvent(StoreUpdatedEvent arg) + private async Task StoreUpdatedEvent(StoreUpdatedEvent arg) { await _hubContext.Clients.Group(arg.StoreId).NotifyServerEvent(new ServerEvent("store-updated") { StoreId = arg.StoreId }); } @@ -128,16 +128,21 @@ public class BTCPayAppState : IHostedService } private string _nodeInfo = string.Empty; + private async Task UpdateNodeInfo() { while (!_cts.Token.IsCancellationRequested) { try { - var res = await _serviceProvider.GetRequiredService().GetLightningHandler(ExplorerClient.CryptoCode).GetNodeInfo( - new LightningPaymentMethodConfig() {InternalNodeRef = LightningPaymentMethodConfig.InternalNode}, - null, - false, false); + var res = await _serviceProvider.GetRequiredService() + .GetLightningHandler(ExplorerClient.CryptoCode).GetNodeInfo( + new LightningPaymentMethodConfig() + { + InternalNodeRef = LightningPaymentMethodConfig.InternalNode + }, + null, + false, false); if (res.Any()) { var newInf = res.First(); @@ -145,6 +150,7 @@ public class BTCPayAppState : IHostedService { newInf = new NodeInfo(newInf.NodeId, "127.0.0.1", 30893); } + if (newInf.ToString() != _nodeInfo) { _nodeInfo = newInf.ToString(); @@ -156,11 +162,12 @@ public class BTCPayAppState : IHostedService { _logger.LogError(e, "Error during node info update"); } - await Task.Delay(TimeSpan.FromMinutes(string.IsNullOrEmpty(_nodeInfo)? 1:5), _cts.Token); + + await Task.Delay(TimeSpan.FromMinutes(string.IsNullOrEmpty(_nodeInfo) ? 1 : 5), _cts.Token); } } - private async Task OnNewTransaction(NewOnChainTransactionEvent obj) + private async Task OnNewTransaction(NewOnChainTransactionEvent obj) { if (obj.CryptoCode != "BTC") return; @@ -205,11 +212,11 @@ public class BTCPayAppState : IHostedService { if (trackedSource is GroupTrackedSource groupTrackedSource) { - } - + ExplorerClient.Track(trackedSource); } + await _hubContext.Groups.AddToGroupAsync(contextConnectionId, ts); } catch (Exception e) @@ -257,12 +264,15 @@ public class BTCPayAppState : IHostedService _serviceProvider.GetService()?.CheckConnection(ExplorerClient.CryptoCode, connString); return true; } + return false; } + if (GroupToConnectionId.TryGetValue(group, out var connId) && connId == contextConnectionId) { return GroupToConnectionId.TryRemove(group, out _); } + return false; } @@ -279,7 +289,7 @@ public class BTCPayAppState : IHostedService } public event EventHandler? GroupRemoved; - + public async Task Connected(string contextConnectionId) { if (_nodeInfo.Length > 0) diff --git a/BTCPayServer/App/LN.cs b/BTCPayServer/App/LN.cs index 06d79b067..2dd2725f8 100644 --- a/BTCPayServer/App/LN.cs +++ b/BTCPayServer/App/LN.cs @@ -102,8 +102,6 @@ public class BTCPayAppLightningClient:ILightningClient return await HubClient.GetLightningPayment(uint256.Parse(paymentHash)); } - - public async Task ListPayments(CancellationToken cancellation = new CancellationToken()) { return await ListPayments(new ListPaymentsParams(), cancellation);