From 7a9f197de8a290c7d229ef233422d2c715dcfc55 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 3 Jul 2025 04:42:34 +0800 Subject: [PATCH] lnwire: simplify dyn decode methods Remove the unnecessary convertions as suggested by Gemini. --- lnwire/dyn_commit.go | 16 ++++------------ lnwire/dyn_propose.go | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/lnwire/dyn_commit.go b/lnwire/dyn_commit.go index d829684ac..2cb1047b0 100644 --- a/lnwire/dyn_commit.go +++ b/lnwire/dyn_commit.go @@ -110,24 +110,16 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error { // Check the results of the TLV Stream decoding and appropriately set // message fields. if _, ok := knownRecords[dc.DustLimit.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] - rec.Val = dustLimit.Val - dc.DustLimit = tlv.SomeRecordT(rec) + dc.DustLimit = tlv.SomeRecordT(dustLimit) } if _, ok := knownRecords[dc.MaxValueInFlight.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] - rec.Val = maxValue.Val - dc.MaxValueInFlight = tlv.SomeRecordT(rec) + dc.MaxValueInFlight = tlv.SomeRecordT(maxValue) } if _, ok := knownRecords[dc.HtlcMinimum.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] - rec.Val = htlcMin.Val - dc.HtlcMinimum = tlv.SomeRecordT(rec) + dc.HtlcMinimum = tlv.SomeRecordT(htlcMin) } if _, ok := knownRecords[dc.ChannelReserve.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] - rec.Val = reserve.Val - dc.ChannelReserve = tlv.SomeRecordT(rec) + dc.ChannelReserve = tlv.SomeRecordT(reserve) } if _, ok := knownRecords[dc.CsvDelay.TlvType()]; ok { dc.CsvDelay = tlv.SomeRecordT(csvDelay) diff --git a/lnwire/dyn_propose.go b/lnwire/dyn_propose.go index 4744b87d2..2771e790f 100644 --- a/lnwire/dyn_propose.go +++ b/lnwire/dyn_propose.go @@ -130,27 +130,19 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error { // Check the results of the TLV Stream decoding and appropriately set // message fields. if _, ok := knownRecords[dp.DustLimit.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] - rec.Val = dustLimit.Val - dp.DustLimit = tlv.SomeRecordT(rec) + dp.DustLimit = tlv.SomeRecordT(dustLimit) } if _, ok := knownRecords[dp.MaxValueInFlight.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] - rec.Val = maxValue.Val - dp.MaxValueInFlight = tlv.SomeRecordT(rec) + dp.MaxValueInFlight = tlv.SomeRecordT(maxValue) } if _, ok := knownRecords[dp.HtlcMinimum.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] - rec.Val = htlcMin.Val - dp.HtlcMinimum = tlv.SomeRecordT(rec) + dp.HtlcMinimum = tlv.SomeRecordT(htlcMin) } if _, ok := knownRecords[dp.ChannelReserve.TlvType()]; ok { - var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] - rec.Val = reserve.Val - dp.ChannelReserve = tlv.SomeRecordT(rec) + dp.ChannelReserve = tlv.SomeRecordT(reserve) } if _, ok := knownRecords[dp.CsvDelay.TlvType()]; ok {