@@ -57,29 +57,43 @@ impl SpontaneousPayment {
5757 pub fn send (
5858 & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
5959 ) -> Result < PaymentId , Error > {
60- self . send_inner ( amount_msat, node_id, sending_parameters, None )
60+ self . send_inner ( amount_msat, node_id, sending_parameters, None , None )
6161 }
6262
6363 /// Send a spontaneous payment including a list of custom TLVs.
6464 pub fn send_with_custom_tlvs (
6565 & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
6666 custom_tlvs : Vec < CustomTlvRecord > ,
6767 ) -> Result < PaymentId , Error > {
68- self . send_inner ( amount_msat, node_id, sending_parameters, Some ( custom_tlvs) )
68+ self . send_inner ( amount_msat, node_id, sending_parameters, Some ( custom_tlvs) , None )
69+ }
70+
71+ /// Send a spontaneous payment with custom preimage
72+ pub fn send_with_preimage (
73+ & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
74+ preimage : PaymentPreimage ,
75+ ) -> Result < PaymentId , Error > {
76+ self . send_inner ( amount_msat, node_id, sending_parameters, None , Some ( preimage) )
77+ }
78+
79+ /// Send a spontaneous payment with custom preimage including a list of custom TLVs.
80+ pub fn send_with_preimage_and_custom_tlvs (
81+ & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
82+ custom_tlvs : Vec < CustomTlvRecord > , preimage : PaymentPreimage ,
83+ ) -> Result < PaymentId , Error > {
84+ self . send_inner ( amount_msat, node_id, sending_parameters, Some ( custom_tlvs) , Some ( preimage) )
6985 }
7086
7187 fn send_inner (
7288 & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
73- custom_tlvs : Option < Vec < CustomTlvRecord > > ,
89+ custom_tlvs : Option < Vec < CustomTlvRecord > > , preimage : Option < PaymentPreimage > ,
7490 ) -> Result < PaymentId , Error > {
7591 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
7692 if rt_lock. is_none ( ) {
7793 return Err ( Error :: NotRunning ) ;
7894 }
7995
80- let payment_preimage = sending_parameters
81- . as_ref ( )
82- . and_then ( |sp| sp. preimage )
96+ let payment_preimage = preimage
8397 . unwrap_or_else ( || PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ) ;
8498 let payment_hash = PaymentHash :: from ( payment_preimage) ;
8599 let payment_id = PaymentId ( payment_hash. 0 ) ;
0 commit comments