@@ -493,14 +493,6 @@ const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
493
493
/// The recipient of a payment.
494
494
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
495
495
pub struct PaymentParameters {
496
- /// Features supported by the payee.
497
- ///
498
- /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
499
- /// does not contain any features.
500
- ///
501
- /// [`for_keysend`]: Self::for_keysend
502
- pub features : Option < InvoiceFeatures > ,
503
-
504
496
/// Route hints and other information used to route to the payee.
505
497
pub payee : Payee ,
506
498
@@ -550,7 +542,7 @@ impl Writeable for PaymentParameters {
550
542
write_tlv_fields ! ( writer, {
551
543
( 0 , self . payee. node_id( ) , option) ,
552
544
( 1 , self . max_total_cltv_expiry_delta, required) ,
553
- ( 2 , self . features , option) ,
545
+ ( 2 , self . payee . bolt11_features ( ) , option) ,
554
546
( 3 , self . max_path_count, required) ,
555
547
( 4 , * clear_hints, vec_type) ,
556
548
( 5 , self . max_channel_saturation_power_of_half, required) ,
@@ -586,11 +578,11 @@ impl ReadableArgs<u32> for PaymentParameters {
586
578
Payee :: Clear {
587
579
route_hints : clear_route_hints,
588
580
node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
581
+ features,
589
582
}
590
583
} ;
591
584
Ok ( Self {
592
585
max_total_cltv_expiry_delta : _init_tlv_based_struct_field ! ( max_total_cltv_expiry_delta, ( default_value, unused) ) ,
593
- features,
594
586
max_path_count : _init_tlv_based_struct_field ! ( max_path_count, ( default_value, unused) ) ,
595
587
payee,
596
588
max_channel_saturation_power_of_half : _init_tlv_based_struct_field ! ( max_channel_saturation_power_of_half, ( default_value, unused) ) ,
@@ -609,8 +601,7 @@ impl PaymentParameters {
609
601
/// provided.
610
602
pub fn from_node_id ( payee_pubkey : PublicKey , final_cltv_expiry_delta : u32 ) -> Self {
611
603
Self {
612
- features : None ,
613
- payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] } ,
604
+ payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] , features : None } ,
614
605
expiry_time : None ,
615
606
max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
616
607
max_path_count : DEFAULT_MAX_PATH_COUNT ,
@@ -633,8 +624,11 @@ impl PaymentParameters {
633
624
///
634
625
/// This is not exported to bindings users since bindings don't support move semantics
635
626
pub fn with_bolt11_features ( self , features : InvoiceFeatures ) -> Result < Self , ( ) > {
636
- if let Payee :: Blinded ( _) = self . payee { return Err ( ( ) ) }
637
- Ok ( Self { features : Some ( features) , ..self } )
627
+ match self . payee {
628
+ Payee :: Blinded ( _) => Err ( ( ) ) ,
629
+ Payee :: Clear { route_hints, node_id, .. } =>
630
+ Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features : Some ( features) } , ..self } )
631
+ }
638
632
}
639
633
640
634
/// Includes hints for routing to the payee. Errors if the parameters were initialized with
@@ -644,8 +638,8 @@ impl PaymentParameters {
644
638
pub fn with_route_hints ( self , route_hints : Vec < RouteHint > ) -> Result < Self , ( ) > {
645
639
match self . payee {
646
640
Payee :: Blinded ( _) => Err ( ( ) ) ,
647
- Payee :: Clear { node_id, .. } =>
648
- Ok ( Self { payee : Payee :: Clear { route_hints, node_id } , ..self } )
641
+ Payee :: Clear { node_id, features , .. } =>
642
+ Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features } , ..self } )
649
643
}
650
644
}
651
645
@@ -691,6 +685,13 @@ pub enum Payee {
691
685
node_id : PublicKey ,
692
686
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
693
687
route_hints : Vec < RouteHint > ,
688
+ /// Features supported by the payee.
689
+ ///
690
+ /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
691
+ /// does not contain any features.
692
+ ///
693
+ /// [`for_keysend`]: PaymentParameters::for_keysend
694
+ features : Option < InvoiceFeatures > ,
694
695
} ,
695
696
}
696
697
@@ -701,6 +702,12 @@ impl Payee {
701
702
_ => None ,
702
703
}
703
704
}
705
+ fn bolt11_features ( & self ) -> & Option < InvoiceFeatures > {
706
+ match self {
707
+ Self :: Clear { features, .. } => features,
708
+ _ => & None ,
709
+ }
710
+ }
704
711
}
705
712
706
713
/// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1155,7 +1162,7 @@ where L::Target: Logger {
1155
1162
}
1156
1163
1157
1164
match & payment_params. payee {
1158
- Payee :: Clear { route_hints, node_id } => {
1165
+ Payee :: Clear { route_hints, node_id, .. } => {
1159
1166
for route in route_hints. iter ( ) {
1160
1167
for hop in & route. 0 {
1161
1168
if hop. src_node_id == * node_id {
@@ -1239,7 +1246,7 @@ where L::Target: Logger {
1239
1246
// work reliably.
1240
1247
let allow_mpp = if payment_params. max_path_count == 1 {
1241
1248
false
1242
- } else if let Some ( features) = & payment_params. features {
1249
+ } else if let Some ( features) = payment_params. payee . bolt11_features ( ) {
1243
1250
features. supports_basic_mpp ( )
1244
1251
} else if let Some ( payee) = payee_node_id {
1245
1252
network_nodes. get ( & payee) . map_or ( false , |node| node. announcement_info . as_ref ( ) . map_or ( false ,
@@ -2099,7 +2106,7 @@ where L::Target: Logger {
2099
2106
// Make sure we would never create a route with more paths than we allow.
2100
2107
debug_assert ! ( selected_paths. len( ) <= payment_params. max_path_count. into( ) ) ;
2101
2108
2102
- if let Some ( features) = & payment_params. features {
2109
+ if let Some ( features) = payment_params. payee . bolt11_features ( ) {
2103
2110
for path in selected_paths. iter_mut ( ) {
2104
2111
if let Ok ( route_hop) = path. last_mut ( ) . unwrap ( ) {
2105
2112
route_hop. node_features = features. to_context ( ) ;
0 commit comments