@@ -58,6 +58,27 @@ impl SpontaneousPayment {
5858 /// node-wide parameters configured via [`Config::sending_parameters`] on a per-field basis.
5959 pub fn send (
6060 & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
61+ ) -> Result < PaymentId , Error > {
62+ self . send_inner ( amount_msat, node_id, sending_parameters, None )
63+ }
64+
65+ /// Send a spontaneous payment including a custom TLV key and value.
66+ pub fn send_with_custom_tlv (
67+ & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
68+ custom_tlv_type : u64 , custom_tlv_value : Vec < u8 > ,
69+ ) -> 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+ )
76+ }
77+
78+ /// Send a spontaneous aka. "keysend", payment.
79+ fn send_inner (
80+ & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
81+ custom_tlv : Option < ( u64 , Vec < u8 > ) > ,
6182 ) -> Result < PaymentId , Error > {
6283 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
6384 if rt_lock. is_none ( ) {
@@ -97,7 +118,12 @@ impl SpontaneousPayment {
97118 . map ( |s| route_params. payment_params . max_channel_saturation_power_of_half = s) ;
98119 } ;
99120
100- let recipient_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
121+ let recipient_fields = match custom_tlv {
122+ Some ( ( tlv_type, tlv_value) ) => RecipientOnionFields :: spontaneous_empty ( )
123+ . with_custom_tlvs ( vec ! [ ( tlv_type, tlv_value) ] )
124+ . map_err ( |_| Error :: PaymentSendingFailed ) ?,
125+ None => RecipientOnionFields :: spontaneous_empty ( ) ,
126+ } ;
101127
102128 match self . channel_manager . send_spontaneous_payment_with_retry (
103129 Some ( payment_preimage) ,
0 commit comments