@@ -521,24 +521,7 @@ pub struct RoutingFees {
521
521
pub proportional_millionths : u32 ,
522
522
}
523
523
524
- impl Readable for RoutingFees {
525
- fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < RoutingFees , DecodeError > {
526
- let base_msat: u32 = Readable :: read ( reader) ?;
527
- let proportional_millionths: u32 = Readable :: read ( reader) ?;
528
- Ok ( RoutingFees {
529
- base_msat,
530
- proportional_millionths,
531
- } )
532
- }
533
- }
534
-
535
- impl Writeable for RoutingFees {
536
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
537
- self . base_msat . write ( writer) ?;
538
- self . proportional_millionths . write ( writer) ?;
539
- Ok ( ( ) )
540
- }
541
- }
524
+ impl_writeable_tlv_based ! ( RoutingFees , { ( 0 , base_msat, 0 ) , ( 2 , proportional_millionths, 0 ) } , { } , { } ) ;
542
525
543
526
#[ derive( Clone , Debug , PartialEq ) ]
544
527
/// Information received in the latest node_announcement from this node.
@@ -565,25 +548,22 @@ pub struct NodeAnnouncementInfo {
565
548
566
549
impl Writeable for NodeAnnouncementInfo {
567
550
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
568
- self . features . write ( writer) ?;
569
- self . last_update . write ( writer) ?;
570
- self . rgb . write ( writer) ?;
571
- self . alias . write ( writer) ?;
572
551
( self . addresses . len ( ) as u64 ) . write ( writer) ?;
573
552
for ref addr in & self . addresses {
574
553
addr. write ( writer) ?;
575
554
}
576
- self . announcement_message . write ( writer) ?;
555
+ write_tlv_fields ! ( writer, {
556
+ ( 0 , self . features) ,
557
+ ( 2 , self . last_update) ,
558
+ ( 4 , self . rgb) ,
559
+ ( 6 , self . alias)
560
+ } , { ( 8 , self . announcement_message) } ) ;
577
561
Ok ( ( ) )
578
562
}
579
563
}
580
564
581
565
impl Readable for NodeAnnouncementInfo {
582
566
fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < NodeAnnouncementInfo , DecodeError > {
583
- let features = Readable :: read ( reader) ?;
584
- let last_update = Readable :: read ( reader) ?;
585
- let rgb = Readable :: read ( reader) ?;
586
- let alias = Readable :: read ( reader) ?;
587
567
let addresses_count: u64 = Readable :: read ( reader) ?;
588
568
let mut addresses = Vec :: with_capacity ( cmp:: min ( addresses_count, MAX_ALLOC_SIZE / 40 ) as usize ) ;
589
569
for _ in 0 ..addresses_count {
@@ -594,7 +574,17 @@ impl Readable for NodeAnnouncementInfo {
594
574
_ => unreachable ! ( ) ,
595
575
}
596
576
}
597
- let announcement_message = Readable :: read ( reader) ?;
577
+ let mut features = NodeFeatures :: empty ( ) ;
578
+ let mut last_update = 0 ;
579
+ let mut rgb = [ 0 ; 3 ] ;
580
+ let mut alias = [ 0 ; 32 ] ;
581
+ let mut announcement_message = None ;
582
+ read_tlv_fields ! ( reader, {
583
+ ( 0 , features) ,
584
+ ( 2 , last_update) ,
585
+ ( 4 , rgb) ,
586
+ ( 6 , alias)
587
+ } , { ( 8 , announcement_message) } ) ;
598
588
Ok ( NodeAnnouncementInfo {
599
589
features,
600
590
last_update,
@@ -629,37 +619,15 @@ impl fmt::Display for NodeInfo {
629
619
}
630
620
}
631
621
632
- impl Writeable for NodeInfo {
633
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
634
- ( self . channels . len ( ) as u64 ) . write ( writer) ?;
635
- for ref chan in self . channels . iter ( ) {
636
- chan. write ( writer) ?;
637
- }
638
- self . lowest_inbound_channel_fees . write ( writer) ?;
639
- self . announcement_info . write ( writer) ?;
640
- Ok ( ( ) )
641
- }
642
- }
622
+ impl_writeable_tlv_based ! ( NodeInfo , { } , {
623
+ ( 0 , lowest_inbound_channel_fees) ,
624
+ ( 2 , announcement_info) ,
625
+ } , {
626
+ ( 4 , channels) ,
627
+ } ) ;
643
628
644
629
const MAX_ALLOC_SIZE : u64 = 64 * 1024 ;
645
630
646
- impl Readable for NodeInfo {
647
- fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < NodeInfo , DecodeError > {
648
- let channels_count: u64 = Readable :: read ( reader) ?;
649
- let mut channels = Vec :: with_capacity ( cmp:: min ( channels_count, MAX_ALLOC_SIZE / 8 ) as usize ) ;
650
- for _ in 0 ..channels_count {
651
- channels. push ( Readable :: read ( reader) ?) ;
652
- }
653
- let lowest_inbound_channel_fees = Readable :: read ( reader) ?;
654
- let announcement_info = Readable :: read ( reader) ?;
655
- Ok ( NodeInfo {
656
- channels,
657
- lowest_inbound_channel_fees,
658
- announcement_info,
659
- } )
660
- }
661
- }
662
-
663
631
const SERIALIZATION_VERSION : u8 = 1 ;
664
632
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
665
633
0 commit comments