< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Bitcoin.Outputs.ToAnchorOutput
Assembly: NLightning.Infrastructure.Bitcoin
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Bitcoin/Outputs/ToAnchorOutput.cs
Tag: 30_15166811759
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 64
Line coverage: 93.3%
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
get_ScriptType()100%11100%
get_RemoteFundingPubKey()100%11100%
.ctor(...)100%11100%
FromTxOut(...)100%210%
GenerateAnchorScript(...)100%11100%

File(s)

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

#LineLine coverage
 1using NBitcoin;
 2
 3namespace NLightning.Infrastructure.Bitcoin.Outputs;
 4
 5using Domain.Money;
 6
 7/// <summary>
 8/// Represents a to_local_anchor/to_remote_anchor output in a commitment transaction.
 9/// </summary>
 10public class ToAnchorOutput : BaseOutput
 11{
 10412    public override ScriptType ScriptType => ScriptType.P2WSH;
 13
 10414    public PubKey RemoteFundingPubKey { get; set; }
 15
 16    public ToAnchorOutput(PubKey remoteFundingPubKey, LightningMoney amount)
 10417        : base(GenerateAnchorScript(remoteFundingPubKey), amount)
 18    {
 10419        RemoteFundingPubKey = remoteFundingPubKey;
 10420    }
 21
 22    /// <summary>
 23    /// Creates a ToAnchorOutput object from a NBitcoin.TxOut.
 24    /// </summary>
 25    /// <param name="txOut">The TxOut object.</param>
 26    /// <param name="remoteFundingPubKey">The remote funding public key.</param>
 27    /// <returns>A ToAnchorOutput object.</returns>
 28    public static ToAnchorOutput FromTxOut(TxOut txOut, PubKey remoteFundingPubKey)
 29    {
 030        return new ToAnchorOutput(remoteFundingPubKey, (ulong)txOut.Value.Satoshi);
 31    }
 32
 33    private static Script GenerateAnchorScript(PubKey pubKey)
 34    {
 35        /* The following script can be read as:
 36         ** spendingPubKey = the pubkey trying to sign this spend
 37         ** signature = the signature given by spendingPubKey
 38         ** nSequence = Provided by the spending transaction
 39         **
 40         ** if (signature is valid for local_funding_pubkey/remote_funding_pubkey)
 41         ** {
 42         **     return true
 43         ** }
 44         ** else
 45         ** {
 46         **     if (currentTransactionInputSequence < 16)
 47         **     {
 48         **         exit
 49         **     }
 50         ** }
 51         ** return true
 52         */
 53
 10454        return new Script(
 10455            Op.GetPushOp(pubKey.ToBytes()),
 10456            OpcodeType.OP_CHECKSIG,
 10457            OpcodeType.OP_IFDUP,
 10458            OpcodeType.OP_NOTIF,
 10459            OpcodeType.OP_16,
 10460            OpcodeType.OP_CHECKSEQUENCEVERIFY,
 10461            OpcodeType.OP_ENDIF
 10462        );
 63    }
 64}