@@ -57,7 +57,7 @@ use crate::util::events::{EventHandler, EventsProvider, MessageSendEvent, Messag
57
57
use crate :: util:: { byte_utils, events} ;
58
58
use crate :: util:: wakers:: { Future , Notifier } ;
59
59
use crate :: util:: scid_utils:: fake_scid;
60
- use crate :: util:: ser:: { BigSize , FixedLengthReader , Readable , ReadableArgs , MaybeReadable , Writeable , Writer , VecWriter } ;
60
+ use crate :: util:: ser:: { BigSize , FixedLengthReader , Readable , ReadableArgs , MaybeReadable , Writeable , Writer , VecWriter , OptionDeserWrapper } ;
61
61
use crate :: util:: logger:: { Level , Logger } ;
62
62
use crate :: util:: errors:: APIError ;
63
63
@@ -6407,33 +6407,134 @@ impl_writeable_tlv_based!(ChannelCounterparty, {
6407
6407
( 11 , outbound_htlc_maximum_msat, option) ,
6408
6408
} ) ;
6409
6409
6410
- impl_writeable_tlv_based ! ( ChannelDetails , {
6411
- ( 1 , inbound_scid_alias, option) ,
6412
- ( 2 , channel_id, required) ,
6413
- ( 3 , channel_type, option) ,
6414
- ( 4 , counterparty, required) ,
6415
- ( 5 , outbound_scid_alias, option) ,
6416
- ( 6 , funding_txo, option) ,
6417
- ( 7 , config, option) ,
6418
- ( 8 , short_channel_id, option) ,
6419
- ( 10 , channel_value_satoshis, required) ,
6420
- ( 12 , unspendable_punishment_reserve, option) ,
6421
- ( 14 , user_channel_id, required) ,
6422
- ( 16 , balance_msat, required) ,
6423
- ( 18 , outbound_capacity_msat, required) ,
6424
- // Note that by the time we get past the required read above, outbound_capacity_msat will be
6425
- // filled in, so we can safely unwrap it here.
6426
- ( 19 , next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
6427
- ( 20 , inbound_capacity_msat, required) ,
6428
- ( 22 , confirmations_required, option) ,
6429
- ( 24 , force_close_spend_delay, option) ,
6430
- ( 26 , is_outbound, required) ,
6431
- ( 28 , is_channel_ready, required) ,
6432
- ( 30 , is_usable, required) ,
6433
- ( 32 , is_public, required) ,
6434
- ( 33 , inbound_htlc_minimum_msat, option) ,
6435
- ( 35 , inbound_htlc_maximum_msat, option) ,
6436
- } ) ;
6410
+ impl Writeable for ChannelDetails {
6411
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
6412
+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
6413
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
6414
+ let user_channel_id_low = self . user_channel_id as u64 ;
6415
+ let user_channel_id_high_opt = Some ( ( self . user_channel_id >> 64 ) as u64 ) ;
6416
+ write_tlv_fields ! ( writer, {
6417
+ ( 1 , self . inbound_scid_alias, option) ,
6418
+ ( 2 , self . channel_id, required) ,
6419
+ ( 3 , self . channel_type, option) ,
6420
+ ( 4 , self . counterparty, required) ,
6421
+ ( 5 , self . outbound_scid_alias, option) ,
6422
+ ( 6 , self . funding_txo, option) ,
6423
+ ( 7 , self . config, option) ,
6424
+ ( 8 , self . short_channel_id, option) ,
6425
+ ( 10 , self . channel_value_satoshis, required) ,
6426
+ ( 12 , self . unspendable_punishment_reserve, option) ,
6427
+ ( 14 , user_channel_id_low, required) ,
6428
+ ( 16 , self . balance_msat, required) ,
6429
+ ( 18 , self . outbound_capacity_msat, required) ,
6430
+ // Note that by the time we get past the required read above, outbound_capacity_msat will be
6431
+ // filled in, so we can safely unwrap it here.
6432
+ ( 19 , self . next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
6433
+ ( 20 , self . inbound_capacity_msat, required) ,
6434
+ ( 22 , self . confirmations_required, option) ,
6435
+ ( 24 , self . force_close_spend_delay, option) ,
6436
+ ( 26 , self . is_outbound, required) ,
6437
+ ( 28 , self . is_channel_ready, required) ,
6438
+ ( 30 , self . is_usable, required) ,
6439
+ ( 32 , self . is_public, required) ,
6440
+ ( 33 , self . inbound_htlc_minimum_msat, option) ,
6441
+ ( 35 , self . inbound_htlc_maximum_msat, option) ,
6442
+ ( 35 , user_channel_id_high_opt, option) ,
6443
+ } ) ;
6444
+ Ok ( ( ) )
6445
+ }
6446
+ }
6447
+
6448
+ impl Readable for ChannelDetails {
6449
+ fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6450
+ let mut inbound_scid_alias = None ;
6451
+ let mut channel_id = OptionDeserWrapper ( None ) ;
6452
+ let mut channel_type = None ;
6453
+ let mut counterparty = OptionDeserWrapper ( None ) ;
6454
+ let mut outbound_scid_alias = None ;
6455
+ let mut funding_txo = None ;
6456
+ let mut config = None ;
6457
+ let mut short_channel_id = None ;
6458
+ let mut channel_value_satoshis = OptionDeserWrapper ( None ) ;
6459
+ let mut unspendable_punishment_reserve = None ;
6460
+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
6461
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
6462
+ let mut user_channel_id_low: OptionDeserWrapper < u64 > = OptionDeserWrapper ( None ) ;
6463
+ let mut balance_msat = OptionDeserWrapper ( None ) ;
6464
+ let mut outbound_capacity_msat = OptionDeserWrapper ( None ) ;
6465
+ let mut next_outbound_htlc_limit_msat = OptionDeserWrapper ( None ) ;
6466
+ let mut inbound_capacity_msat = OptionDeserWrapper ( None ) ;
6467
+ let mut confirmations_required = None ;
6468
+ let mut force_close_spend_delay = None ;
6469
+ let mut is_outbound = OptionDeserWrapper ( None ) ;
6470
+ let mut is_channel_ready = OptionDeserWrapper ( None ) ;
6471
+ let mut is_usable = OptionDeserWrapper ( None ) ;
6472
+ let mut is_public = OptionDeserWrapper ( None ) ;
6473
+ let mut inbound_htlc_minimum_msat = None ;
6474
+ let mut inbound_htlc_maximum_msat = None ;
6475
+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
6476
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
6477
+ let mut user_channel_id_high_opt: Option < u64 > = None ;
6478
+
6479
+ read_tlv_fields ! ( reader, {
6480
+ ( 1 , inbound_scid_alias, option) ,
6481
+ ( 2 , channel_id, required) ,
6482
+ ( 3 , channel_type, option) ,
6483
+ ( 4 , counterparty, required) ,
6484
+ ( 5 , outbound_scid_alias, option) ,
6485
+ ( 6 , funding_txo, option) ,
6486
+ ( 7 , config, option) ,
6487
+ ( 8 , short_channel_id, option) ,
6488
+ ( 10 , channel_value_satoshis, required) ,
6489
+ ( 12 , unspendable_punishment_reserve, option) ,
6490
+ ( 14 , user_channel_id_low, required) ,
6491
+ ( 16 , balance_msat, required) ,
6492
+ ( 18 , outbound_capacity_msat, required) ,
6493
+ // Note that by the time we get past the required read above, outbound_capacity_msat will be
6494
+ // filled in, so we can safely unwrap it here.
6495
+ ( 19 , next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
6496
+ ( 20 , inbound_capacity_msat, required) ,
6497
+ ( 22 , confirmations_required, option) ,
6498
+ ( 24 , force_close_spend_delay, option) ,
6499
+ ( 26 , is_outbound, required) ,
6500
+ ( 28 , is_channel_ready, required) ,
6501
+ ( 30 , is_usable, required) ,
6502
+ ( 32 , is_public, required) ,
6503
+ ( 33 , inbound_htlc_minimum_msat, option) ,
6504
+ ( 35 , inbound_htlc_maximum_msat, option) ,
6505
+ ( 37 , user_channel_id_high_opt, option) ,
6506
+ } ) ;
6507
+
6508
+ let user_channel_id = user_channel_id_low. 0 . unwrap ( ) as u128 +
6509
+ ( ( user_channel_id_high_opt. unwrap_or ( 0 ) as u128 ) << 64 ) ;
6510
+
6511
+ Ok ( Self {
6512
+ inbound_scid_alias,
6513
+ channel_id : channel_id. 0 . unwrap ( ) ,
6514
+ channel_type,
6515
+ counterparty : counterparty. 0 . unwrap ( ) ,
6516
+ outbound_scid_alias,
6517
+ funding_txo,
6518
+ config,
6519
+ short_channel_id,
6520
+ channel_value_satoshis : channel_value_satoshis. 0 . unwrap ( ) ,
6521
+ unspendable_punishment_reserve,
6522
+ user_channel_id,
6523
+ balance_msat : balance_msat. 0 . unwrap ( ) ,
6524
+ outbound_capacity_msat : outbound_capacity_msat. 0 . unwrap ( ) ,
6525
+ next_outbound_htlc_limit_msat : next_outbound_htlc_limit_msat. 0 . unwrap ( ) ,
6526
+ inbound_capacity_msat : inbound_capacity_msat. 0 . unwrap ( ) ,
6527
+ confirmations_required,
6528
+ force_close_spend_delay,
6529
+ is_outbound : is_outbound. 0 . unwrap ( ) ,
6530
+ is_channel_ready : is_channel_ready. 0 . unwrap ( ) ,
6531
+ is_usable : is_usable. 0 . unwrap ( ) ,
6532
+ is_public : is_public. 0 . unwrap ( ) ,
6533
+ inbound_htlc_minimum_msat,
6534
+ inbound_htlc_maximum_msat,
6535
+ } )
6536
+ }
6537
+ }
6437
6538
6438
6539
impl_writeable_tlv_based ! ( PhantomRouteHints , {
6439
6540
( 2 , channels, vec_type) ,
0 commit comments