< Summary - Combined Code Coverage

Information
Class: NLightning.Daemon.Ipc.Handlers.GetWalletBalanceIpcHandler
Assembly: NLightning.Daemon
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Daemon/Ipc/Handlers/GetWalletBalanceIpcHandler.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 64
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/GetWalletBalanceIpcHandler.cs

#LineLine coverage
 1using MessagePack;
 2using Microsoft.Extensions.Logging;
 3
 4namespace NLightning.Daemon.Ipc.Handlers;
 5
 6using Domain.Bitcoin.Interfaces;
 7using Domain.Client.Constants;
 8using Domain.Client.Enums;
 9using Infrastructure.Bitcoin.Wallet.Interfaces;
 10using Interfaces;
 11using Services.Ipc.Factories;
 12using Transport.Ipc;
 13using Transport.Ipc.Responses;
 14
 15internal class GetWalletBalanceIpcHandler : IIpcCommandHandler
 16{
 17    private readonly IBlockchainMonitor _blockchainMonitor;
 18    private readonly ILogger<GetWalletBalanceIpcHandler> _logger;
 19    private readonly IUtxoMemoryRepository _utxoMemoryRepository;
 020    public ClientCommand Command => ClientCommand.WalletBalance;
 21
 022    public GetWalletBalanceIpcHandler(IBlockchainMonitor blockchainMonitor, ILogger<GetWalletBalanceIpcHandler> logger,
 023                                      IUtxoMemoryRepository utxoMemoryRepository)
 24    {
 025        _blockchainMonitor = blockchainMonitor;
 026        _logger = logger;
 027        _utxoMemoryRepository = utxoMemoryRepository;
 028    }
 29
 30    public Task<IpcEnvelope> HandleAsync(IpcEnvelope envelope, CancellationToken ct)
 31    {
 32        try
 33        {
 034            var currentBlockHeight = _blockchainMonitor.LastProcessedBlockHeight;
 035            var confirmedBalance = _utxoMemoryRepository.GetConfirmedBalance(currentBlockHeight);
 036            var unconfirmedBalance = _utxoMemoryRepository.GetUnconfirmedBalance(currentBlockHeight);
 37
 38            // Create a success response
 039            var response = new WalletBalanceIpcResponse
 040            {
 041                ConfirmedBalance = confirmedBalance,
 042                UnconfirmedBalance = unconfirmedBalance
 043            };
 44
 045            var payload = MessagePackSerializer.Serialize(response, cancellationToken: ct);
 046            var respEnvelope = new IpcEnvelope
 047            {
 048                Version = envelope.Version,
 049                Command = envelope.Command,
 050                CorrelationId = envelope.CorrelationId,
 051                Kind = IpcEnvelopeKind.Response,
 052                Payload = payload
 053            };
 54
 055            return Task.FromResult(respEnvelope);
 56        }
 057        catch (Exception e)
 58        {
 059            _logger.LogError(e, "Error getting a unused address");
 060            return Task.FromResult(IpcErrorFactory.CreateErrorEnvelope(envelope, ErrorCodes.ServerError,
 061                                                                       $"Error getting a unused address: {e.Message}"));
 62        }
 063    }
 64}