@@ -357,14 +357,23 @@ impl Writeable for Route {
357
357
fn write < W : crate :: util:: ser:: Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
358
358
write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
359
359
( self . paths . len ( ) as u64 ) . write ( writer) ?;
360
+ let mut blinded_tails = None ;
360
361
for path in self . paths . iter ( ) {
361
362
( path. hops . len ( ) as u8 ) . write ( writer) ?;
362
363
for hop in path. hops . iter ( ) {
363
364
hop. write ( writer) ?;
365
+ if let Some ( blinded_tail) = & path. blinded_tail {
366
+ if blinded_tails. is_none ( ) { blinded_tails = Some ( Vec :: new ( ) ) ; }
367
+ blinded_tails. as_mut ( ) . map ( |tails| tails. push ( blinded_tail) ) ;
368
+ }
364
369
}
365
370
}
371
+ if blinded_tails. is_some ( ) && blinded_tails. as_ref ( ) . unwrap ( ) . len ( ) != self . paths . len ( ) {
372
+ return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "Missing blinded tail for path (if blinded tails are included, there must be 1 set per path)" ) )
373
+ }
366
374
write_tlv_fields ! ( writer, {
367
375
( 1 , self . payment_params, option) ,
376
+ ( 2 , blinded_tails, option) ,
368
377
} ) ;
369
378
Ok ( ( ) )
370
379
}
@@ -388,10 +397,17 @@ impl Readable for Route {
388
397
cmp:: min ( min_final_cltv_expiry_delta, hops. last ( ) . unwrap ( ) . cltv_expiry_delta ) ;
389
398
paths. push ( Path { hops, blinded_tail : None } ) ;
390
399
}
391
- let mut payment_params = None ;
392
- read_tlv_fields ! ( reader, {
400
+ _init_and_read_tlv_fields ! ( reader, {
393
401
( 1 , payment_params, ( option: ReadableArgs , min_final_cltv_expiry_delta) ) ,
402
+ ( 2 , blinded_tails, vec_type) ,
394
403
} ) ;
404
+ let blinded_tails = blinded_tails. unwrap_or ( Vec :: new ( ) ) ;
405
+ if blinded_tails. len ( ) != 0 {
406
+ if blinded_tails. len ( ) != paths. len ( ) { return Err ( DecodeError :: InvalidValue ) }
407
+ for ( mut path, blinded_tail) in paths. iter_mut ( ) . zip ( blinded_tails. into_iter ( ) ) {
408
+ path. blinded_tail = Some ( blinded_tail) ;
409
+ }
410
+ }
395
411
Ok ( Route { paths, payment_params } )
396
412
}
397
413
}
0 commit comments