< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.PayeePubKeyTaggedField
Assembly: NLightning.Bolt11.Blazor
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/PayeePubKeyTaggedField.cs
Tag: 49_19945309242
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 68
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%210%
get_Value()100%210%
get_Length()100%210%
.ctor(...)100%210%
WriteToBitWriter(...)100%210%
IsValid()100%210%
FromBitReader(...)0%620%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/PayeePubKeyTaggedField.cs

#LineLine coverage
 1using NBitcoin;
 2
 3namespace NLightning.Bolt11.Models.TaggedFields;
 4
 5using Constants;
 6using Domain.Utils;
 7using Enums;
 8using Interfaces;
 9
 10/// <summary>
 11/// Tagged field for the payee public key
 12/// </summary>
 13/// <remarks>
 14/// The payee public key is a 33-byte public key used to identify the payee
 15/// </remarks>
 16/// <seealso cref="ITaggedField"/>
 17internal sealed class PayeePubKeyTaggedField : ITaggedField
 18{
 019    public TaggedFieldTypes Type => TaggedFieldTypes.PayeePubKey;
 020    internal PubKey Value { get; }
 021    public short Length => TaggedFieldConstants.PayeePubkeyLength;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="ExpiryTimeTaggedField"/> class.
 25    /// </summary>
 26    /// <param name="value">The Expiry Time in seconds</param>
 027    internal PayeePubKeyTaggedField(PubKey value)
 28    {
 029        Value = value;
 030    }
 31
 32    /// <inheritdoc/>
 33    public void WriteToBitWriter(BitWriter bitWriter)
 34    {
 35        // Write data
 036        bitWriter.WriteBits(Value.ToBytes(), Length * 5);
 037    }
 38
 39    /// <inheritdoc/>
 40    public bool IsValid()
 41    {
 042        return true;
 43    }
 44
 45    /// <summary>
 46    /// Reads a PayeePubKeyTaggedField from a BitReader
 47    /// </summary>
 48    /// <param name="bitReader">The BitReader to read from</param>
 49    /// <param name="length">The length of the field</param>
 50    /// <returns>The PayeePubKeyTaggedField</returns>
 51    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 52    internal static PayeePubKeyTaggedField FromBitReader(BitReader bitReader, short length)
 53    {
 054        if (length != TaggedFieldConstants.PayeePubkeyLength)
 055            throw new ArgumentException(
 056                $"Invalid length for {nameof(PayeePubKeyTaggedField)}. Expected {TaggedFieldConstants.PayeePubkeyLength}
 57
 58        // Read the data from the BitReader
 59        // For 53 groups of 5 bits = 265 bits, we need 34 bytes to read, with one padding byte
 060        var data = new byte[(length * 5 + 7) / 8];
 061        bitReader.ReadBits(data, length * 5);
 62
 63        // Remove the padding byte
 064        data = data[..^1];
 65
 066        return new PayeePubKeyTaggedField(new PubKey(data));
 67    }
 68}