Minor msgs::OnionHopData cleanups
authorValentine Wallace <vwallace@protonmail.com>
Sat, 6 Aug 2022 02:18:27 +0000 (22:18 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Sat, 6 Aug 2022 02:34:36 +0000 (22:34 -0400)
lightning/src/ln/msgs.rs

index 05a336c18eff5634e0fee7f2cec8b86a66e02a89..9886bfeea5e511fd180d3decd9f3158cc64f916f 100644 (file)
@@ -1417,14 +1417,6 @@ impl Writeable for OnionHopData {
        }
 }
 
-// ReadableArgs because we need onion_utils::decode_next_hop to accommodate payment packets and
-// onion message packets.
-impl ReadableArgs<()> for OnionHopData {
-       fn read<R: Read>(r: &mut R, _arg: ()) -> Result<Self, DecodeError> {
-               <Self as Readable>::read(r)
-       }
-}
-
 impl Readable for OnionHopData {
        fn read<R: Read>(mut r: &mut R) -> Result<Self, DecodeError> {
                use bitcoin::consensus::encode::{Decodable, Error, VarInt};
@@ -1441,12 +1433,12 @@ impl Readable for OnionHopData {
                        let mut short_id: Option<u64> = None;
                        let mut payment_data: Option<FinalOnionHopData> = None;
                        let mut keysend_preimage: Option<PaymentPreimage> = None;
-                       // The TLV type is chosen to be compatible with lnd and c-lightning.
                        decode_tlv_stream!(&mut rd, {
                                (2, amt, required),
                                (4, cltv_value, required),
                                (6, short_id, option),
                                (8, payment_data, option),
+                               // See https://github.com/lightning/blips/blob/master/blip-0003.md
                                (5482373484, keysend_preimage, option)
                        });
                        rd.eat_remaining().map_err(|_| DecodeError::ShortRead)?;
@@ -1488,6 +1480,14 @@ impl Readable for OnionHopData {
        }
 }
 
+// ReadableArgs because we need onion_utils::decode_next_hop to accommodate payment packets and
+// onion message packets.
+impl ReadableArgs<()> for OnionHopData {
+       fn read<R: Read>(r: &mut R, _arg: ()) -> Result<Self, DecodeError> {
+               <Self as Readable>::read(r)
+       }
+}
+
 impl Writeable for Ping {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                self.ponglen.write(w)?;