| | | 1 | | using System.Diagnostics.CodeAnalysis; |
| | | 2 | | |
| | | 3 | | namespace NLightning.Infrastructure.Protocol.Tlv.Converters; |
| | | 4 | | |
| | | 5 | | using Domain.Protocol.Constants; |
| | | 6 | | using Domain.Protocol.Interfaces; |
| | | 7 | | using Domain.Protocol.Tlv; |
| | | 8 | | |
| | | 9 | | public class NextFundingTlvConverter : ITlvConverter<NextFundingTlv> |
| | | 10 | | { |
| | | 11 | | public BaseTlv ConvertToBase(NextFundingTlv tlv) |
| | | 12 | | { |
| | 8 | 13 | | return tlv; |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | public NextFundingTlv ConvertFromBase(BaseTlv baseTlv) |
| | | 17 | | { |
| | 8 | 18 | | if (baseTlv.Type != TlvConstants.NextFunding) |
| | | 19 | | { |
| | 0 | 20 | | throw new InvalidCastException("Invalid TLV type"); |
| | | 21 | | } |
| | | 22 | | |
| | 8 | 23 | | if (baseTlv.Length != 32) |
| | | 24 | | { |
| | 0 | 25 | | throw new InvalidCastException("Invalid length"); |
| | | 26 | | } |
| | | 27 | | |
| | 8 | 28 | | return new NextFundingTlv(baseTlv.Value); |
| | | 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 NextFundingTlv |
| | | 41 | | ?? throw new InvalidCastException( |
| | | 42 | | $"Error converting BaseTlv to {nameof(NextFundingTlv)}")); |
| | | 43 | | } |
| | | 44 | | } |