< Summary - Combined Code Coverage

Information
Class: NLightning.Daemon.Services.NltgDaemonService
Assembly: NLightning.Daemon
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Services/NltgDaemonService.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 39
Coverable lines: 39
Total lines: 91
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
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%210140%
StopAsync()100%210%

File(s)

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

#LineLine coverage
 1using Microsoft.Extensions.Configuration;
 2using Microsoft.Extensions.Hosting;
 3using Microsoft.Extensions.Logging;
 4using Microsoft.Extensions.Options;
 5
 6namespace NLightning.Daemon.Services;
 7
 8using Domain.Bitcoin.Interfaces;
 9using Domain.Client.Interfaces;
 10using Domain.Node.Interfaces;
 11using Domain.Node.Options;
 12using Domain.Protocol.Interfaces;
 13using Infrastructure.Bitcoin.Wallet.Interfaces;
 14
 15public class NltgDaemonService : BackgroundService
 16{
 17    private readonly IBlockchainMonitor _blockchainMonitor;
 18    private readonly IConfiguration _configuration;
 19    private readonly IFeeService _feeService;
 20    private readonly ILogger<NltgDaemonService> _logger;
 21    private readonly INamedPipeIpcService _namedPipeIpcService;
 22    private readonly IPeerManager _peerManager;
 23    private readonly NodeOptions _nodeOptions;
 24    private readonly ISecureKeyManager _secureKeyManager;
 25
 026    public NltgDaemonService(IBlockchainMonitor blockchainMonitor, IConfiguration configuration, IFeeService feeService,
 027                             ILogger<NltgDaemonService> logger, INamedPipeIpcService namedPipeIpcService,
 028                             IOptions<NodeOptions> nodeOptions, IPeerManager peerManager,
 029                             ISecureKeyManager secureKeyManager)
 30    {
 031        _blockchainMonitor = blockchainMonitor;
 032        _configuration = configuration;
 033        _feeService = feeService;
 034        _logger = logger;
 035        _namedPipeIpcService = namedPipeIpcService;
 036        _peerManager = peerManager;
 037        _nodeOptions = nodeOptions.Value;
 038        _secureKeyManager = secureKeyManager;
 039    }
 40
 41    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 42    {
 043        var network = _configuration["network"] ?? _configuration["n"] ?? _nodeOptions.BitcoinNetwork;
 044        var isDaemon = _configuration.GetValue<bool?>("daemon")
 045                    ?? _configuration.GetValue<bool?>("daemon-child")
 046                    ?? _nodeOptions.Daemon;
 47
 048        if (_logger.IsEnabled(LogLevel.Information))
 049            _logger.LogInformation("NLTG Daemon started on {Network} network", network);
 50
 051        if (_logger.IsEnabled(LogLevel.Debug))
 52        {
 053            _logger.LogDebug("Running in daemon mode: {IsDaemon}", isDaemon);
 54
 055            var pubKey = _secureKeyManager.GetNodePubKey();
 056            _logger.LogDebug("Our PubKey is {pubKey}", pubKey.ToString());
 57        }
 58
 59        try
 60        {
 61            // Start the fee service
 062            await _feeService.StartAsync(stoppingToken);
 63
 64            // Start the peer manager service
 065            await _peerManager.StartAsync(stoppingToken);
 66
 67            // Start the blockchain monitor service
 068            await _blockchainMonitor.StartAsync(_secureKeyManager.HeightOfBirth, stoppingToken);
 69
 70            // Start the IPC server
 071            await _namedPipeIpcService.StartAsync(stoppingToken);
 72
 073            while (!stoppingToken.IsCancellationRequested)
 074                await Task.Delay(1000, stoppingToken);
 075        }
 076        catch (OperationCanceledException)
 77        {
 078            _logger.LogInformation("Stopping NLTG daemon service");
 079        }
 080    }
 81
 82    public override async Task StopAsync(CancellationToken cancellationToken)
 83    {
 084        _logger.LogInformation("NLTG shutdown requested");
 85
 086        await Task.WhenAll(_blockchainMonitor.StopAsync(), _feeService.StopAsync(), _peerManager.StopAsync(),
 087                           _namedPipeIpcService.StopAsync(), base.StopAsync(cancellationToken));
 88
 089        _logger.LogInformation("NLTG daemon service stopped");
 090    }
 91}