lnwire: simplify dyn decode methods

Remove the unnecessary convertions as suggested by Gemini.
This commit is contained in:
yyforyongyu
2025-07-03 04:42:34 +08:00
parent 91797ad1d2
commit 7a9f197de8
2 changed files with 8 additions and 24 deletions

View File

@@ -110,24 +110,16 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
// Check the results of the TLV Stream decoding and appropriately set // Check the results of the TLV Stream decoding and appropriately set
// message fields. // message fields.
if _, ok := knownRecords[dc.DustLimit.TlvType()]; ok { if _, ok := knownRecords[dc.DustLimit.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] dc.DustLimit = tlv.SomeRecordT(dustLimit)
rec.Val = dustLimit.Val
dc.DustLimit = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dc.MaxValueInFlight.TlvType()]; ok { if _, ok := knownRecords[dc.MaxValueInFlight.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] dc.MaxValueInFlight = tlv.SomeRecordT(maxValue)
rec.Val = maxValue.Val
dc.MaxValueInFlight = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dc.HtlcMinimum.TlvType()]; ok { if _, ok := knownRecords[dc.HtlcMinimum.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] dc.HtlcMinimum = tlv.SomeRecordT(htlcMin)
rec.Val = htlcMin.Val
dc.HtlcMinimum = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dc.ChannelReserve.TlvType()]; ok { if _, ok := knownRecords[dc.ChannelReserve.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] dc.ChannelReserve = tlv.SomeRecordT(reserve)
rec.Val = reserve.Val
dc.ChannelReserve = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dc.CsvDelay.TlvType()]; ok { if _, ok := knownRecords[dc.CsvDelay.TlvType()]; ok {
dc.CsvDelay = tlv.SomeRecordT(csvDelay) dc.CsvDelay = tlv.SomeRecordT(csvDelay)

View File

@@ -130,27 +130,19 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
// Check the results of the TLV Stream decoding and appropriately set // Check the results of the TLV Stream decoding and appropriately set
// message fields. // message fields.
if _, ok := knownRecords[dp.DustLimit.TlvType()]; ok { if _, ok := knownRecords[dp.DustLimit.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] dp.DustLimit = tlv.SomeRecordT(dustLimit)
rec.Val = dustLimit.Val
dp.DustLimit = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dp.MaxValueInFlight.TlvType()]; ok { if _, ok := knownRecords[dp.MaxValueInFlight.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] dp.MaxValueInFlight = tlv.SomeRecordT(maxValue)
rec.Val = maxValue.Val
dp.MaxValueInFlight = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dp.HtlcMinimum.TlvType()]; ok { if _, ok := knownRecords[dp.HtlcMinimum.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] dp.HtlcMinimum = tlv.SomeRecordT(htlcMin)
rec.Val = htlcMin.Val
dp.HtlcMinimum = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dp.ChannelReserve.TlvType()]; ok { if _, ok := knownRecords[dp.ChannelReserve.TlvType()]; ok {
var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] dp.ChannelReserve = tlv.SomeRecordT(reserve)
rec.Val = reserve.Val
dp.ChannelReserve = tlv.SomeRecordT(rec)
} }
if _, ok := knownRecords[dp.CsvDelay.TlvType()]; ok { if _, ok := knownRecords[dp.CsvDelay.TlvType()]; ok {