< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Bitcoin.Outputs.ToRemoteOutput
Assembly: NLightning.Infrastructure.Bitcoin
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Bitcoin/Outputs/ToRemoteOutput.cs
Tag: 30_15166811759
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 57
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ScriptType()100%22100%
get_RemotePubKey()100%11100%
.ctor(...)100%11100%
GenerateToRemoteScript(...)100%22100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Bitcoin/Outputs/ToRemoteOutput.cs

#LineLine coverage
 1using NBitcoin;
 2
 3namespace NLightning.Infrastructure.Bitcoin.Outputs;
 4
 5using Domain.Money;
 6
 7/// <summary>
 8/// Represents a to_remote output in a commitment transaction.
 9/// </summary>
 10public class ToRemoteOutput : BaseOutput
 11{
 12    private readonly bool _hasAnchorOutputs;
 13
 18414    public override ScriptType ScriptType => _hasAnchorOutputs
 18415        ? ScriptType.P2WSH
 18416        : ScriptType.P2WPKH;
 17
 418    public PubKey RemotePubKey { get; }
 19
 20    public ToRemoteOutput(bool hasAnchorOutputs, PubKey remotePubKey, LightningMoney amount)
 17621        : base(GenerateToRemoteScript(hasAnchorOutputs, remotePubKey), amount)
 22    {
 17623        ArgumentNullException.ThrowIfNull(remotePubKey);
 24
 17625        _hasAnchorOutputs = hasAnchorOutputs;
 26
 17627        RemotePubKey = remotePubKey;
 17628    }
 29
 30    private static Script GenerateToRemoteScript(bool hasAnchorOutputs, PubKey remotePubKey)
 31    {
 17632        ArgumentNullException.ThrowIfNull(remotePubKey);
 33
 17634        if (hasAnchorOutputs)
 35        {
 36            /* The following script can be read as:
 37             ** spendingPubKey = the pubkey trying to sign this spend
 38             ** nSequence = Provided by the spending transaction
 39             **
 40             ** if (signature is valid for spendingPubKey && nSequence >= 1) {
 41             **     return true
 42             ** } else {
 43             **     return false
 44             ** }
 45             */
 8446            return new Script(
 8447                Op.GetPushOp(remotePubKey.ToBytes()),
 8448                OpcodeType.OP_CHECKSIGVERIFY,
 8449                OpcodeType.OP_1,
 8450                OpcodeType.OP_CHECKSEQUENCEVERIFY
 8451            );
 52        }
 53
 54        // If we don't require anchor outputs, we'll return a P2WPKH redeemScript
 9255        return remotePubKey.WitHash.ScriptPubKey;
 56    }
 57}