< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Bitcoin.Outputs.BaseOutput
Assembly: NLightning.Infrastructure.Bitcoin
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Bitcoin/Outputs/BaseOutput.cs
Tag: 30_15166811759
Line coverage
92%
Covered lines: 39
Uncovered lines: 3
Coverable lines: 42
Total lines: 97
Line coverage: 92.8%
Branch coverage
72%
Covered branches: 13
Total branches: 18
Branch coverage: 72.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Amount()100%11100%
get_ScriptPubKey()100%11100%
get_TxId()100%11100%
get_Index()100%11100%
get_RedeemScript()100%11100%
.ctor(...)100%11100%
.ctor(...)66.67%6.05688.89%
ToTxOut()100%11100%
ToCoin()70%10.291085.71%
CompareTo(...)100%22100%

File(s)

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

#LineLine coverage
 1using NBitcoin;
 2
 3namespace NLightning.Infrastructure.Bitcoin.Outputs;
 4
 5using Comparers;
 6using Domain.Money;
 7
 8/// <summary>
 9/// Represents a transaction output.
 10/// </summary>
 11public abstract class BaseOutput
 12{
 13    /// <summary>
 14    /// Gets the amount of the output in satoshis.
 15    /// </summary>
 446016    public LightningMoney Amount { get; set; }
 17
 18    /// <summary>
 19    /// Gets the scriptPubKey of the output.
 20    /// </summary>
 105221    public Script ScriptPubKey { get; }
 22
 23    /// <summary>
 24    /// Gets or sets the transaction ID of the output.
 25    /// </summary>
 288026    public uint256? TxId { get; set; }
 27
 28    /// <summary>
 29    /// Gets or sets the index of the output in the transaction.
 30    /// </summary>
 31    /// <remarks>
 32    /// Output is nonexistent if this is -1.
 33    /// </remarks>
 252034    public int Index { get; set; }
 35
 26836    public Script RedeemScript { get; }
 37
 38    public abstract ScriptType ScriptType { get; }
 39
 4440    protected BaseOutput(Script redeemScript, Script scriptPubKey, LightningMoney amount)
 41    {
 4442        ArgumentNullException.ThrowIfNull(redeemScript);
 4443        ArgumentNullException.ThrowIfNull(scriptPubKey);
 4444        ArgumentNullException.ThrowIfNull(amount);
 45
 4446        Amount = amount;
 4447        RedeemScript = redeemScript;
 4448        ScriptPubKey = scriptPubKey;
 4449        TxId = uint256.Zero;
 4450        Index = -1;
 4451    }
 131652    protected BaseOutput(Script redeemScript, LightningMoney amount)
 53    {
 131654        ArgumentNullException.ThrowIfNull(redeemScript);
 131655        ArgumentNullException.ThrowIfNull(amount);
 56
 131657        Amount = amount;
 131658        RedeemScript = redeemScript;
 131659        ScriptPubKey = ScriptType switch
 131660        {
 131661            ScriptType.P2WPKH
 131662                or ScriptType.P2WSH
 149263                when redeemScript.ToString().StartsWith("0 ") => redeemScript,
 131664            ScriptType.P2WPKH
 114065                or ScriptType.P2WSH => redeemScript.WitHash.ScriptPubKey,
 066            ScriptType.P2SH => redeemScript.Hash.ScriptPubKey,
 067            _ => redeemScript.PaymentScript
 131668        };
 131669        TxId = uint256.Zero;
 131670        Index = -1;
 131671    }
 72
 73    /// <summary>
 74    /// Converts the output to a NBitcoin.TxOut.
 75    /// </summary>
 76    /// <returns>TxOut object.</returns>
 77    public TxOut ToTxOut()
 78    {
 51279        return new TxOut((Money)Amount, ScriptPubKey);
 80    }
 81
 82    public ScriptCoin ToCoin()
 83    {
 18084        if (Index == -1)
 1685            throw new InvalidOperationException("Output is nonexistent. Sign the transaction first.");
 86
 16487        if (TxId is null || TxId == uint256.Zero || TxId == uint256.One)
 088            throw new InvalidOperationException("Transaction ID is not set. Sign the transaction first.");
 89
 16490        if (Amount.IsZero)
 491            throw new InvalidOperationException("You can't spend a zero amount output.");
 92
 16093        return new ScriptCoin(TxId, checked((uint)Index), Amount, ScriptPubKey, RedeemScript);
 94    }
 95
 2496    public int CompareTo(BaseOutput? other) => other is null ? 1 : TransactionOutputComparer.Instance.Compare(this, othe
 97}