< Summary - Combined Code Coverage

Information
Class: NLightning.Application.Channels.Handlers.OpenChannel1MessageHandler
Assembly: NLightning.Application
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Application/Channels/Handlers/OpenChannel1MessageHandler.cs
Tag: 36_15743069263
Line coverage
100%
Covered lines: 36
Uncovered lines: 0
Coverable lines: 36
Total lines: 83
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync()100%88100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Application/Channels/Handlers/OpenChannel1MessageHandler.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2
 3namespace NLightning.Application.Channels.Handlers;
 4
 5using Domain.Channels.Enums;
 6using Domain.Channels.Interfaces;
 7using Domain.Crypto.ValueObjects;
 8using Domain.Exceptions;
 9using Domain.Node.Options;
 10using Domain.Protocol.Interfaces;
 11using Domain.Protocol.Messages;
 12using Domain.Protocol.Tlv;
 13using Interfaces;
 14
 15public class OpenChannel1MessageHandler : IChannelMessageHandler<OpenChannel1Message>
 16{
 17    private readonly IChannelFactory _channelFactory;
 18    private readonly IChannelMemoryRepository _channelMemoryRepository;
 19    private readonly ILogger<OpenChannel1MessageHandler> _logger;
 20    private readonly IMessageFactory _messageFactory;
 21
 2022    public OpenChannel1MessageHandler(IChannelFactory channelFactory, IChannelMemoryRepository channelMemoryRepository,
 2023                                      ILogger<OpenChannel1MessageHandler> logger, IMessageFactory messageFactory)
 24    {
 2025        _channelFactory = channelFactory;
 2026        _channelMemoryRepository = channelMemoryRepository;
 2027        _logger = logger;
 2028        _messageFactory = messageFactory;
 2029    }
 30
 31    public async Task<IChannelMessage?> HandleAsync(OpenChannel1Message message, ChannelState currentState,
 32                                                    FeatureOptions negotiatedFeatures, CompactPubKey peerPubKey)
 33    {
 2034        _logger.LogTrace("Processing OpenChannel1Message with ChannelId: {ChannelId} from Peer: {PeerPubKey}",
 2035                         message.Payload.ChannelId, peerPubKey);
 36
 2037        var payload = message.Payload;
 38
 2039        if (currentState != ChannelState.None)
 440            throw new ChannelErrorException("A channel with this id already exists", payload.ChannelId);
 41
 42        // Check if there's a temporary channel for this peer
 1643        if (_channelMemoryRepository.TryGetTemporaryChannelState(peerPubKey, payload.ChannelId, out currentState))
 44        {
 845            if (currentState != ChannelState.V1Opening)
 46            {
 447                throw new ChannelErrorException("Channel had the wrong state", payload.ChannelId,
 448                                                "This channel is already being negotiated with peer");
 49            }
 50        }
 51
 52        // Create the channel
 1253        var channel = await _channelFactory.CreateChannelV1AsNonInitiatorAsync(message, negotiatedFeatures, peerPubKey);
 54
 1255        _logger.LogTrace("Created Channel with fundingPubKey: {fundingPubKey}",
 1256                         channel.LocalKeySet.FundingCompactPubKey);
 57
 58        // Add the channel to dictionaries
 1259        _channelMemoryRepository.AddTemporaryChannel(peerPubKey, channel);
 60
 61        // Create UpfrontShutdownScriptTlv if needed
 1262        UpfrontShutdownScriptTlv? upfrontShutdownScriptTlv = null;
 1263        if (channel.LocalUpfrontShutdownScript is not null)
 464            upfrontShutdownScriptTlv = new UpfrontShutdownScriptTlv(channel.LocalUpfrontShutdownScript.Value);
 65
 66        // TODO: Create the ChannelTypeTlv
 67
 68        // Create the reply message
 1269        var acceptChannel1ReplyMessage = _messageFactory
 1270           .CreateAcceptChannel1Message(channel.ChannelConfig.ChannelReserveAmount!, null,
 1271                                        channel.LocalKeySet.DelayedPaymentCompactBasepoint,
 1272                                        channel.LocalKeySet.CurrentPerCommitmentCompactPoint,
 1273                                        channel.LocalKeySet.FundingCompactPubKey,
 1274                                        channel.LocalKeySet.HtlcCompactBasepoint,
 1275                                        channel.ChannelConfig.MaxAcceptedHtlcs,
 1276                                        channel.ChannelConfig.MaxHtlcAmountInFlight, channel.ChannelConfig.MinimumDepth,
 1277                                        channel.LocalKeySet.PaymentCompactBasepoint,
 1278                                        channel.LocalKeySet.RevocationCompactBasepoint, channel.ChannelId,
 1279                                        channel.ChannelConfig.ToSelfDelay, upfrontShutdownScriptTlv);
 80
 1281        return acceptChannel1ReplyMessage;
 1282    }
 83}