@@ -54,7 +54,7 @@ macro_rules! _encode_tlv {
54
54
field. write( $stream) ?;
55
55
}
56
56
} ;
57
- ( $stream: expr, $optional_type: expr, $optional_field: expr, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => {
57
+ ( $stream: expr, $optional_type: expr, $optional_field: expr, ( legacy, $fieldty: ty, $write: expr) ) => {
58
58
$crate:: _encode_tlv!( $stream, $optional_type, $write, option) ;
59
59
} ;
60
60
( $stream: expr, $type: expr, $field: expr, optional_vec) => {
@@ -216,7 +216,7 @@ macro_rules! _get_varint_length_prefixed_tlv_length {
216
216
$len. 0 += field_len;
217
217
}
218
218
} ;
219
- ( $len: expr, $optional_type: expr, $optional_field: expr, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => {
219
+ ( $len: expr, $optional_type: expr, $optional_field: expr, ( legacy, $fieldty: ty, $write: expr) ) => {
220
220
$crate:: _get_varint_length_prefixed_tlv_length!( $len, $optional_type, $write, option) ;
221
221
} ;
222
222
( $len: expr, $type: expr, $field: expr, optional_vec) => {
@@ -301,7 +301,7 @@ macro_rules! _check_decoded_tlv_order {
301
301
( $last_seen_type: expr, $typ: expr, $type: expr, $field: ident, ( option, explicit_type: $fieldty: ty) ) => { {
302
302
// no-op
303
303
} } ;
304
- ( $last_seen_type: expr, $typ: expr, $type: expr, $field: ident, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => { {
304
+ ( $last_seen_type: expr, $typ: expr, $type: expr, $field: ident, ( legacy, $fieldty: ty, $write: expr) ) => { {
305
305
// no-op
306
306
} } ;
307
307
( $last_seen_type: expr, $typ: expr, $type: expr, $field: ident, ( required, explicit_type: $fieldty: ty) ) => { {
@@ -363,7 +363,7 @@ macro_rules! _check_missing_tlv {
363
363
( $last_seen_type: expr, $type: expr, $field: ident, ( option, explicit_type: $fieldty: ty) ) => { {
364
364
// no-op
365
365
} } ;
366
- ( $last_seen_type: expr, $type: expr, $field: ident, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => { {
366
+ ( $last_seen_type: expr, $type: expr, $field: ident, ( legacy, $fieldty: ty, $write: expr) ) => { {
367
367
// no-op
368
368
} } ;
369
369
( $last_seen_type: expr, $type: expr, $field: ident, ( required, explicit_type: $fieldty: ty) ) => { {
@@ -413,7 +413,7 @@ macro_rules! _decode_tlv {
413
413
let _field: & Option <$fieldty> = & $field;
414
414
_decode_tlv!( $outer_reader, $reader, $field, option) ;
415
415
} } ;
416
- ( $outer_reader: expr, $reader: expr, $field: ident, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => { {
416
+ ( $outer_reader: expr, $reader: expr, $field: ident, ( legacy, $fieldty: ty, $write: expr) ) => { {
417
417
$crate:: _decode_tlv!( $outer_reader, $reader, $field, ( option, explicit_type: $fieldty) ) ;
418
418
// Note that $read is only executed in impl_writeable_tlv_based_enum_upgradable!
419
419
} } ;
@@ -478,16 +478,6 @@ macro_rules! _decode_tlv {
478
478
} } ;
479
479
}
480
480
481
- /// Runs the read side logic for legacy read types
482
- #[ doc( hidden) ]
483
- #[ macro_export]
484
- macro_rules! _run_legacy_tlv_read_logic {
485
- ( $field: ident, ( legacy, $fieldty: ty, $read: expr, $write: expr) ) => { {
486
- $read;
487
- } } ;
488
- ( $field: ident, $fieldty: tt) => { } ;
489
- }
490
-
491
481
/// Checks if `$val` matches `$type`.
492
482
/// This is exported for use by other exported macros, do not use directly.
493
483
#[ doc( hidden) ]
@@ -569,13 +559,6 @@ macro_rules! decode_tlv_stream_with_custom_tlv_decode {
569
559
#[ macro_export]
570
560
macro_rules! _decode_tlv_stream_range {
571
561
( $stream: expr, $range: expr, $rewind: ident, { $( ( $type: expr, $field: ident, $fieldty: tt) ) ,* $( , ) * }
572
- $( , $decode_custom_tlv: expr) ?) => { {
573
- $crate:: _decode_tlv_stream_range!( SKIP_LEGACY , $stream, $range, $rewind, { $( ( $type, $field, $fieldty) ) ,* } $( , $decode_custom_tlv) ?) ;
574
- $( {
575
- $crate:: _run_legacy_tlv_read_logic!( $field, $fieldty) ;
576
- } ) *
577
- } } ;
578
- ( SKIP_LEGACY , $stream: expr, $range: expr, $rewind: ident, { $( ( $type: expr, $field: ident, $fieldty: tt) ) ,* $( , ) * }
579
562
$( , $decode_custom_tlv: expr) ?) => { {
580
563
use $crate:: ln:: msgs:: DecodeError ;
581
564
let mut last_seen_type: Option <u64 > = None ;
@@ -818,7 +801,7 @@ macro_rules! _init_tlv_based_struct_field {
818
801
( $field: ident, option) => {
819
802
$field
820
803
} ;
821
- ( $field: ident, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => {
804
+ ( $field: ident, ( legacy, $fieldty: ty, $write: expr) ) => {
822
805
$crate:: _init_tlv_based_struct_field!( $field, option)
823
806
} ;
824
807
( $field: ident, ( option: $trait: ident $( , $read_arg: expr) ?) ) => {
@@ -872,7 +855,7 @@ macro_rules! _init_tlv_field_var {
872
855
( $field: ident, ( option, explicit_type: $fieldty: ty) ) => {
873
856
let mut $field: Option <$fieldty> = None ;
874
857
} ;
875
- ( $field: ident, ( legacy, $fieldty: ty, $read : expr , $ write: expr) ) => {
858
+ ( $field: ident, ( legacy, $fieldty: ty, $write: expr) ) => {
876
859
$crate:: _init_tlv_field_var!( $field, ( option, explicit_type: $fieldty) ) ;
877
860
} ;
878
861
( $field: ident, ( required, explicit_type: $fieldty: ty) ) => {
@@ -943,24 +926,12 @@ macro_rules! _ignore_arg {
943
926
#[ macro_export]
944
927
macro_rules! _decode_and_build {
945
928
( $stream: ident, $thing: path, { $( ( $type: expr, $field: ident, $fieldty: tt) ) ,* $( , ) * } ) => { {
929
+ $crate:: _init_and_read_len_prefixed_tlv_fields!( $stream, {
930
+ $( ( $type, $field, $fieldty) ) ,*
931
+ } ) ;
946
932
$(
947
- $crate:: _init_tlv_field_var!( $field, $fieldty) ;
948
- ) *
949
- let tlv_len: $crate:: util:: ser:: BigSize = $crate:: util:: ser:: Readable :: read( $stream) ?;
950
- let mut rd = $crate:: util:: ser:: FixedLengthReader :: new( $stream, tlv_len. 0 ) ;
951
- let rewind = |_, _| { unreachable!( ) } ;
952
- $crate:: _decode_tlv_stream_range!( SKIP_LEGACY , & mut rd, .., rewind, { $( ( $type, $field, $fieldty) ) ,* } ) ;
953
- rd. eat_remaining( ) . map_err( |_| $crate:: ln:: msgs:: DecodeError :: ShortRead ) ?;
954
- // We mark fields as `mut` as we read them so that legacy post-read actions can modify them
955
- // if desired.
956
- $(
957
- #[ allow( unused_mut) ]
958
- let mut $field = $crate:: _init_tlv_based_struct_field!( $field, $fieldty) ;
933
+ let $field = $crate:: _init_tlv_based_struct_field!( $field, $fieldty) ;
959
934
) *
960
- $( {
961
- $crate:: _run_legacy_tlv_read_logic!( $field, $fieldty) ;
962
- } ) *
963
-
964
935
:: lightning_macros:: drop_legacy_field_definition!( $thing {
965
936
$( $field: $crate:: _ignore_arg!( $field, $fieldty) ) ,*
966
937
} )
@@ -973,10 +944,10 @@ macro_rules! _decode_and_build {
973
944
/// If `$fieldty` is `option`, then `$field` is optional field.
974
945
/// If `$fieldty` is `optional_vec`, then `$field` is a [`Vec`], which needs to have its individual elements serialized.
975
946
/// Note that for `optional_vec` no bytes are written if the vec is empty
976
- /// If `$fieldty` is `(legacy, $ty, $read, $ write)` then, when writing, the expression $write will
947
+ /// If `$fieldty` is `(legacy, $ty, $write)` then, when writing, the expression $write will
977
948
/// be called which returns an `Option` and is written as a TLV if `Some`. When reading, an
978
- /// optional field of type `$ty` is read. The code in `$read` is always executed after all TLVs
979
- /// have been read .
949
+ /// optional field of type `$ty` is read (which can be used in later `default_value` or
950
+ /// `static_value` fields) .
980
951
///
981
952
/// For example,
982
953
/// ```
0 commit comments