Skip to content

Commit 89528dd

Browse files
committed
support for passing preimage for spontaneous payment
1 parent 01c396a commit 89528dd

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/payment/spontaneous.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,44 @@ 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 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 = 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()));
8198
let payment_hash = PaymentHash::from(payment_preimage);
8299
let payment_id = PaymentId(payment_hash.0);
83100

0 commit comments

Comments
 (0)