Skip to content

Commit 9e541d0

Browse files
committed
Add PaymentSent, PaymentFailed and PaymentClaimed events
1 parent 4999890 commit 9e541d0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

mutiny-core/src/event.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,15 @@ impl<S: MutinyStorage> EventHandler<S> {
365365
}
366366
}
367367
}
368+
369+
if let Some(cb) = self.ln_event_callback.as_ref() {
370+
let event = CommonLnEvent::PaymentClaimed {
371+
receiver_node_id: receiver_node_id.map(|node_id| format!("{node_id}")),
372+
amount_msat,
373+
payment_hash: format!("{payment_hash:x}"),
374+
};
375+
cb.trigger(event);
376+
}
368377
}
369378
Event::PaymentSent {
370379
payment_preimage,
@@ -406,6 +415,12 @@ impl<S: MutinyStorage> EventHandler<S> {
406415
);
407416
}
408417
}
418+
if let Some(cb) = self.ln_event_callback.as_ref() {
419+
let event = CommonLnEvent::PaymentSent {
420+
payment_hash: format!("{payment_hash:x}"),
421+
};
422+
cb.trigger(event);
423+
}
409424
}
410425
Event::OpenChannelRequest {
411426
temporary_channel_id,
@@ -525,6 +540,13 @@ impl<S: MutinyStorage> EventHandler<S> {
525540
);
526541
}
527542
}
543+
if let Some(cb) = self.ln_event_callback.as_ref() {
544+
let event = CommonLnEvent::PaymentFailed {
545+
payment_hash: format!("{payment_hash:x}"),
546+
reason: reason.map(|r| format!("{r:?}")),
547+
};
548+
cb.trigger(event);
549+
}
528550
}
529551
}
530552
Event::PaymentForwarded { .. } => {

mutiny-core/src/messagehandler.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ pub enum CommonLnEvent {
3939
// this must only be used to report debugging information.
4040
maybe_force_closed: bool,
4141
},
42+
// Sent payment
43+
PaymentSent {
44+
payment_hash: String,
45+
},
46+
// Sent payment failed
47+
PaymentFailed {
48+
payment_hash: String,
49+
reason: Option<String>,
50+
},
51+
// Received payment
52+
PaymentClaimed {
53+
/// The node that received the payment.
54+
receiver_node_id: Option<String>,
55+
/// The payment hash of the payment.
56+
payment_hash: String,
57+
amount_msat: u64,
58+
},
4259
}
4360

4461
#[derive(Clone)]

0 commit comments

Comments
 (0)