Skip to content

Commit 53f91ba

Browse files
committed
Add fee_paid_msat to PaymentSuccessful event
The fee as returned from `PaymentSent` event generated by LDK and is saved in `PaymentSuccessful` event.
1 parent 71a3e32 commit 53f91ba

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ enum BuildError {
154154

155155
[Enum]
156156
interface Event {
157-
PaymentSuccessful(PaymentHash payment_hash);
157+
PaymentSuccessful(PaymentHash payment_hash, u64? fee_paid_msat);
158158
PaymentFailed(PaymentHash payment_hash, PaymentFailureReason? reason);
159159
PaymentReceived(PaymentHash payment_hash, u64 amount_msat);
160160
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);

src/event.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub enum Event {
4747
PaymentSuccessful {
4848
/// The hash of the payment.
4949
payment_hash: PaymentHash,
50+
/// Paid fee in milli-satoshis.
51+
fee_paid_msat: Option<u64>,
5052
},
5153
/// A sent payment has failed.
5254
PaymentFailed {
@@ -106,6 +108,7 @@ pub enum Event {
106108
impl_writeable_tlv_based_enum!(Event,
107109
(0, PaymentSuccessful) => {
108110
(0, payment_hash, required),
111+
(1, fee_paid_msat, option),
109112
},
110113
(1, PaymentFailed) => {
111114
(0, payment_hash, required),
@@ -611,7 +614,7 @@ where
611614
);
612615
}
613616
self.event_queue
614-
.add_event(Event::PaymentSuccessful { payment_hash })
617+
.add_event(Event::PaymentSuccessful { payment_hash, fee_paid_msat })
615618
.unwrap_or_else(|e| {
616619
log_error!(self.logger, "Failed to push to event queue: {}", e);
617620
panic!("Failed to push to event queue");

tests/integration_tests_rust.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,28 @@ fn multi_hop_sending() {
133133
let invoice = nodes[4].receive_payment(2_500_000, &"asdf", 9217).unwrap();
134134
nodes[0].send_payment(&invoice).unwrap();
135135

136-
expect_event!(nodes[4], PaymentReceived);
137-
expect_event!(nodes[0], PaymentSuccessful);
136+
let payment_hash = match nodes[4].wait_next_event() {
137+
ref e @ Event::PaymentReceived { payment_hash, amount_msat } => {
138+
println!("{} got event {:?}", std::stringify!(node_b), e);
139+
assert_eq!(amount_msat, 2_500_000);
140+
nodes[4].event_handled();
141+
payment_hash
142+
},
143+
ref e => {
144+
panic!("{} got unexpected event!: {:?}", std::stringify!(node_b), e);
145+
},
146+
};
147+
match nodes[0].wait_next_event() {
148+
ref e @ Event::PaymentSuccessful { payment_hash: hash, fee_paid_msat } => {
149+
println!("{} got event {:?}", std::stringify!(node_b), e);
150+
assert_eq!(hash, payment_hash);
151+
assert_eq!(fee_paid_msat, Some(2000));
152+
nodes[0].event_handled();
153+
},
154+
ref e => {
155+
panic!("{} got unexpected event!: {:?}", std::stringify!(node_b), e);
156+
},
157+
};
138158
}
139159

140160
#[test]

0 commit comments

Comments
 (0)