< Summary - Combined Code Coverage

Information
Class: NLightning.Application.NLTG.Services.NltgDaemonService
Assembly: NLightning.Application.NLTG
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Application.NLTG/Services/NltgDaemonService.cs
Tag: 30_15166811759
Line coverage
0%
Covered lines: 0
Uncovered lines: 31
Coverable lines: 31
Total lines: 74
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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%
ExecuteAsync()0%110100%
StopAsync()100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Application.NLTG/Services/NltgDaemonService.cs

#LineLine coverage
 1using Microsoft.Extensions.Configuration;
 2using Microsoft.Extensions.Hosting;
 3using Microsoft.Extensions.Logging;
 4using Microsoft.Extensions.Options;
 5
 6namespace NLightning.Application.NLTG.Services;
 7
 8using Domain.Bitcoin.Services;
 9using Domain.Node.Options;
 10using Domain.Protocol.Managers;
 11using Interfaces;
 12
 13public class NltgDaemonService : BackgroundService
 14{
 15    private readonly IConfiguration _configuration;
 16    private readonly IFeeService _feeService;
 17    private readonly ILogger<NltgDaemonService> _logger;
 18    private readonly NodeOptions _nodeOptions;
 19    private readonly ISecureKeyManager _secureKeyManager;
 20    private readonly ITcpListenerService _tcpListenerService;
 21
 022    public NltgDaemonService(IConfiguration configuration, IFeeService feeService, ILogger<NltgDaemonService> logger,
 023                             IOptions<NodeOptions> nodeOptions, ISecureKeyManager secureKeyManager,
 024                             ITcpListenerService tcpListenerService)
 25    {
 026        _configuration = configuration;
 027        _feeService = feeService;
 028        _logger = logger;
 029        _nodeOptions = nodeOptions.Value;
 030        _secureKeyManager = secureKeyManager;
 031        _tcpListenerService = tcpListenerService;
 032    }
 33
 34    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 35    {
 036        var network = _configuration["network"] ?? _configuration["n"] ?? _nodeOptions.Network;
 037        var isDaemon = _configuration.GetValue<bool?>("daemon")
 038                       ?? _configuration.GetValue<bool?>("daemon-child")
 039                       ?? _nodeOptions.Daemon;
 40
 041        _logger.LogInformation("NLTG Daemon started on {Network} network", network);
 042        _logger.LogDebug("Running in daemon mode: {IsDaemon}", isDaemon);
 43
 044        var pubKey = _secureKeyManager.GetNodePubKey();
 045        _logger.LogDebug("lncli connect {pubKey}@docker.for.mac.host.internal:9735", pubKey.ToString());
 46
 47        try
 48        {
 49            // Start the fee service
 050            await _feeService.StartAsync(stoppingToken);
 51
 52            // Start listening for connections
 053            await _tcpListenerService.StartAsync(stoppingToken);
 54
 055            while (!stoppingToken.IsCancellationRequested)
 56            {
 057                await Task.Delay(1000, stoppingToken);
 58            }
 059        }
 060        catch (OperationCanceledException)
 61        {
 062            _logger.LogInformation("Stopping NLTG daemon service");
 063        }
 064    }
 65
 66    public override async Task StopAsync(CancellationToken cancellationToken)
 67    {
 068        _logger.LogInformation("NLTG shutdown requested");
 69
 070        await Task.WhenAll(_feeService.StopAsync(), _tcpListenerService.StopAsync(), base.StopAsync(cancellationToken));
 71
 072        _logger.LogInformation("NLTG daemon service stopped");
 073    }
 74}