Skip to content
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

Add preimage argument to SpontaneousPayment::send() #42

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ interface Bolt12Payment {

interface SpontaneousPayment {
[Throws=NodeError]
PaymentId send(u64 amount_msat, PublicKey node_id, sequence<TlvEntry> custom_tlvs);
PaymentId send(u64 amount_msat, PublicKey node_id, sequence<TlvEntry> custom_tlvs, PaymentPreimage? preimage);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};
Expand Down
4 changes: 3 additions & 1 deletion src/payment/spontaneous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ impl SpontaneousPayment {
/// Send a spontaneous, aka. "keysend", payment
pub fn send(
&self, amount_msat: u64, node_id: PublicKey, custom_tlvs: Vec<TlvEntry>,
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);

Expand Down
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
let tlv2 = TlvEntry { r#type: 131075, value: vec![0xaa, 0xbb] };
let keysend_payment_id = node_a
.spontaneous_payment()
.send(keysend_amount_msat, node_b.node_id(), vec![tlv1, tlv2])
.send(keysend_amount_msat, node_b.node_id(), vec![tlv1, tlv2], None)
.unwrap();
expect_event!(node_a, PaymentSuccessful);
let received_keysend_amount = match node_b.wait_next_event() {
Expand Down
Loading