< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Protocol.Factories.ChannelIdFactory
Assembly: NLightning.Infrastructure
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Infrastructure/Protocol/Factories/ChannelIdFactory.cs
Tag: 57_24045730253
Line coverage
60%
Covered lines: 9
Uncovered lines: 6
Coverable lines: 15
Total lines: 43
Line coverage: 60%
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
CreateTemporaryChannelId()100%210%
CreateV1(...)100%210%
CreateV2(...)100%11100%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Infrastructure/Protocol/Factories/ChannelIdFactory.cs

#LineLine coverage
 1using System.Security.Cryptography;
 2
 3namespace NLightning.Infrastructure.Protocol.Factories;
 4
 5using Crypto.Hashes;
 6using Domain.Bitcoin.ValueObjects;
 7using Domain.Channels.Constants;
 8using Domain.Channels.ValueObjects;
 9using Domain.Crypto.ValueObjects;
 10using Domain.Protocol.Interfaces;
 11
 12public class ChannelIdFactory : IChannelIdFactory
 13{
 14    public ChannelId CreateTemporaryChannelId()
 15    {
 016        return new ChannelId(RandomNumberGenerator.GetBytes(ChannelConstants.ChannelIdLength));
 17    }
 18
 19    public ChannelId CreateV1(TxId fundingTxId, ushort fundingOutputIndex)
 20    {
 021        Span<byte> channelId = stackalloc byte[32];
 022        ((ReadOnlySpan<byte>)fundingTxId).CopyTo(channelId);
 23
 24        // XOR the last 2 bytes with the funding_output_index
 025        channelId[30] ^= (byte)(fundingOutputIndex >> 8);
 026        channelId[31] ^= (byte)(fundingOutputIndex & 0xFF);
 27
 028        return new ChannelId(channelId);
 29    }
 30
 31    public ChannelId CreateV2(CompactPubKey lesserRevocationBasepoint, CompactPubKey greaterRevocationBasepoint)
 32    {
 433        Span<byte> combined = stackalloc byte[66];
 434        ((ReadOnlySpan<byte>)lesserRevocationBasepoint).CopyTo(combined);
 435        ((ReadOnlySpan<byte>)greaterRevocationBasepoint).CopyTo(combined[33..]);
 36
 437        using var hasher = new Sha256();
 438        hasher.AppendData(combined);
 439        Span<byte> hash = stackalloc byte[32];
 440        hasher.GetHashAndReset(hash);
 441        return new ChannelId(hash);
 442    }
 43}