-
Notifications
You must be signed in to change notification settings - Fork 109
Support passing preimage for spontaneous payments #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
412cff4
781fea7
15fc6b2
8cbb6d5
143ec7c
12318c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,27 +57,44 @@ impl SpontaneousPayment { | |
pub fn send( | ||
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>, | ||
) -> Result<PaymentId, Error> { | ||
self.send_inner(amount_msat, node_id, sending_parameters, None) | ||
self.send_inner(amount_msat, node_id, sending_parameters, None, None) | ||
} | ||
|
||
/// Send a spontaneous payment including a list of custom TLVs. | ||
pub fn send_with_custom_tlvs( | ||
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>, | ||
custom_tlvs: Vec<CustomTlvRecord>, | ||
) -> Result<PaymentId, Error> { | ||
self.send_inner(amount_msat, node_id, sending_parameters, Some(custom_tlvs)) | ||
self.send_inner(amount_msat, node_id, sending_parameters, Some(custom_tlvs), None) | ||
} | ||
|
||
/// Send a spontaneous payment with custom preimage | ||
pub fn send_with_preimage( | ||
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>, | ||
preimage: PaymentPreimage, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should expand the purpose of This approach would allow us to include preimage as an Option within A significant benefit of this change would be the ability to deprecate or drop specialized functions like What do you think about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially hesitated about mixing routing parameters with payment content. Your point about expanding I'll refactor to move preimage into Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, no, I don't think we should do that. Note that after LDK 0.2 release (cf. #462) we'll replace
Please revert this. I think we can either have separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we add this as a new required parameter, let's move it before the optional parameters, i.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, will fix it. Thank you. |
||
) -> Result<PaymentId, Error> { | ||
self.send_inner(amount_msat, node_id, sending_parameters, None, Some(preimage)) | ||
} | ||
|
||
/// Send a spontaneous payment with custom preimage including a list of custom TLVs. | ||
pub fn send_with_preimage_and_custom_tlvs( | ||
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>, | ||
custom_tlvs: Vec<CustomTlvRecord>, preimage: PaymentPreimage, | ||
) -> Result<PaymentId, Error> { | ||
self.send_inner(amount_msat, node_id, sending_parameters, Some(custom_tlvs), Some(preimage)) | ||
} | ||
|
||
fn send_inner( | ||
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>, | ||
custom_tlvs: Option<Vec<CustomTlvRecord>>, | ||
custom_tlvs: Option<Vec<CustomTlvRecord>>, preimage: Option<PaymentPreimage>, | ||
) -> Result<PaymentId, Error> { | ||
let rt_lock = self.runtime.read().unwrap(); | ||
if rt_lock.is_none() { | ||
return Err(Error::NotRunning); | ||
} | ||
|
||
let payment_preimage = PaymentPreimage(self.keys_manager.get_secure_random_bytes()); | ||
let payment_preimage = preimage | ||
.unwrap_or_else(|| PaymentPreimage(self.keys_manager.get_secure_random_bytes())); | ||
let payment_hash = PaymentHash::from(payment_preimage); | ||
let payment_id = PaymentId(payment_hash.0); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Let's move these new entries to the correct location w.r.t. API, i.e. below
send_with_custom_tlvs
.