@@ -15,11 +15,14 @@ use bitcoin::secp256k1::PublicKey;
1515
1616use crate :: chain:: chaininterface:: { FeeEstimator , LowerBoundedFeeEstimator } ;
1717use crate :: chain:: transaction:: OutPoint ;
18+ use crate :: io;
1819use crate :: ln:: channel:: ChannelContext ;
1920use crate :: ln:: features:: { ChannelTypeFeatures , InitFeatures } ;
21+ use crate :: ln:: msgs:: DecodeError ;
2022use crate :: ln:: types:: { ChannelId , PaymentHash } ;
2123use crate :: sign:: SignerProvider ;
2224use crate :: util:: config:: ChannelConfig ;
25+ use crate :: util:: ser:: { Writeable , Writer , Readable } ;
2326
2427use core:: ops:: Deref ;
2528
@@ -224,6 +227,12 @@ pub struct CounterpartyForwardingInfo {
224227 pub cltv_expiry_delta : u16 ,
225228}
226229
230+ impl_writeable_tlv_based ! ( CounterpartyForwardingInfo , {
231+ ( 2 , fee_base_msat, required) ,
232+ ( 4 , fee_proportional_millionths, required) ,
233+ ( 6 , cltv_expiry_delta, required) ,
234+ } ) ;
235+
227236/// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
228237/// to better separate parameters.
229238#[ derive( Clone , Debug , PartialEq ) ]
@@ -253,6 +262,15 @@ pub struct ChannelCounterparty {
253262 pub outbound_htlc_maximum_msat : Option < u64 > ,
254263}
255264
265+ impl_writeable_tlv_based ! ( ChannelCounterparty , {
266+ ( 2 , node_id, required) ,
267+ ( 4 , features, required) ,
268+ ( 6 , unspendable_punishment_reserve, required) ,
269+ ( 8 , forwarding_info, option) ,
270+ ( 9 , outbound_htlc_minimum_msat, option) ,
271+ ( 11 , outbound_htlc_maximum_msat, option) ,
272+ } ) ;
273+
256274/// Details of a channel, as returned by [`ChannelManager::list_channels`] and [`ChannelManager::list_usable_channels`]
257275///
258276/// [`ChannelManager::list_channels`]: crate::ln::channelmanager::ChannelManager::list_channels
@@ -537,6 +555,125 @@ impl ChannelDetails {
537555 }
538556}
539557
558+ impl Writeable for ChannelDetails {
559+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
560+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
561+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
562+ let user_channel_id_low = self . user_channel_id as u64 ;
563+ let user_channel_id_high_opt = Some ( ( self . user_channel_id >> 64 ) as u64 ) ;
564+ write_tlv_fields ! ( writer, {
565+ ( 1 , self . inbound_scid_alias, option) ,
566+ ( 2 , self . channel_id, required) ,
567+ ( 3 , self . channel_type, option) ,
568+ ( 4 , self . counterparty, required) ,
569+ ( 5 , self . outbound_scid_alias, option) ,
570+ ( 6 , self . funding_txo, option) ,
571+ ( 7 , self . config, option) ,
572+ ( 8 , self . short_channel_id, option) ,
573+ ( 9 , self . confirmations, option) ,
574+ ( 10 , self . channel_value_satoshis, required) ,
575+ ( 12 , self . unspendable_punishment_reserve, option) ,
576+ ( 14 , user_channel_id_low, required) ,
577+ ( 16 , self . balance_msat, required) ,
578+ ( 18 , self . outbound_capacity_msat, required) ,
579+ ( 19 , self . next_outbound_htlc_limit_msat, required) ,
580+ ( 20 , self . inbound_capacity_msat, required) ,
581+ ( 21 , self . next_outbound_htlc_minimum_msat, required) ,
582+ ( 22 , self . confirmations_required, option) ,
583+ ( 24 , self . force_close_spend_delay, option) ,
584+ ( 26 , self . is_outbound, required) ,
585+ ( 28 , self . is_channel_ready, required) ,
586+ ( 30 , self . is_usable, required) ,
587+ ( 32 , self . is_public, required) ,
588+ ( 33 , self . inbound_htlc_minimum_msat, option) ,
589+ ( 35 , self . inbound_htlc_maximum_msat, option) ,
590+ ( 37 , user_channel_id_high_opt, option) ,
591+ ( 39 , self . feerate_sat_per_1000_weight, option) ,
592+ ( 41 , self . channel_shutdown_state, option) ,
593+ ( 43 , self . pending_inbound_htlcs, optional_vec) ,
594+ ( 45 , self . pending_outbound_htlcs, optional_vec) ,
595+ } ) ;
596+ Ok ( ( ) )
597+ }
598+ }
599+
600+ impl Readable for ChannelDetails {
601+ fn read < R : io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
602+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
603+ ( 1 , inbound_scid_alias, option) ,
604+ ( 2 , channel_id, required) ,
605+ ( 3 , channel_type, option) ,
606+ ( 4 , counterparty, required) ,
607+ ( 5 , outbound_scid_alias, option) ,
608+ ( 6 , funding_txo, option) ,
609+ ( 7 , config, option) ,
610+ ( 8 , short_channel_id, option) ,
611+ ( 9 , confirmations, option) ,
612+ ( 10 , channel_value_satoshis, required) ,
613+ ( 12 , unspendable_punishment_reserve, option) ,
614+ ( 14 , user_channel_id_low, required) ,
615+ ( 16 , balance_msat, required) ,
616+ ( 18 , outbound_capacity_msat, required) ,
617+ // Note that by the time we get past the required read above, outbound_capacity_msat will be
618+ // filled in, so we can safely unwrap it here.
619+ ( 19 , next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
620+ ( 20 , inbound_capacity_msat, required) ,
621+ ( 21 , next_outbound_htlc_minimum_msat, ( default_value, 0 ) ) ,
622+ ( 22 , confirmations_required, option) ,
623+ ( 24 , force_close_spend_delay, option) ,
624+ ( 26 , is_outbound, required) ,
625+ ( 28 , is_channel_ready, required) ,
626+ ( 30 , is_usable, required) ,
627+ ( 32 , is_public, required) ,
628+ ( 33 , inbound_htlc_minimum_msat, option) ,
629+ ( 35 , inbound_htlc_maximum_msat, option) ,
630+ ( 37 , user_channel_id_high_opt, option) ,
631+ ( 39 , feerate_sat_per_1000_weight, option) ,
632+ ( 41 , channel_shutdown_state, option) ,
633+ ( 43 , pending_inbound_htlcs, optional_vec) ,
634+ ( 45 , pending_outbound_htlcs, optional_vec) ,
635+ } ) ;
636+
637+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
638+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
639+ let user_channel_id_low: u64 = user_channel_id_low. 0 . unwrap ( ) ;
640+ let user_channel_id = user_channel_id_low as u128 +
641+ ( ( user_channel_id_high_opt. unwrap_or ( 0 as u64 ) as u128 ) << 64 ) ;
642+
643+ Ok ( Self {
644+ inbound_scid_alias,
645+ channel_id : channel_id. 0 . unwrap ( ) ,
646+ channel_type,
647+ counterparty : counterparty. 0 . unwrap ( ) ,
648+ outbound_scid_alias,
649+ funding_txo,
650+ config,
651+ short_channel_id,
652+ channel_value_satoshis : channel_value_satoshis. 0 . unwrap ( ) ,
653+ unspendable_punishment_reserve,
654+ user_channel_id,
655+ balance_msat : balance_msat. 0 . unwrap ( ) ,
656+ outbound_capacity_msat : outbound_capacity_msat. 0 . unwrap ( ) ,
657+ next_outbound_htlc_limit_msat : next_outbound_htlc_limit_msat. 0 . unwrap ( ) ,
658+ next_outbound_htlc_minimum_msat : next_outbound_htlc_minimum_msat. 0 . unwrap ( ) ,
659+ inbound_capacity_msat : inbound_capacity_msat. 0 . unwrap ( ) ,
660+ confirmations_required,
661+ confirmations,
662+ force_close_spend_delay,
663+ is_outbound : is_outbound. 0 . unwrap ( ) ,
664+ is_channel_ready : is_channel_ready. 0 . unwrap ( ) ,
665+ is_usable : is_usable. 0 . unwrap ( ) ,
666+ is_public : is_public. 0 . unwrap ( ) ,
667+ inbound_htlc_minimum_msat,
668+ inbound_htlc_maximum_msat,
669+ feerate_sat_per_1000_weight,
670+ channel_shutdown_state,
671+ pending_inbound_htlcs : pending_inbound_htlcs. unwrap_or ( Vec :: new ( ) ) ,
672+ pending_outbound_htlcs : pending_outbound_htlcs. unwrap_or ( Vec :: new ( ) ) ,
673+ } )
674+ }
675+ }
676+
540677#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
541678/// Further information on the details of the channel shutdown.
542679/// Upon channels being forced closed (i.e. commitment transaction confirmation detected
@@ -558,3 +695,11 @@ pub enum ChannelShutdownState {
558695 /// to drop the channel.
559696 ShutdownComplete ,
560697}
698+
699+ impl_writeable_tlv_based_enum ! ( ChannelShutdownState ,
700+ ( 0 , NotShuttingDown ) => { } ,
701+ ( 2 , ShutdownInitiated ) => { } ,
702+ ( 4 , ResolvingHTLCs ) => { } ,
703+ ( 6 , NegotiatingClosingFee ) => { } ,
704+ ( 8 , ShutdownComplete ) => { } , ;
705+ ) ;
0 commit comments