< 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: 36_15743069263
Line coverage
94%
Covered lines: 17
Uncovered lines: 1
Coverable lines: 18
Total lines: 57
Line coverage: 94.4%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ScriptType()50%22100%
get_RemotePubKey()100%210%
.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
 7214    public override ScriptType ScriptType => _hasAnchorOutputs
 7215        ? ScriptType.P2WSH
 7216        : ScriptType.P2WPKH;
 17
 018    public PubKey RemotePubKey { get; }
 19
 20    public ToRemoteOutput(LightningMoney amount, bool hasAnchorOutputs, PubKey remotePubKey)
 7221        : base(amount, GenerateToRemoteScript(hasAnchorOutputs, remotePubKey))
 22    {
 7223        ArgumentNullException.ThrowIfNull(remotePubKey);
 24
 7225        _hasAnchorOutputs = hasAnchorOutputs;
 26
 7227        RemotePubKey = remotePubKey;
 7228    }
 29
 30    private static Script GenerateToRemoteScript(bool hasAnchorOutputs, PubKey remotePubKey)
 31    {
 7232        ArgumentNullException.ThrowIfNull(remotePubKey);
 33
 7234        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             */
 446            return new Script(
 447                Op.GetPushOp(remotePubKey.ToBytes()),
 448                OpcodeType.OP_CHECKSIGVERIFY,
 449                OpcodeType.OP_1,
 450                OpcodeType.OP_CHECKSEQUENCEVERIFY
 451            );
 52        }
 53
 54        // If we don't require anchor outputs, we'll return a P2WPKH redeemScript
 6855        return remotePubKey.WitHash.ScriptPubKey;
 56    }
 57}