@@ -346,6 +346,8 @@ pub struct ReceiveTlvs {
346346pub ( crate ) enum BlindedPaymentTlvs {
347347 /// This blinded payment data is for a forwarding node.
348348 Forward ( ForwardTlvs ) ,
349+ /// This blinded payment data is dummy and is to be peeled by receiving node.
350+ Dummy ,
349351 /// This blinded payment data is for the receiving node.
350352 Receive ( ReceiveTlvs ) ,
351353}
@@ -363,6 +365,7 @@ pub(crate) enum BlindedTrampolineTlvs {
363365// Used to include forward and receive TLVs in the same iterator for encoding.
364366enum BlindedPaymentTlvsRef < ' a > {
365367 Forward ( & ' a ForwardTlvs ) ,
368+ Dummy ,
366369 Receive ( & ' a ReceiveTlvs ) ,
367370}
368371
@@ -532,6 +535,11 @@ impl<'a> Writeable for BlindedPaymentTlvsRef<'a> {
532535 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
533536 match self {
534537 Self :: Forward ( tlvs) => tlvs. write ( w) ?,
538+ Self :: Dummy => {
539+ encode_tlv_stream ! ( w, {
540+ ( 65539 , ( ) , required) ,
541+ } )
542+ } ,
535543 Self :: Receive ( tlvs) => tlvs. write ( w) ?,
536544 }
537545 Ok ( ( ) )
@@ -548,32 +556,48 @@ impl Readable for BlindedPaymentTlvs {
548556 ( 2 , scid, option) ,
549557 ( 8 , next_blinding_override, option) ,
550558 ( 10 , payment_relay, option) ,
551- ( 12 , payment_constraints, required ) ,
559+ ( 12 , payment_constraints, option ) ,
552560 ( 14 , features, ( option, encoding: ( BlindedHopFeatures , WithoutLength ) ) ) ,
553561 ( 65536 , payment_secret, option) ,
554562 ( 65537 , payment_context, option) ,
563+ ( 65539 , is_dummy, option)
555564 } ) ;
556565
557- if let Some ( short_channel_id) = scid {
558- if payment_secret. is_some ( ) {
559- return Err ( DecodeError :: InvalidValue ) ;
560- }
561- Ok ( BlindedPaymentTlvs :: Forward ( ForwardTlvs {
566+ match (
567+ scid,
568+ next_blinding_override,
569+ payment_relay,
570+ payment_constraints,
571+ features,
572+ payment_secret,
573+ payment_context,
574+ is_dummy,
575+ ) {
576+ (
577+ Some ( short_channel_id) ,
578+ next_override,
579+ Some ( relay) ,
580+ Some ( constraints) ,
581+ features,
582+ None ,
583+ None ,
584+ None ,
585+ ) => Ok ( BlindedPaymentTlvs :: Forward ( ForwardTlvs {
562586 short_channel_id,
563- payment_relay : payment_relay . ok_or ( DecodeError :: InvalidValue ) ? ,
564- payment_constraints : payment_constraints . 0 . unwrap ( ) ,
565- next_blinding_override,
587+ payment_relay : relay ,
588+ payment_constraints : constraints ,
589+ next_blinding_override : next_override ,
566590 features : features. unwrap_or_else ( BlindedHopFeatures :: empty) ,
567- } ) )
568- } else {
569- if payment_relay . is_some ( ) || features . is_some ( ) {
570- return Err ( DecodeError :: InvalidValue ) ;
571- }
572- Ok ( BlindedPaymentTlvs :: Receive ( ReceiveTlvs {
573- payment_secret : payment_secret . ok_or ( DecodeError :: InvalidValue ) ? ,
574- payment_constraints : payment_constraints . 0 . unwrap ( ) ,
575- payment_context : payment_context . ok_or ( DecodeError :: InvalidValue ) ? ,
576- } ) )
591+ } ) ) ,
592+ ( None , None , None , Some ( constraints ) , None , Some ( secret ) , Some ( context ) , None ) => {
593+ Ok ( BlindedPaymentTlvs :: Receive ( ReceiveTlvs {
594+ payment_secret : secret ,
595+ payment_constraints : constraints ,
596+ payment_context : context ,
597+ } ) )
598+ } ,
599+ ( None , None , None , None , None , None , None , Some ( ( ) ) ) => Ok ( BlindedPaymentTlvs :: Dummy ) ,
600+ _ => return Err ( DecodeError :: InvalidValue ) ,
577601 }
578602 }
579603}
0 commit comments