| | 1 | | using NBitcoin; |
| | 2 | |
|
| | 3 | | namespace NLightning.Domain.Protocol.Payloads; |
| | 4 | |
|
| | 5 | | using Interfaces; |
| | 6 | | using Messages; |
| | 7 | | using Money; |
| | 8 | | using ValueObjects; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Represents a tx_add_output payload. |
| | 12 | | /// </summary> |
| | 13 | | /// <remarks> |
| | 14 | | /// The tx_add_output payload is used to add an output to the transaction. |
| | 15 | | /// </remarks> |
| | 16 | | /// <seealso cref="TxAddOutputMessage"/> |
| | 17 | | /// <seealso cref="ValueObjects.ChannelId"/> |
| | 18 | | public class TxAddOutputPayload : IMessagePayload |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// The channel id. |
| | 22 | | /// </summary> |
| 8 | 23 | | public ChannelId ChannelId { get; } |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// The serial id. |
| | 27 | | /// </summary> |
| 8 | 28 | | public ulong SerialId { get; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// The sats amount. |
| | 32 | | /// </summary> |
| 8 | 33 | | public LightningMoney Amount { get; } |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// The spending script. |
| | 37 | | /// </summary> |
| 12 | 38 | | public Script Script { get; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Initializes a new instance of the <see cref="TxAddOutputPayload"/> class. |
| | 42 | | /// </summary> |
| | 43 | | /// <param name="channelId">The channel id.</param> |
| | 44 | | /// <param name="serialId">The serial id.</param> |
| | 45 | | /// <param name="amount">The sats amount.</param> |
| | 46 | | /// <param name="script">The spending script.</param> |
| | 47 | | /// <exception cref="ArgumentException">ScriptPubKey length is out of bounds.</exception> |
| 12 | 48 | | public TxAddOutputPayload(LightningMoney amount, ChannelId channelId, Script script, ulong serialId) |
| | 49 | | { |
| | 50 | | // Check if script is only types P2WSH, P2WPKH, or P2TR using NBitcoin |
| 12 | 51 | | if (!PayToWitScriptHashTemplate.Instance.CheckScriptPubKey(script) |
| 12 | 52 | | && !PayToWitPubKeyHashTemplate.Instance.CheckScriptPubKey(script) |
| 12 | 53 | | && !PayToTaprootTemplate.Instance.CheckScriptPubKey(script)) |
| | 54 | | { |
| 4 | 55 | | throw new ArgumentException("Script is non-standard"); |
| | 56 | | } |
| | 57 | |
|
| 8 | 58 | | ChannelId = channelId; |
| 8 | 59 | | SerialId = serialId; |
| 8 | 60 | | Amount = amount; |
| 8 | 61 | | Script = script; |
| 8 | 62 | | } |
| | 63 | | } |