@@ -57,27 +57,44 @@ impl SpontaneousPayment {
57
57
pub fn send (
58
58
& self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
59
59
) -> 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 )
61
61
}
62
62
63
63
/// Send a spontaneous payment including a list of custom TLVs.
64
64
pub fn send_with_custom_tlvs (
65
65
& self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
66
66
custom_tlvs : Vec < CustomTlvRecord > ,
67
67
) -> 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 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) )
69
85
}
70
86
71
87
fn send_inner (
72
88
& 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 > ,
74
90
) -> Result < PaymentId , Error > {
75
91
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
76
92
if rt_lock. is_none ( ) {
77
93
return Err ( Error :: NotRunning ) ;
78
94
}
79
95
80
- let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
96
+ let payment_preimage = preimage
97
+ . unwrap_or_else ( || PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ) ;
81
98
let payment_hash = PaymentHash :: from ( payment_preimage) ;
82
99
let payment_id = PaymentId ( payment_hash. 0 ) ;
83
100
0 commit comments