@@ -35,11 +35,13 @@ use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
35
35
use crate :: ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
36
36
use crate :: ln:: onion_utils;
37
37
use crate :: onion_message;
38
+ use crate :: sign:: NodeSigner ;
38
39
39
40
use crate :: prelude:: * ;
40
41
use core:: convert:: TryFrom ;
41
42
use core:: fmt;
42
43
use core:: fmt:: Debug ;
44
+ use core:: ops:: Deref ;
43
45
use core:: str:: FromStr ;
44
46
use crate :: io:: { self , Read } ;
45
47
use crate :: io_extras:: read_to_end;
@@ -2132,8 +2134,8 @@ impl Writeable for OutboundOnionPayload {
2132
2134
}
2133
2135
}
2134
2136
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 > {
2137
2139
let mut amt = HighZeroBytesDroppedBigSize ( 0u64 ) ;
2138
2140
let mut cltv_value = HighZeroBytesDroppedBigSize ( 0u32 ) ;
2139
2141
let mut short_id: Option < u64 > = None ;
@@ -2187,14 +2189,6 @@ impl Readable for InboundOnionPayload {
2187
2189
}
2188
2190
}
2189
2191
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
-
2198
2192
impl Writeable for Ping {
2199
2193
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
2200
2194
self . ponglen . write ( w) ?;
@@ -2612,7 +2606,8 @@ mod tests {
2612
2606
use crate :: ln:: msgs:: { self , FinalOnionHopData , OnionErrorPacket } ;
2613
2607
use crate :: ln:: msgs:: SocketAddress ;
2614
2608
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;
2616
2611
2617
2612
use bitcoin:: hashes:: hex:: FromHex ;
2618
2613
use bitcoin:: util:: address:: Address ;
@@ -3704,8 +3699,11 @@ mod tests {
3704
3699
let target_value = hex:: decode ( "1a02080badf00d010203040404ffffffff0608deadbeef1bad1dea" ) . unwrap ( ) ;
3705
3700
assert_eq ! ( encoded_value, target_value) ;
3706
3701
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 {
3709
3707
assert_eq ! ( short_channel_id, 0xdeadbeef1bad1dea ) ;
3710
3708
assert_eq ! ( amt_to_forward, 0x0badf00d01020304 ) ;
3711
3709
assert_eq ! ( outgoing_cltv_value, 0xffffffff ) ;
@@ -3726,8 +3724,11 @@ mod tests {
3726
3724
let target_value = hex:: decode ( "1002080badf00d010203040404ffffffff" ) . unwrap ( ) ;
3727
3725
assert_eq ! ( encoded_value, target_value) ;
3728
3726
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 {
3731
3732
assert_eq ! ( amt_msat, 0x0badf00d01020304 ) ;
3732
3733
assert_eq ! ( outgoing_cltv_value, 0xffffffff ) ;
3733
3734
} else { panic ! ( ) ; }
@@ -3751,7 +3752,8 @@ mod tests {
3751
3752
let target_value = hex:: decode ( "3602080badf00d010203040404ffffffff082442424242424242424242424242424242424242424242424242424242424242421badca1f" ) . unwrap ( ) ;
3752
3753
assert_eq ! ( encoded_value, target_value) ;
3753
3754
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 ( ) ;
3755
3757
if let msgs:: InboundOnionPayload :: Receive {
3756
3758
payment_data : Some ( FinalOnionHopData {
3757
3759
payment_secret,
@@ -3786,7 +3788,8 @@ mod tests {
3786
3788
outgoing_cltv_value : 0xffffffff ,
3787
3789
} ;
3788
3790
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( ) ) ;
3790
3793
let good_type_range_tlvs = vec ! [
3791
3794
( ( 1 << 16 ) - 3 , vec![ 42 ] ) ,
3792
3795
( ( 1 << 16 ) - 1 , vec![ 42 ; 32 ] ) ,
@@ -3795,7 +3798,7 @@ mod tests {
3795
3798
* custom_tlvs = good_type_range_tlvs. clone ( ) ;
3796
3799
}
3797
3800
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 ( ) ;
3799
3802
match inbound_msg {
3800
3803
msgs:: InboundOnionPayload :: Receive { custom_tlvs, .. } => assert ! ( custom_tlvs. is_empty( ) ) ,
3801
3804
_ => panic ! ( ) ,
@@ -3819,7 +3822,8 @@ mod tests {
3819
3822
let encoded_value = msg. encode ( ) ;
3820
3823
let target_value = hex:: decode ( "2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242" ) . unwrap ( ) ;
3821
3824
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 ( ) ;
3823
3827
if let msgs:: InboundOnionPayload :: Receive {
3824
3828
payment_data : None ,
3825
3829
payment_metadata : None ,
@@ -3982,7 +3986,10 @@ mod tests {
3982
3986
// payload length to be encoded over multiple bytes rather than a single u8.
3983
3987
let big_payload = encode_big_payload ( ) . unwrap ( ) ;
3984
3988
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 ( ) ;
3986
3993
}
3987
3994
// see above test, needs to be a separate method for use of the serialization macros.
3988
3995
fn encode_big_payload ( ) -> Result < Vec < u8 > , io:: Error > {
0 commit comments