@@ -346,14 +346,23 @@ impl Writeable for Route {
346
346
fn write < W : crate :: util:: ser:: Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
347
347
write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
348
348
( self . paths . len ( ) as u64 ) . write ( writer) ?;
349
+ let mut blinded_tails = None ;
349
350
for path in self . paths . iter ( ) {
350
351
( path. hops . len ( ) as u8 ) . write ( writer) ?;
351
352
for hop in path. hops . iter ( ) {
352
353
hop. write ( writer) ?;
354
+ if let Some ( blinded_tail) = & path. blinded_tail {
355
+ if blinded_tails. is_none ( ) { blinded_tails = Some ( Vec :: new ( ) ) ; }
356
+ blinded_tails. as_mut ( ) . map ( |tails| tails. push ( blinded_tail) ) ;
357
+ }
353
358
}
354
359
}
360
+ if blinded_tails. is_some ( ) && blinded_tails. as_ref ( ) . unwrap ( ) . len ( ) != self . paths . len ( ) {
361
+ 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)" ) )
362
+ }
355
363
write_tlv_fields ! ( writer, {
356
364
( 1 , self . payment_params, option) ,
365
+ ( 2 , blinded_tails, option) ,
357
366
} ) ;
358
367
Ok ( ( ) )
359
368
}
@@ -377,10 +386,17 @@ impl Readable for Route {
377
386
cmp:: min ( min_final_cltv_expiry_delta, hops. last ( ) . unwrap ( ) . cltv_expiry_delta ) ;
378
387
paths. push ( Path { hops, blinded_tail : None } ) ;
379
388
}
380
- let mut payment_params = None ;
381
- read_tlv_fields ! ( reader, {
389
+ _init_and_read_tlv_fields ! ( reader, {
382
390
( 1 , payment_params, ( option: ReadableArgs , min_final_cltv_expiry_delta) ) ,
391
+ ( 2 , blinded_tails, vec_type) ,
383
392
} ) ;
393
+ let blinded_tails = blinded_tails. unwrap_or ( Vec :: new ( ) ) ;
394
+ if blinded_tails. len ( ) != 0 {
395
+ if blinded_tails. len ( ) != paths. len ( ) { return Err ( DecodeError :: InvalidValue ) }
396
+ for ( mut path, blinded_tail) in paths. iter_mut ( ) . zip ( blinded_tails. into_iter ( ) ) {
397
+ path. blinded_tail = Some ( blinded_tail) ;
398
+ }
399
+ }
384
400
Ok ( Route { paths, payment_params } )
385
401
}
386
402
}
0 commit comments