@@ -14,7 +14,7 @@ use crate::payment::store::{
1414 PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus , PaymentStore ,
1515} ;
1616use crate :: payment:: SendingParameters ;
17- use crate :: types:: { ChannelManager , KeysManager } ;
17+ use crate :: types:: { ChannelManager , KeysManager , TlvEntry } ;
1818
1919use lightning:: ln:: channelmanager:: { PaymentId , RecipientOnionFields , Retry , RetryableSendFailure } ;
2020use lightning:: ln:: { PaymentHash , PaymentPreimage } ;
@@ -63,22 +63,16 @@ impl SpontaneousPayment {
6363 }
6464
6565 /// Send a spontaneous payment including a custom TLV key and value.
66- pub fn send_with_custom_tlv (
66+ pub fn send_with_custom_tlvs (
6767 & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
68- custom_tlv_type : u64 , custom_tlv_value : Vec < u8 > ,
68+ custom_tlvs : Vec < TlvEntry > ,
6969 ) -> Result < PaymentId , Error > {
70- self . send_inner (
71- amount_msat,
72- node_id,
73- sending_parameters,
74- Some ( ( custom_tlv_type, custom_tlv_value) ) ,
75- )
70+ self . send_inner ( amount_msat, node_id, sending_parameters, Some ( custom_tlvs) )
7671 }
7772
78- /// Send a spontaneous aka. "keysend", payment.
7973 fn send_inner (
8074 & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
81- custom_tlv : Option < ( u64 , Vec < u8 > ) > ,
75+ custom_tlvs : Option < Vec < TlvEntry > > ,
8276 ) -> Result < PaymentId , Error > {
8377 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
8478 if rt_lock. is_none ( ) {
@@ -118,17 +112,13 @@ impl SpontaneousPayment {
118112 . map ( |s| route_params. payment_params . max_channel_saturation_power_of_half = s) ;
119113 } ;
120114
121- let recipient_fields = match custom_tlv {
122- Some ( ( tlv_type, tlv_value) ) => {
123- if tlv_value. len ( ) > 1300 {
124- // The real limit is lower, but we can't know without the full route.
125- // This is just an early check to avoid trying a payment that will fail.
126- return Err ( Error :: PaymentSendingFailed ) ;
127- }
128- RecipientOnionFields :: spontaneous_empty ( )
129- . with_custom_tlvs ( vec ! [ ( tlv_type, tlv_value) ] )
130- . map_err ( |_| Error :: PaymentSendingFailed ) ?
131- } ,
115+ let recipient_fields = match custom_tlvs {
116+ Some ( tlvs) => RecipientOnionFields :: spontaneous_empty ( )
117+ . with_custom_tlvs ( tlvs. into_iter ( ) . map ( |tlv| ( tlv. r#type , tlv. value ) ) . collect ( ) )
118+ . map_err ( |e| {
119+ log_error ! ( self . logger, "Failed to send payment with custom TLVs: {:?}" , e) ;
120+ Error :: InvalidCustomTlvs
121+ } ) ?,
132122 None => RecipientOnionFields :: spontaneous_empty ( ) ,
133123 } ;
134124
0 commit comments