@@ -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) ?;
@@ -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) ?;
@@ -3653,8 +3653,8 @@ impl Writeable for ErrorMessage {
3653
3653
}
3654
3654
}
3655
3655
3656
- impl Readable for ErrorMessage {
3657
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3656
+ impl LengthReadable for ErrorMessage {
3657
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3658
3658
Ok ( Self {
3659
3659
channel_id : Readable :: read ( r) ?,
3660
3660
data : {
@@ -3680,8 +3680,8 @@ impl Writeable for WarningMessage {
3680
3680
}
3681
3681
}
3682
3682
3683
- impl Readable for WarningMessage {
3684
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3683
+ impl LengthReadable for WarningMessage {
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 : {
@@ -3787,8 +3787,8 @@ impl_writeable!(NodeAnnouncement, {
3787
3787
contents
3788
3788
} ) ;
3789
3789
3790
- impl Readable for QueryShortChannelIds {
3791
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3790
+ impl LengthReadable for QueryShortChannelIds {
3791
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3792
3792
let chain_hash: ChainHash = Readable :: read ( r) ?;
3793
3793
3794
3794
let encoding_len: u16 = Readable :: read ( r) ?;
@@ -3863,8 +3863,8 @@ impl_writeable_msg!(QueryChannelRange, {
3863
3863
number_of_blocks
3864
3864
} , { } ) ;
3865
3865
3866
- impl Readable for ReplyChannelRange {
3867
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
3866
+ impl LengthReadable for ReplyChannelRange {
3867
+ fn read_from_fixed_length_buffer < R : LengthLimitedRead > ( r : & mut R ) -> Result < Self , DecodeError > {
3868
3868
let chain_hash: ChainHash = Readable :: read ( r) ?;
3869
3869
let first_blocknum: u32 = Readable :: read ( r) ?;
3870
3870
let number_of_blocks: u32 = Readable :: read ( r) ?;
@@ -5445,7 +5445,7 @@ mod tests {
5445
5445
let encoded_value = reply_channel_range. encode ( ) ;
5446
5446
assert_eq ! ( encoded_value, target_value) ;
5447
5447
5448
- reply_channel_range = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
5448
+ reply_channel_range = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) . unwrap ( ) ;
5449
5449
assert_eq ! ( reply_channel_range. chain_hash, expected_chain_hash) ;
5450
5450
assert_eq ! ( reply_channel_range. first_blocknum, 756230 ) ;
5451
5451
assert_eq ! ( reply_channel_range. number_of_blocks, 1500 ) ;
@@ -5455,7 +5455,7 @@ mod tests {
5455
5455
assert_eq ! ( reply_channel_range. short_channel_ids[ 2 ] , 0x000000000045a6c4 ) ;
5456
5456
} else {
5457
5457
target_value. append ( & mut <Vec < u8 > >:: from_hex ( "001601789c636000833e08659309a65878be010010a9023a" ) . unwrap ( ) ) ;
5458
- let result: Result < msgs:: ReplyChannelRange , msgs:: DecodeError > = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) ;
5458
+ let result: Result < msgs:: ReplyChannelRange , msgs:: DecodeError > = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) ;
5459
5459
assert ! ( result. is_err( ) , "Expected decode failure with unsupported zlib encoding" ) ;
5460
5460
}
5461
5461
}
@@ -5479,14 +5479,14 @@ mod tests {
5479
5479
let encoded_value = query_short_channel_ids. encode ( ) ;
5480
5480
assert_eq ! ( encoded_value, target_value) ;
5481
5481
5482
- query_short_channel_ids = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) . unwrap ( ) ;
5482
+ query_short_channel_ids = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) . unwrap ( ) ;
5483
5483
assert_eq ! ( query_short_channel_ids. chain_hash, expected_chain_hash) ;
5484
5484
assert_eq ! ( query_short_channel_ids. short_channel_ids[ 0 ] , 0x000000000000008e ) ;
5485
5485
assert_eq ! ( query_short_channel_ids. short_channel_ids[ 1 ] , 0x0000000000003c69 ) ;
5486
5486
assert_eq ! ( query_short_channel_ids. short_channel_ids[ 2 ] , 0x000000000045a6c4 ) ;
5487
5487
} else {
5488
5488
target_value. append ( & mut <Vec < u8 > >:: from_hex ( "001601789c636000833e08659309a65878be010010a9023a" ) . unwrap ( ) ) ;
5489
- let result: Result < msgs:: QueryShortChannelIds , msgs:: DecodeError > = Readable :: read ( & mut Cursor :: new ( & target_value[ ..] ) ) ;
5489
+ let result: Result < msgs:: QueryShortChannelIds , msgs:: DecodeError > = LengthReadable :: read_from_fixed_length_buffer ( & mut & target_value[ ..] ) ;
5490
5490
assert ! ( result. is_err( ) , "Expected decode failure with unsupported zlib encoding" ) ;
5491
5491
}
5492
5492
}
0 commit comments