diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 1d776782b..58fab0d52 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -186,9 +186,9 @@ enum BuildError { [Enum] interface Event { - PaymentSuccessful(PaymentHash payment_hash, u64? fee_paid_msat); - PaymentFailed(PaymentHash payment_hash, PaymentFailureReason? reason); - PaymentReceived(PaymentHash payment_hash, u64 amount_msat); + PaymentSuccessful(PaymentId? payment_id, PaymentHash payment_hash, u64? fee_paid_msat); + PaymentFailed(PaymentId? payment_id, PaymentHash payment_hash, PaymentFailureReason? reason); + PaymentReceived(PaymentId? payment_id, PaymentHash payment_hash, u64 amount_msat); ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo); ChannelReady(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id); ChannelClosed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, ClosureReason? reason); diff --git a/src/event.rs b/src/event.rs index 9c44ad04b..c9daff1cd 100644 --- a/src/event.rs +++ b/src/event.rs @@ -46,6 +46,10 @@ use std::time::Duration; pub enum Event { /// A sent payment was successful. PaymentSuccessful { + /// A local identifier used to track the payment. + /// + /// Will only be `None` for events serialized with LDK Node v0.2.1 or prior. + payment_id: Option, /// The hash of the payment. payment_hash: PaymentHash, /// The total fee which was spent at intermediate hops in this payment. @@ -53,6 +57,10 @@ pub enum Event { }, /// A sent payment has failed. PaymentFailed { + /// A local identifier used to track the payment. + /// + /// Will only be `None` for events serialized with LDK Node v0.2.1 or prior. + payment_id: Option, /// The hash of the payment. payment_hash: PaymentHash, /// The reason why the payment failed. @@ -62,6 +70,10 @@ pub enum Event { }, /// A payment has been received. PaymentReceived { + /// A local identifier used to track the payment. + /// + /// Will only be `None` for events serialized with LDK Node v0.2.1 or prior. + payment_id: Option, /// The hash of the payment. payment_hash: PaymentHash, /// The value, in thousandths of a satoshi, that has been received. @@ -110,13 +122,16 @@ impl_writeable_tlv_based_enum!(Event, (0, PaymentSuccessful) => { (0, payment_hash, required), (1, fee_paid_msat, option), + (3, payment_id, option), }, (1, PaymentFailed) => { (0, payment_hash, required), (1, reason, option), + (3, payment_id, option), }, (2, PaymentReceived) => { (0, payment_hash, required), + (1, payment_id, option), (2, amount_msat, required), }, (3, ChannelReady) => { @@ -636,7 +651,11 @@ where }; self.event_queue - .add_event(Event::PaymentReceived { payment_hash, amount_msat }) + .add_event(Event::PaymentReceived { + payment_id: Some(payment_id), + payment_hash, + amount_msat, + }) .unwrap_or_else(|e| { log_error!(self.logger, "Failed to push to event queue: {}", e); panic!("Failed to push to event queue"); @@ -684,7 +703,11 @@ where }); self.event_queue - .add_event(Event::PaymentSuccessful { payment_hash, fee_paid_msat }) + .add_event(Event::PaymentSuccessful { + payment_id: Some(payment_id), + payment_hash, + fee_paid_msat, + }) .unwrap_or_else(|e| { log_error!(self.logger, "Failed to push to event queue: {}", e); panic!("Failed to push to event queue"); @@ -707,7 +730,11 @@ where panic!("Failed to access payment store"); }); self.event_queue - .add_event(Event::PaymentFailed { payment_hash, reason }) + .add_event(Event::PaymentFailed { + payment_id: Some(payment_id), + payment_hash, + reason, + }) .unwrap_or_else(|e| { log_error!(self.logger, "Failed to push to event queue: {}", e); panic!("Failed to push to event queue"); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index f8022639a..bcb47accb 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -82,11 +82,11 @@ pub(crate) use expect_channel_ready_event; macro_rules! expect_payment_received_event { ($node: expr, $amount_msat: expr) => {{ match $node.wait_next_event() { - ref e @ Event::PaymentReceived { payment_hash, amount_msat } => { + ref e @ Event::PaymentReceived { payment_id, amount_msat, .. } => { println!("{} got event {:?}", $node.node_id(), e); assert_eq!(amount_msat, $amount_msat); $node.event_handled(); - payment_hash + payment_id }, ref e => { panic!("{} got unexpected event!: {:?}", std::stringify!(node_b), e); @@ -98,12 +98,12 @@ macro_rules! expect_payment_received_event { pub(crate) use expect_payment_received_event; macro_rules! expect_payment_successful_event { - ($node: expr, $payment_hash: expr, $fee_paid_msat: expr) => {{ + ($node: expr, $payment_id: expr, $fee_paid_msat: expr) => {{ match $node.wait_next_event() { - ref e @ Event::PaymentSuccessful { payment_hash, fee_paid_msat } => { + ref e @ Event::PaymentSuccessful { payment_id, fee_paid_msat, .. } => { println!("{} got event {:?}", $node.node_id(), e); assert_eq!(fee_paid_msat, $fee_paid_msat); - assert_eq!(payment_hash, $payment_hash); + assert_eq!(payment_id, $payment_id); $node.event_handled(); }, ref e => { diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index fa8986c71..1820ef76a 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -136,9 +136,9 @@ fn multi_hop_sending() { let invoice = nodes[4].bolt11_payment().receive(2_500_000, &"asdf", 9217).unwrap(); nodes[0].bolt11_payment().send(&invoice).unwrap(); - let payment_hash = expect_payment_received_event!(&nodes[4], 2_500_000); + let payment_id = expect_payment_received_event!(&nodes[4], 2_500_000); let fee_paid_msat = Some(2000); - expect_payment_successful_event!(nodes[0], payment_hash, fee_paid_msat); + expect_payment_successful_event!(nodes[0], payment_id, fee_paid_msat); } #[test]