Skip to content

Commit

Permalink
Add fee_paid_msat to PaymentSuccessful event
Browse files Browse the repository at this point in the history
  The fee as returned from `PaymentSent` event generated by LDK and is
  saved in `PaymentSuccessful` event.
  • Loading branch information
jbesraa committed Mar 5, 2024
1 parent 71a3e32 commit 53f91ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ enum BuildError {

[Enum]
interface Event {
PaymentSuccessful(PaymentHash payment_hash);
PaymentSuccessful(PaymentHash payment_hash, u64? fee_paid_msat);
PaymentFailed(PaymentHash payment_hash, PaymentFailureReason? reason);
PaymentReceived(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);
Expand Down
5 changes: 4 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum Event {
PaymentSuccessful {
/// The hash of the payment.
payment_hash: PaymentHash,
/// Paid fee in milli-satoshis.
fee_paid_msat: Option<u64>,
},
/// A sent payment has failed.
PaymentFailed {
Expand Down Expand Up @@ -106,6 +108,7 @@ pub enum Event {
impl_writeable_tlv_based_enum!(Event,
(0, PaymentSuccessful) => {
(0, payment_hash, required),
(1, fee_paid_msat, option),
},
(1, PaymentFailed) => {
(0, payment_hash, required),
Expand Down Expand Up @@ -611,7 +614,7 @@ where
);
}
self.event_queue
.add_event(Event::PaymentSuccessful { payment_hash })
.add_event(Event::PaymentSuccessful { 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");
Expand Down
24 changes: 22 additions & 2 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,28 @@ fn multi_hop_sending() {
let invoice = nodes[4].receive_payment(2_500_000, &"asdf", 9217).unwrap();
nodes[0].send_payment(&invoice).unwrap();

expect_event!(nodes[4], PaymentReceived);
expect_event!(nodes[0], PaymentSuccessful);
let payment_hash = match nodes[4].wait_next_event() {
ref e @ Event::PaymentReceived { payment_hash, amount_msat } => {
println!("{} got event {:?}", std::stringify!(node_b), e);
assert_eq!(amount_msat, 2_500_000);
nodes[4].event_handled();
payment_hash
},
ref e => {
panic!("{} got unexpected event!: {:?}", std::stringify!(node_b), e);
},
};
match nodes[0].wait_next_event() {
ref e @ Event::PaymentSuccessful { payment_hash: hash, fee_paid_msat } => {
println!("{} got event {:?}", std::stringify!(node_b), e);
assert_eq!(hash, payment_hash);
assert_eq!(fee_paid_msat, Some(2000));
nodes[0].event_handled();
},
ref e => {
panic!("{} got unexpected event!: {:?}", std::stringify!(node_b), e);
},
};
}

#[test]
Expand Down

0 comments on commit 53f91ba

Please sign in to comment.