@@ -35,11 +35,13 @@ use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
3535use crate :: ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
3636use crate :: ln:: onion_utils;
3737use crate :: onion_message;
38+ use crate :: sign:: NodeSigner ;
3839
3940use crate :: prelude:: * ;
4041use core:: convert:: TryFrom ;
4142use core:: fmt;
4243use core:: fmt:: Debug ;
44+ use core:: ops:: Deref ;
4345use core:: str:: FromStr ;
4446use crate :: io:: { self , Read } ;
4547use crate :: io_extras:: read_to_end;
@@ -2132,8 +2134,8 @@ impl Writeable for OutboundOnionPayload {
21322134 }
21332135}
21342136
2135- impl Readable for InboundOnionPayload {
2136- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
2137+ impl < NS : Deref > ReadableArgs < & NS > for InboundOnionPayload where NS :: Target : NodeSigner {
2138+ fn read < R : Read > ( r : & mut R , node_signer : & NS ) -> Result < Self , DecodeError > {
21372139 let mut amt = HighZeroBytesDroppedBigSize ( 0u64 ) ;
21382140 let mut cltv_value = HighZeroBytesDroppedBigSize ( 0u32 ) ;
21392141 let mut short_id: Option < u64 > = None ;
@@ -2187,14 +2189,6 @@ impl Readable for InboundOnionPayload {
21872189 }
21882190}
21892191
2190- // ReadableArgs because we need onion_utils::decode_next_hop to accommodate payment packets and
2191- // onion message packets.
2192- impl ReadableArgs < ( ) > for InboundOnionPayload {
2193- fn read < R : Read > ( r : & mut R , _arg : ( ) ) -> Result < Self , DecodeError > {
2194- <Self as Readable >:: read ( r)
2195- }
2196- }
2197-
21982192impl Writeable for Ping {
21992193 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
22002194 self . ponglen . write ( w) ?;
@@ -2612,7 +2606,8 @@ mod tests {
26122606 use crate :: ln:: msgs:: { self , FinalOnionHopData , OnionErrorPacket } ;
26132607 use crate :: ln:: msgs:: SocketAddress ;
26142608 use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
2615- use crate :: util:: ser:: { Writeable , Readable , Hostname , TransactionU16LenLimited } ;
2609+ use crate :: util:: ser:: { Writeable , Readable , ReadableArgs , Hostname , TransactionU16LenLimited } ;
2610+ use crate :: util:: test_utils;
26162611
26172612 use bitcoin:: hashes:: hex:: FromHex ;
26182613 use bitcoin:: util:: address:: Address ;
@@ -3704,8 +3699,11 @@ mod tests {
37043699 let target_value = hex:: decode ( "1a02080badf00d010203040404ffffffff0608deadbeef1bad1dea" ) . unwrap ( ) ;
37053700 assert_eq ! ( encoded_value, target_value) ;
37063701
3707- let inbound_msg = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
3708- if let msgs:: InboundOnionPayload :: Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } = inbound_msg {
3702+ let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
3703+ let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , & & node_signer) . unwrap ( ) ;
3704+ if let msgs:: InboundOnionPayload :: Forward {
3705+ short_channel_id, amt_to_forward, outgoing_cltv_value
3706+ } = inbound_msg {
37093707 assert_eq ! ( short_channel_id, 0xdeadbeef1bad1dea ) ;
37103708 assert_eq ! ( amt_to_forward, 0x0badf00d01020304 ) ;
37113709 assert_eq ! ( outgoing_cltv_value, 0xffffffff ) ;
@@ -3726,8 +3724,11 @@ mod tests {
37263724 let target_value = hex:: decode ( "1002080badf00d010203040404ffffffff" ) . unwrap ( ) ;
37273725 assert_eq ! ( encoded_value, target_value) ;
37283726
3729- let inbound_msg = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
3730- if let msgs:: InboundOnionPayload :: Receive { payment_data : None , amt_msat, outgoing_cltv_value, .. } = inbound_msg {
3727+ let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
3728+ let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , & & node_signer) . unwrap ( ) ;
3729+ if let msgs:: InboundOnionPayload :: Receive {
3730+ payment_data : None , amt_msat, outgoing_cltv_value, ..
3731+ } = inbound_msg {
37313732 assert_eq ! ( amt_msat, 0x0badf00d01020304 ) ;
37323733 assert_eq ! ( outgoing_cltv_value, 0xffffffff ) ;
37333734 } else { panic ! ( ) ; }
@@ -3751,7 +3752,8 @@ mod tests {
37513752 let target_value = hex:: decode ( "3602080badf00d010203040404ffffffff082442424242424242424242424242424242424242424242424242424242424242421badca1f" ) . unwrap ( ) ;
37523753 assert_eq ! ( encoded_value, target_value) ;
37533754
3754- let inbound_msg = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
3755+ let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
3756+ let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , & & node_signer) . unwrap ( ) ;
37553757 if let msgs:: InboundOnionPayload :: Receive {
37563758 payment_data : Some ( FinalOnionHopData {
37573759 payment_secret,
@@ -3786,7 +3788,8 @@ mod tests {
37863788 outgoing_cltv_value : 0xffffffff ,
37873789 } ;
37883790 let encoded_value = msg. encode ( ) ;
3789- assert ! ( msgs:: InboundOnionPayload :: read( & mut Cursor :: new( & encoded_value[ ..] ) ) . is_err( ) ) ;
3791+ let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
3792+ assert ! ( msgs:: InboundOnionPayload :: read( & mut Cursor :: new( & encoded_value[ ..] ) , &&node_signer) . is_err( ) ) ;
37903793 let good_type_range_tlvs = vec ! [
37913794 ( ( 1 << 16 ) - 3 , vec![ 42 ] ) ,
37923795 ( ( 1 << 16 ) - 1 , vec![ 42 ; 32 ] ) ,
@@ -3795,7 +3798,7 @@ mod tests {
37953798 * custom_tlvs = good_type_range_tlvs. clone ( ) ;
37963799 }
37973800 let encoded_value = msg. encode ( ) ;
3798- let inbound_msg = Readable :: read ( & mut Cursor :: new ( & encoded_value[ ..] ) ) . unwrap ( ) ;
3801+ let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & encoded_value[ ..] ) , & & node_signer ) . unwrap ( ) ;
37993802 match inbound_msg {
38003803 msgs:: InboundOnionPayload :: Receive { custom_tlvs, .. } => assert ! ( custom_tlvs. is_empty( ) ) ,
38013804 _ => panic ! ( ) ,
@@ -3819,7 +3822,8 @@ mod tests {
38193822 let encoded_value = msg. encode ( ) ;
38203823 let target_value = hex:: decode ( "2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242" ) . unwrap ( ) ;
38213824 assert_eq ! ( encoded_value, target_value) ;
3822- let inbound_msg: msgs:: InboundOnionPayload = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
3825+ let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
3826+ let inbound_msg: msgs:: InboundOnionPayload = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , & & node_signer) . unwrap ( ) ;
38233827 if let msgs:: InboundOnionPayload :: Receive {
38243828 payment_data : None ,
38253829 payment_metadata : None ,
@@ -3982,7 +3986,10 @@ mod tests {
39823986 // payload length to be encoded over multiple bytes rather than a single u8.
39833987 let big_payload = encode_big_payload ( ) . unwrap ( ) ;
39843988 let mut rd = Cursor :: new ( & big_payload[ ..] ) ;
3985- <msgs:: InboundOnionPayload as Readable >:: read ( & mut rd) . unwrap ( ) ;
3989+
3990+ let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
3991+ <msgs:: InboundOnionPayload as ReadableArgs < & & test_utils:: TestKeysInterface > >
3992+ :: read ( & mut rd, & & node_signer) . unwrap ( ) ;
39863993 }
39873994 // see above test, needs to be a separate method for use of the serialization macros.
39883995 fn encode_big_payload ( ) -> Result < Vec < u8 > , io:: Error > {
0 commit comments