| | 1 | | using System.Diagnostics.CodeAnalysis; |
| | 2 | |
|
| | 3 | | namespace NLightning.Infrastructure.Protocol.Tlv.Converters; |
| | 4 | |
|
| | 5 | | using Domain.Protocol.Constants; |
| | 6 | | using Domain.Protocol.Tlv; |
| | 7 | | using Domain.Protocol.Tlv.Converters; |
| | 8 | |
|
| | 9 | | public class RequireConfirmedInputsTlvConverter : ITlvConverter<RequireConfirmedInputsTlv> |
| | 10 | | { |
| | 11 | | public BaseTlv ConvertToBase(RequireConfirmedInputsTlv tlv) |
| | 12 | | { |
| 24 | 13 | | return tlv; |
| | 14 | | } |
| | 15 | |
|
| | 16 | | public RequireConfirmedInputsTlv ConvertFromBase(BaseTlv baseTlv) |
| | 17 | | { |
| 20 | 18 | | if (baseTlv.Type != TlvConstants.REQUIRE_CONFIRMED_INPUTS) |
| | 19 | | { |
| 0 | 20 | | throw new InvalidCastException("Invalid TLV type"); |
| | 21 | | } |
| | 22 | |
|
| 20 | 23 | | if (baseTlv.Length != 0) |
| | 24 | | { |
| 0 | 25 | | throw new InvalidCastException("Invalid length"); |
| | 26 | | } |
| | 27 | |
|
| 20 | 28 | | return new RequireConfirmedInputsTlv(); |
| | 29 | | } |
| | 30 | |
|
| | 31 | | [ExcludeFromCodeCoverage] |
| | 32 | | BaseTlv ITlvConverter.ConvertFromBase(BaseTlv tlv) |
| | 33 | | { |
| | 34 | | return ConvertFromBase(tlv); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | [ExcludeFromCodeCoverage] |
| | 38 | | BaseTlv ITlvConverter.ConvertToBase(BaseTlv tlv) |
| | 39 | | { |
| | 40 | | return ConvertToBase(tlv as RequireConfirmedInputsTlv |
| | 41 | | ?? throw new InvalidCastException( |
| | 42 | | $"Error converting BaseTlv to {nameof(RequireConfirmedInputsTlv)}")); |
| | 43 | | } |
| | 44 | | } |