| | 1 | | using NBitcoin; |
| | 2 | |
|
| | 3 | | namespace NLightning.Infrastructure.Bitcoin.Outputs; |
| | 4 | |
|
| | 5 | | using Domain.Money; |
| | 6 | |
|
| | 7 | | public class FundingOutput : BaseOutput |
| | 8 | | { |
| 296 | 9 | | public override ScriptType ScriptType => ScriptType.P2WSH; |
| | 10 | |
|
| 56 | 11 | | public PubKey LocalPubKey { get; } |
| 156 | 12 | | public PubKey RemotePubKey { get; } |
| | 13 | |
|
| | 14 | | public FundingOutput(PubKey localPubKey, PubKey remotePubKey, LightningMoney amount) |
| 292 | 15 | | : base(CreateMultisigScript(localPubKey, remotePubKey), amount) |
| | 16 | | { |
| 292 | 17 | | ArgumentNullException.ThrowIfNull(localPubKey); |
| 292 | 18 | | ArgumentNullException.ThrowIfNull(remotePubKey); |
| | 19 | |
|
| 292 | 20 | | if (localPubKey == remotePubKey) |
| 4 | 21 | | throw new ArgumentException("Public keys must be different."); |
| | 22 | |
|
| 288 | 23 | | if (amount.IsZero) |
| 4 | 24 | | throw new ArgumentOutOfRangeException(nameof(amount), "Funding amount must be greater than zero."); |
| | 25 | |
|
| 284 | 26 | | LocalPubKey = localPubKey; |
| 284 | 27 | | RemotePubKey = remotePubKey; |
| 284 | 28 | | } |
| | 29 | |
|
| | 30 | | private static Script CreateMultisigScript(PubKey localPubKey, PubKey remotePubKey) |
| | 31 | | { |
| 292 | 32 | | ArgumentNullException.ThrowIfNull(localPubKey); |
| 292 | 33 | | ArgumentNullException.ThrowIfNull(remotePubKey); |
| | 34 | |
|
| 876 | 35 | | var orderedKeys = new[] { localPubKey, remotePubKey }.OrderBy(pk => pk, PubKeyComparer.Instance).ToArray(); |
| 292 | 36 | | return PayToMultiSigTemplate.Instance.GenerateScriptPubKey(2, orderedKeys); |
| | 37 | | } |
| | 38 | | } |