< 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: 36_15743069263
Line coverage
64%
Covered lines: 9
Uncovered lines: 5
Coverable lines: 14
Total lines: 35
Line coverage: 64.2%
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
CreateV1(...)100%210%
CreateV2(...)100%11100%

File(s)

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

#LineLine coverage
 1namespace NLightning.Infrastructure.Protocol.Factories;
 2
 3using Crypto.Hashes;
 4using Domain.Bitcoin.ValueObjects;
 5using Domain.Channels.ValueObjects;
 6using Domain.Crypto.ValueObjects;
 7using Domain.Protocol.Interfaces;
 8
 9public class ChannelIdFactory : IChannelIdFactory
 10{
 11    public ChannelId CreateV1(TxId fundingTxId, ushort fundingOutputIndex)
 12    {
 013        Span<byte> channelId = stackalloc byte[32];
 014        ((ReadOnlySpan<byte>)fundingTxId).CopyTo(channelId);
 15
 16        // XOR the last 2 bytes with the funding_output_index
 017        channelId[30] ^= (byte)(fundingOutputIndex >> 8);
 018        channelId[31] ^= (byte)(fundingOutputIndex & 0xFF);
 19
 020        return new ChannelId(channelId);
 21    }
 22
 23    public ChannelId CreateV2(CompactPubKey lesserRevocationBasepoint, CompactPubKey greaterRevocationBasepoint)
 24    {
 425        Span<byte> combined = stackalloc byte[66];
 426        ((ReadOnlySpan<byte>)lesserRevocationBasepoint).CopyTo(combined);
 427        ((ReadOnlySpan<byte>)greaterRevocationBasepoint).CopyTo(combined[33..]);
 28
 429        using var hasher = new Sha256();
 430        hasher.AppendData(combined);
 431        Span<byte> hash = stackalloc byte[32];
 432        hasher.GetHashAndReset(hash);
 433        return new ChannelId(hash);
 434    }
 35}