ln_gateway/state_machine/
events.rs

1use fedimint_core::core::{ModuleKind, OperationId};
2use fedimint_core::Amount;
3use fedimint_eventlog::{Event, EventKind};
4use fedimint_ln_common::contracts::outgoing::OutgoingContractAccount;
5use fedimint_ln_common::contracts::ContractId;
6use serde::{Deserialize, Serialize};
7
8use super::pay::OutgoingPaymentError;
9
10/// LNv1 event that is emitted when an outgoing payment attempt is initiated.
11#[derive(Serialize, Deserialize)]
12pub struct OutgoingPaymentStarted {
13    /// The contract ID that uniquely identifies the outgoing contract.
14    pub contract_id: ContractId,
15
16    /// The amount of the invoice that is being paid.
17    pub invoice_amount: Amount,
18
19    /// The operation ID of the outgoing payment
20    pub operation_id: OperationId,
21}
22
23impl Event for OutgoingPaymentStarted {
24    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
25
26    const KIND: EventKind = EventKind::from_static("outgoing-payment-started");
27}
28
29/// LNv1 event that is emitted when an outgoing payment attempt has succeeded.
30#[derive(Serialize, Deserialize)]
31pub struct OutgoingPaymentSucceeded {
32    /// LNv1 outgoing contract
33    pub outgoing_contract: OutgoingContractAccount,
34
35    /// The contract ID that uniquely identifies the outgoing contract.
36    pub contract_id: ContractId,
37
38    /// The preimage acquired from successfully paying the invoice.
39    pub preimage: String,
40}
41
42impl Event for OutgoingPaymentSucceeded {
43    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
44
45    const KIND: EventKind = EventKind::from_static("outgoing-payment-succeeded");
46}
47
48/// LNv1 event that is emitted when an outgoing payment attempt has failed.
49#[derive(Serialize, Deserialize)]
50pub struct OutgoingPaymentFailed {
51    /// LNv1 outgoing contract
52    pub outgoing_contract: OutgoingContractAccount,
53
54    /// The contract ID that uniquely identifies the outgoing contract.
55    pub contract_id: ContractId,
56
57    /// The reason the outgoing payment failed.
58    pub error: OutgoingPaymentError,
59}
60
61impl Event for OutgoingPaymentFailed {
62    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
63
64    const KIND: EventKind = EventKind::from_static("outgoing-payment-failed");
65}
66
67/// LNv1 event that is emitted when an incoming payment attempt has started.
68#[derive(Serialize, Deserialize)]
69pub struct IncomingPaymentStarted {
70    /// The contract ID that uniquely identifies the incoming contract.
71    pub contract_id: ContractId,
72
73    /// The payment hash of the invoice that is being paid.
74    pub payment_hash: bitcoin::hashes::sha256::Hash,
75
76    /// The amount specified in the invoice.
77    pub invoice_amount: Amount,
78
79    /// The amount offered in the contract.
80    pub contract_amount: Amount,
81
82    /// The operation ID of the outgoing payment
83    pub operation_id: OperationId,
84}
85
86impl Event for IncomingPaymentStarted {
87    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
88
89    const KIND: EventKind = EventKind::from_static("incoming-payment-started");
90}
91
92/// LNv1 event that is emitted when an incoming payment attempt was successful.
93#[derive(Serialize, Deserialize)]
94pub struct IncomingPaymentSucceeded {
95    /// The payment hash of the invoice that was paid.
96    pub payment_hash: bitcoin::hashes::sha256::Hash,
97
98    /// The decrypted preimage that was acquired from the federation.
99    pub preimage: String,
100}
101
102impl Event for IncomingPaymentSucceeded {
103    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
104
105    const KIND: EventKind = EventKind::from_static("incoming-payment-succeeded");
106}
107
108/// LNv1 event that is emitted when an incoming payment attempt has failed.
109#[derive(Serialize, Deserialize)]
110pub struct IncomingPaymentFailed {
111    /// The payment hash of the invoice that failed to be paid.
112    pub payment_hash: bitcoin::hashes::sha256::Hash,
113
114    /// The reason the incoming payment attempt failed.
115    pub error: String,
116}
117
118impl Event for IncomingPaymentFailed {
119    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
120
121    const KIND: EventKind = EventKind::from_static("incoming-payment-failed");
122}
123
124/// LNv1 event that is emitted when a preimage was successfully revealed to the
125/// Lightning Network.
126#[derive(Serialize, Deserialize)]
127pub struct CompleteLightningPaymentSucceeded {
128    /// The payment hash of the payment.
129    pub payment_hash: bitcoin::hashes::sha256::Hash,
130}
131
132impl Event for CompleteLightningPaymentSucceeded {
133    const MODULE: Option<ModuleKind> = Some(fedimint_ln_common::KIND);
134
135    const KIND: EventKind = EventKind::from_static("complete-lightning-payment-succeeded");
136}