| | 1 | | namespace NLightning.Infrastructure.Protocol.Validators; |
| | 2 | |
|
| | 3 | | using Domain.Money; |
| | 4 | | using Domain.Protocol.Constants; |
| | 5 | | using Domain.Protocol.Payloads; |
| | 6 | |
|
| | 7 | | public static class TxAddOutputValidator |
| | 8 | | { |
| | 9 | | public static void Validate(bool isInitiator, TxAddOutputPayload output, int currentOutputCount, |
| | 10 | | Func<ulong, bool> isSerialIdUnique, Func<byte[], bool> isStandardScript, |
| | 11 | | LightningMoney dustLimit) |
| | 12 | | { |
| 0 | 13 | | if (isInitiator && (output.SerialId & 1) != 0) // Ensure even serial_id for initiator |
| | 14 | | { |
| 0 | 15 | | throw new InvalidOperationException("SerialId has the wrong parity."); |
| | 16 | | } |
| | 17 | |
|
| 0 | 18 | | if (!isSerialIdUnique(output.SerialId)) |
| | 19 | | { |
| 0 | 20 | | throw new InvalidOperationException("SerialId is already included in the transaction."); |
| | 21 | | } |
| | 22 | |
|
| 0 | 23 | | if (currentOutputCount >= InteractiveTransactionConstants.MAX_OUTPUTS_ALLOWED) |
| | 24 | | { |
| 0 | 25 | | throw new InvalidOperationException($"Cannot receive more than {InteractiveTransactionConstants.MAX_OUTPUTS_ |
| | 26 | | } |
| | 27 | |
|
| 0 | 28 | | if (output.Amount < dustLimit) |
| | 29 | | { |
| 0 | 30 | | throw new InvalidOperationException("The sats amount is less than the dust_limit."); |
| | 31 | | } |
| | 32 | |
|
| 0 | 33 | | if (output.Amount > InteractiveTransactionConstants.MAX_MONEY) |
| | 34 | | { |
| 0 | 35 | | throw new InvalidOperationException("The sats amount is greater than the maximum allowed (MAX_MONEY)."); |
| | 36 | | } |
| | 37 | |
|
| 0 | 38 | | if (!isStandardScript(output.Script.ToBytes())) |
| | 39 | | { |
| 0 | 40 | | throw new InvalidOperationException("The script is non-standard."); |
| | 41 | | } |
| 0 | 42 | | } |
| | 43 | | } |