mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-23 22:46:49 +01:00
fixes
This commit is contained in:
parent
49aae758a9
commit
2b349bfc8a
4 changed files with 24 additions and 16 deletions
|
@ -43,7 +43,7 @@ public interface IBTCPayAppHubServer
|
|||
Task<CoinResponse[]> GetUTXOs(string[] identifiers);
|
||||
Task<Dictionary<string, TxResp[]>> GetTransactions(string[] identifiers);
|
||||
|
||||
Task SendPaymentUpdate(string identifier, LightningPayment lightningPayment);
|
||||
Task SendInvoiceUpdate(string identifier, LightningInvoice lightningInvoice);
|
||||
}
|
||||
|
||||
public class ServerEvent(string type)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -36,9 +36,9 @@ public class BTCPayAppState : IHostedService
|
|||
private DerivationSchemeParser _derivationSchemeParser;
|
||||
public readonly ConcurrentDictionary<string, string> GroupToConnectionId = new(StringComparer.InvariantCultureIgnoreCase);
|
||||
private CancellationTokenSource? _cts;
|
||||
// private readonly ConcurrentDictionary<string, TrackedSource> _connectionScheme = new();
|
||||
|
||||
public event EventHandler<(string,LightningInvoice)>? OnInvoiceUpdate;
|
||||
public event EventHandler<(string, LightningInvoice)>? OnInvoiceUpdate;
|
||||
|
||||
public BTCPayAppState(
|
||||
IHubContext<BTCPayAppHub, IBTCPayAppHubClient> hubContext,
|
||||
ILogger<BTCPayAppState> 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<PaymentMethodHandlerDictionary>().GetLightningHandler(ExplorerClient.CryptoCode).GetNodeInfo(
|
||||
new LightningPaymentMethodConfig() {InternalNodeRef = LightningPaymentMethodConfig.InternalNode},
|
||||
null,
|
||||
false, false);
|
||||
var res = await _serviceProvider.GetRequiredService<PaymentMethodHandlerDictionary>()
|
||||
.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<LightningListener>()?.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<string>? GroupRemoved;
|
||||
|
||||
|
||||
public async Task Connected(string contextConnectionId)
|
||||
{
|
||||
if (_nodeInfo.Length > 0)
|
||||
|
|
|
@ -102,8 +102,6 @@ public class BTCPayAppLightningClient:ILightningClient
|
|||
|
||||
return await HubClient.GetLightningPayment(uint256.Parse(paymentHash));
|
||||
}
|
||||
|
||||
|
||||
public async Task<Lightning.LightningPayment[]> ListPayments(CancellationToken cancellation = new CancellationToken())
|
||||
{
|
||||
return await ListPayments(new ListPaymentsParams(), cancellation);
|
||||
|
|
Loading…
Add table
Reference in a new issue