@@ -2412,8 +2412,8 @@ impl Writeable for AcceptChannel {
2412
2412
}
2413
2413
}
2414
2414
2415
- impl Readable for AcceptChannel {
2416
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
2415
+ impl LengthReadable for AcceptChannel {
2416
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
2417
2417
let temporary_channel_id: ChannelId = Readable :: read ( r) ?;
2418
2418
let dust_limit_satoshis: u64 = Readable :: read ( r) ?;
2419
2419
let max_htlc_value_in_flight_msat: u64 = Readable :: read ( r) ?;
@@ -2497,8 +2497,8 @@ impl Writeable for AcceptChannelV2 {
2497
2497
}
2498
2498
}
2499
2499
2500
- impl Readable for AcceptChannelV2 {
2501
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
2500
+ impl LengthReadable for AcceptChannelV2 {
2501
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
2502
2502
let temporary_channel_id: ChannelId = Readable :: read ( r) ?;
2503
2503
let funding_satoshis: u64 = Readable :: read ( r) ?;
2504
2504
let dust_limit_satoshis: u64 = Readable :: read ( r) ?;
@@ -2760,8 +2760,8 @@ impl Writeable for Init {
2760
2760
}
2761
2761
}
2762
2762
2763
- impl Readable for Init {
2764
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
2763
+ impl LengthReadable for Init {
2764
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
2765
2765
let global_features: InitFeatures = Readable :: read ( r) ?;
2766
2766
let features: InitFeatures = Readable :: read ( r) ?;
2767
2767
let mut remote_network_address: Option < SocketAddress > = None ;
@@ -2806,8 +2806,8 @@ impl Writeable for OpenChannel {
2806
2806
}
2807
2807
}
2808
2808
2809
- impl Readable for OpenChannel {
2810
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
2809
+ impl LengthReadable for OpenChannel {
2810
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
2811
2811
let chain_hash: ChainHash = Readable :: read ( r) ?;
2812
2812
let temporary_channel_id: ChannelId = Readable :: read ( r) ?;
2813
2813
let funding_satoshis: u64 = Readable :: read ( r) ?;
@@ -2890,8 +2890,8 @@ impl Writeable for OpenChannelV2 {
2890
2890
}
2891
2891
}
2892
2892
2893
- impl Readable for OpenChannelV2 {
2894
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
2893
+ impl LengthReadable for OpenChannelV2 {
2894
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
2895
2895
let chain_hash: ChainHash = Readable :: read ( r) ?;
2896
2896
let temporary_channel_id: ChannelId = Readable :: read ( r) ?;
2897
2897
let funding_feerate_sat_per_1000_weight: u32 = Readable :: read ( r) ?;
@@ -3052,8 +3052,8 @@ impl_writeable_msg!(UpdateAddHTLC, {
3052
3052
( 65537 , skimmed_fee_msat, option)
3053
3053
} ) ;
3054
3054
3055
- impl Readable for OnionMessage {
3056
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3055
+ impl LengthReadable for OnionMessage {
3056
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3057
3057
let blinding_point: PublicKey = Readable :: read ( r) ?;
3058
3058
let len: u16 = Readable :: read ( r) ?;
3059
3059
let mut packet_reader = FixedLengthReader :: new ( r, len as u64 ) ;
@@ -3526,8 +3526,8 @@ impl Writeable for Ping {
3526
3526
}
3527
3527
}
3528
3528
3529
- impl Readable for Ping {
3530
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3529
+ impl LengthReadable for Ping {
3530
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3531
3531
Ok ( Ping {
3532
3532
ponglen : Readable :: read ( r) ?,
3533
3533
byteslen : {
@@ -3546,8 +3546,8 @@ impl Writeable for Pong {
3546
3546
}
3547
3547
}
3548
3548
3549
- impl Readable for Pong {
3550
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3549
+ impl LengthReadable for Pong {
3550
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3551
3551
Ok ( Pong {
3552
3552
byteslen : {
3553
3553
let byteslen = Readable :: read ( r) ?;
@@ -3680,8 +3680,8 @@ impl Writeable for ErrorMessage {
3680
3680
}
3681
3681
}
3682
3682
3683
- impl Readable for ErrorMessage {
3684
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3683
+ impl LengthReadable for ErrorMessage {
3684
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3685
3685
Ok ( Self {
3686
3686
channel_id : Readable :: read ( r) ?,
3687
3687
data : {
@@ -3707,8 +3707,8 @@ impl Writeable for WarningMessage {
3707
3707
}
3708
3708
}
3709
3709
3710
- impl Readable for WarningMessage {
3711
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3710
+ impl LengthReadable for WarningMessage {
3711
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3712
3712
Ok ( Self {
3713
3713
channel_id : Readable :: read ( r) ?,
3714
3714
data : {
@@ -3826,8 +3826,8 @@ impl LengthReadable for NodeAnnouncement {
3826
3826
}
3827
3827
}
3828
3828
3829
- impl Readable for QueryShortChannelIds {
3830
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3829
+ impl LengthReadable for QueryShortChannelIds {
3830
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3831
3831
let chain_hash: ChainHash = Readable :: read ( r) ?;
3832
3832
3833
3833
let encoding_len: u16 = Readable :: read ( r) ?;
@@ -3902,8 +3902,8 @@ impl_writeable_msg!(QueryChannelRange, {
3902
3902
number_of_blocks
3903
3903
} , { } ) ;
3904
3904
3905
- impl Readable for ReplyChannelRange {
3906
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3905
+ impl LengthReadable for ReplyChannelRange {
3906
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3907
3907
let chain_hash: ChainHash = Readable :: read ( r) ?;
3908
3908
let first_blocknum: u32 = Readable :: read ( r) ?;
3909
3909
let number_of_blocks: u32 = Readable :: read ( r) ?;
@@ -5484,7 +5484,7 @@ mod tests {
5484
5484
let encoded_value = reply_channel_range. encode ( ) ;
5485
5485
assert_eq ! ( encoded_value, target_value) ;
5486
5486
5487
- reply_channel_range = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
5487
+ reply_channel_range = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) . unwrap ( ) ;
5488
5488
assert_eq ! ( reply_channel_range. chain_hash, expected_chain_hash) ;
5489
5489
assert_eq ! ( reply_channel_range. first_blocknum, 756230 ) ;
5490
5490
assert_eq ! ( reply_channel_range. number_of_blocks, 1500 ) ;
@@ -5494,7 +5494,7 @@ mod tests {
5494
5494
assert_eq ! ( reply_channel_range. short_channel_ids[ 2 ] , 0x000000000045a6c4 ) ;
5495
5495
} else {
5496
5496
target_value. append ( & mut <Vec < u8 > >:: from_hex ( "001601789c636000833e08659309a65878be010010a9023a" ) . unwrap ( ) ) ;
5497
- let result: Result < msgs:: ReplyChannelRange , msgs:: DecodeError > = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) ;
5497
+ let result: Result < msgs:: ReplyChannelRange , msgs:: DecodeError > = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) ;
5498
5498
assert ! ( result. is_err( ) , "Expected decode failure with unsupported zlib encoding" ) ;
5499
5499
}
5500
5500
}
@@ -5518,14 +5518,14 @@ mod tests {
5518
5518
let encoded_value = query_short_channel_ids. encode ( ) ;
5519
5519
assert_eq ! ( encoded_value, target_value) ;
5520
5520
5521
- query_short_channel_ids = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
5521
+ query_short_channel_ids = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) . unwrap ( ) ;
5522
5522
assert_eq ! ( query_short_channel_ids. chain_hash, expected_chain_hash) ;
5523
5523
assert_eq ! ( query_short_channel_ids. short_channel_ids[ 0 ] , 0x000000000000008e ) ;
5524
5524
assert_eq ! ( query_short_channel_ids. short_channel_ids[ 1 ] , 0x0000000000003c69 ) ;
5525
5525
assert_eq ! ( query_short_channel_ids. short_channel_ids[ 2 ] , 0x000000000045a6c4 ) ;
5526
5526
} else {
5527
5527
target_value. append ( & mut <Vec < u8 > >:: from_hex ( "001601789c636000833e08659309a65878be010010a9023a" ) . unwrap ( ) ) ;
5528
- let result: Result < msgs:: QueryShortChannelIds , msgs:: DecodeError > = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) ;
5528
+ let result: Result < msgs:: QueryShortChannelIds , msgs:: DecodeError > = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) ;
5529
5529
assert ! ( result. is_err( ) , "Expected decode failure with unsupported zlib encoding" ) ;
5530
5530
}
5531
5531
}
0 commit comments