return lock

This commit is contained in:
Kukks 2024-06-05 09:14:31 +02:00 committed by Dennis Reimann
parent 5ca19879b6
commit 3218db5815
No known key found for this signature in database
GPG key ID: 5009E1797F03F8D0
3 changed files with 13 additions and 6 deletions

View file

@ -46,7 +46,7 @@ public record TxResp(long Confirmations, long? Height, decimal BalanceChange, Da
//methods available on the hub in the server
public interface IBTCPayAppHubServer
{
Task IdentifierActive(string group, bool active);
Task<bool> IdentifierActive(string group, bool active);
Task<Dictionary<string,string>> Pair(PairRequest request);
Task<AppHandshakeResponse> Handshake(AppHandshake request);

View file

@ -300,9 +300,10 @@ var resultPsbt = PSBT.Parse(psbt, explorerClient.Network.NBitcoinNetwork);
}
public async Task IdentifierActive(string group, bool active)
public async Task<bool> IdentifierActive(string group, bool active)
{
await _appState.IdentifierActive(group, Context.ConnectionId, active);
return await _appState.IdentifierActive(group, Context.ConnectionId, active);
}

View file

@ -151,6 +151,11 @@ public class BTCPayAppState : IHostedService
{
if (TrackedSource.TryParse(ts, out var trackedSource, ExplorerClient.Network))
{
if (trackedSource is GroupTrackedSource groupTrackedSource)
{
}
ExplorerClient.Track(trackedSource);
}
await _hubContext.Groups.AddToGroupAsync(contextConnectionId, ts);
@ -193,16 +198,17 @@ public class BTCPayAppState : IHostedService
private CancellationTokenSource _cts;
public async Task IdentifierActive(string group, string contextConnectionId, bool active)
public async Task<bool> IdentifierActive(string group, string contextConnectionId, bool active)
{
if (active)
{
GroupToConnectionId.AddOrUpdate(group, contextConnectionId, (a, b) => contextConnectionId);
return GroupToConnectionId.TryAdd(group, contextConnectionId);
}
else if (GroupToConnectionId.TryGetValue(group, out var connId) && connId == contextConnectionId)
{
GroupToConnectionId.TryRemove(group, out _);
return GroupToConnectionId.TryRemove(group, out _);
}
return false;
}
public async Task Disconnected(string contextConnectionId)