ln_gateway/gateway_module_v2/
events.rs

1use std::time::SystemTime;
2
3use fedimint_core::config::FederationId;
4use fedimint_core::core::ModuleKind;
5use fedimint_core::Amount;
6use fedimint_eventlog::{Event, EventKind};
7use fedimint_lnv2_common::contracts::{Commitment, OutgoingContract, PaymentImage};
8use serde::{Deserialize, Serialize};
9use serde_millis;
10
11use super::send_sm::Cancelled;
12
13/// Event that is emitted when an outgoing payment attempt is initiated.
14#[derive(Serialize, Deserialize)]
15pub struct OutgoingPaymentStarted {
16    /// The timestamp that the operation begins, including the API calls to the
17    /// federation to get the consensus block height.
18    #[serde(with = "serde_millis")]
19    pub operation_start: SystemTime,
20
21    /// The outgoing contract for this payment.
22    pub outgoing_contract: OutgoingContract,
23
24    /// The minimum amount that must be escrowed for the payment (includes the
25    /// gateway's fee)
26    pub min_contract_amount: Amount,
27
28    /// The amount requested in the invoice.
29    pub invoice_amount: Amount,
30
31    /// The max delay of the payment in blocks.
32    pub max_delay: u64,
33}
34
35impl Event for OutgoingPaymentStarted {
36    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
37
38    const KIND: EventKind = EventKind::from_static("outgoing-payment-started");
39}
40
41/// Event that is emitted when an outgoing payment attempt has succeeded.
42#[derive(Serialize, Deserialize)]
43pub struct OutgoingPaymentSucceeded {
44    /// The payment image of the invoice that was paid.
45    pub payment_image: PaymentImage,
46
47    /// The target federation ID if a swap was performed, otherwise `None`.
48    pub target_federation: Option<FederationId>,
49}
50
51impl Event for OutgoingPaymentSucceeded {
52    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
53
54    const KIND: EventKind = EventKind::from_static("outgoing-payment-succeeded");
55}
56
57/// Event that is emitted when an outgoing payment attempt has failed.
58#[derive(Serialize, Deserialize)]
59pub struct OutgoingPaymentFailed {
60    /// The payment image of the invoice that failed.
61    pub payment_image: PaymentImage,
62
63    /// The reason the outgoing payment was cancelled.
64    pub error: Cancelled,
65}
66
67impl Event for OutgoingPaymentFailed {
68    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
69
70    const KIND: EventKind = EventKind::from_static("outgoing-payment-failed");
71}
72
73/// Event that is emitted when an incoming payment attempt has started. Includes
74/// both internal swaps and outside LN payments.
75#[derive(Serialize, Deserialize)]
76pub struct IncomingPaymentStarted {
77    /// The timestamp that the operation begins, including any metadata checks
78    /// before the state machine has spawned.
79    #[serde(with = "serde_millis")]
80    pub operation_start: SystemTime,
81
82    /// The commitment for the incoming contract.
83    pub incoming_contract_commitment: Commitment,
84
85    /// The amount requested in the invoice.
86    pub invoice_amount: Amount,
87}
88
89impl Event for IncomingPaymentStarted {
90    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
91
92    const KIND: EventKind = EventKind::from_static("incoming-payment-started");
93}
94
95/// Event that is emitted when an incoming payment attempt has succeeded.
96/// Includes both internal swaps and outside LN payments.
97#[derive(Serialize, Deserialize)]
98pub struct IncomingPaymentSucceeded {
99    /// The payment image of the invoice that was paid.
100    pub payment_image: PaymentImage,
101}
102
103impl Event for IncomingPaymentSucceeded {
104    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
105
106    const KIND: EventKind = EventKind::from_static("incoming-payment-succeeded");
107}
108
109/// Event that is emitted when an incoming payment attempt has failed.
110#[derive(Serialize, Deserialize)]
111pub struct IncomingPaymentFailed {
112    /// The payment image of the invoice that failed
113    pub payment_image: PaymentImage,
114
115    /// The reason the incoming payment failed
116    pub error: String,
117}
118
119impl Event for IncomingPaymentFailed {
120    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
121
122    const KIND: EventKind = EventKind::from_static("incoming-payment-failed");
123}
124
125/// Event that is emitted when a preimage is revealed to the Lightning network.
126/// Only emitted for payments that are received from an external Lightning node,
127/// not internal swaps.
128#[derive(Serialize, Deserialize)]
129pub struct CompleteLightningPaymentSucceeded {
130    /// The payment image of the invoice that was paid.
131    pub payment_image: PaymentImage,
132}
133
134impl Event for CompleteLightningPaymentSucceeded {
135    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
136
137    const KIND: EventKind = EventKind::from_static("complete-lightning-payment-succeeded");
138}