< Summary - Combined Code Coverage

Information
Class: NLightning.Daemon.Ipc.Handlers.NodeInfoIpcHandler
Assembly: NLightning.Daemon
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Ipc/Handlers/NodeInfoIpcHandler.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 60
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Command()100%210%
.ctor(...)100%210%
HandleAsync()100%210%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Ipc/Handlers/NodeInfoIpcHandler.cs

#LineLine coverage
 1using MessagePack;
 2using Microsoft.Extensions.Logging;
 3
 4namespace NLightning.Daemon.Ipc.Handlers;
 5
 6using Daemon.Interfaces;
 7using Domain.Client.Constants;
 8using Domain.Client.Enums;
 9using Domain.Crypto.ValueObjects;
 10using Interfaces;
 11using Services.Ipc.Factories;
 12using Transport.Ipc;
 13using Transport.Ipc.Responses;
 14
 15internal sealed class NodeInfoIpcHandler : IIpcCommandHandler
 16{
 17    private readonly INodeInfoQueryService _query;
 18    private readonly ILogger<NodeInfoIpcHandler> _logger;
 19
 020    public ClientCommand Command => ClientCommand.NodeInfo;
 21
 022    public NodeInfoIpcHandler(INodeInfoQueryService query, ILogger<NodeInfoIpcHandler> logger)
 23    {
 024        _query = query;
 025        _logger = logger;
 026    }
 27
 28    public async Task<IpcEnvelope> HandleAsync(IpcEnvelope envelope, CancellationToken ct)
 29    {
 30        try
 31        {
 032            var resp = await _query.QueryAsync(ct);
 033            var ipcResp = new NodeInfoIpcResponse
 034            {
 035                PubKey = new CompactPubKey(Convert.FromHexString(resp.PubKey)),
 036                ListeningTo = resp.ListeningTo.Split(',').ToList(),
 037                Network = resp.Network,
 038                BestBlockHash = new Hash(Convert.FromHexString(resp.BestBlockHash)),
 039                BestBlockHeight = resp.BestBlockHeight,
 040                BestBlockTime = resp.BestBlockTime,
 041                Implementation = resp.Implementation,
 042                Version = resp.Version
 043            };
 044            var payload = MessagePackSerializer.Serialize(ipcResp, cancellationToken: ct);
 045            return new IpcEnvelope
 046            {
 047                Version = envelope.Version,
 048                Command = envelope.Command,
 049                CorrelationId = envelope.CorrelationId,
 050                Kind = IpcEnvelopeKind.Response,
 051                Payload = payload
 052            };
 53        }
 054        catch (Exception e)
 55        {
 056            _logger.LogError(e, "Error handling node info");
 057            return IpcErrorFactory.CreateErrorEnvelope(envelope, ErrorCodes.ServerError, e.Message);
 58        }
 059    }
 60}