Skip to content

Commit

Permalink
Merge pull request #42 from getAlby/keysend-preimage
Browse files Browse the repository at this point in the history
Add preimage argument to SpontaneousPayment::send()
  • Loading branch information
rolznz authored Aug 1, 2024
2 parents c75e244 + 727efe9 commit 7f8486f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
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

0 comments on commit 7f8486f

Please sign in to comment.