< Summary - Combined Code Coverage

Information
Class: NLightning.Daemon.Services.NodeInfoQueryService
Assembly: NLightning.Daemon
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Services/NodeInfoQueryService.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 35
Coverable lines: 35
Total lines: 72
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
QueryAsync()0%4260%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Services/NodeInfoQueryService.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.Options;
 3
 4namespace NLightning.Daemon.Services;
 5
 6using Contracts.Control;
 7using Domain.Node.Options;
 8using Domain.Persistence.Interfaces;
 9using Domain.Protocol.Interfaces;
 10using Infrastructure.Transport.Interfaces;
 11using Interfaces;
 12
 13public sealed class NodeInfoQueryService : INodeInfoQueryService
 14{
 15    private readonly NodeOptions _nodeOptions;
 16    private readonly ISecureKeyManager _secureKeyManager;
 17    private readonly IServiceProvider _services;
 18    private readonly ITcpService _tcpService;
 19
 020    public NodeInfoQueryService(IOptions<NodeOptions> nodeOptions, ISecureKeyManager secureKeyManager,
 021                                IServiceProvider services, ITcpService tcpService)
 22    {
 023        _nodeOptions = nodeOptions.Value;
 024        _secureKeyManager = secureKeyManager;
 025        _services = services;
 026        _tcpService = tcpService;
 027    }
 28
 29    public async Task<NodeInfoResponse> QueryAsync(CancellationToken ct)
 30    {
 31        // resolve per-call scope to access repositories
 032        using var scope = _services.CreateScope();
 033        var uow = scope.ServiceProvider.GetService<IUnitOfWork>();
 34
 035        var bestHashHex = string.Empty;
 036        long bestHeight = 0;
 037        DateTimeOffset? bestTime = null;
 38
 039        if (uow is not null)
 40        {
 41            try
 42            {
 043                var state = await uow.BlockchainStateDbRepository.GetStateAsync();
 044                if (state is not null)
 45                {
 046                    bestHeight = state.LastProcessedHeight;
 047                    bestHashHex = state.LastProcessedBlockHash.ToString();
 048                    bestTime = state.LastProcessedAt;
 49                }
 050            }
 051            catch
 52            {
 53                // ignore, return defaults
 054            }
 55        }
 56
 057        var pubKeyString = _secureKeyManager.GetNodePubKey().ToString();
 058        var listeningToString = string.Join(',', _tcpService.ListeningTo.Select(e => e.ToString()).ToList());
 59
 060        return new NodeInfoResponse
 061        {
 062            PubKey = pubKeyString,
 063            ListeningTo = listeningToString,
 064            Network = _nodeOptions.BitcoinNetwork,
 065            BestBlockHash = bestHashHex,
 066            BestBlockHeight = bestHeight,
 067            BestBlockTime = bestTime,
 068            Implementation = "NLightning",
 069            Version = typeof(NodeInfoQueryService).Assembly.GetName().Version?.ToString()
 070        };
 071    }
 72}