fedimint_lnv2_client/
events.rs

1use fedimint_core::Amount;
2use fedimint_core::core::{ModuleKind, OperationId};
3use fedimint_eventlog::{Event, EventKind, EventPersistence};
4use serde::{Deserialize, Serialize};
5
6/// Event emitted when a send operation is created.
7#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
8pub struct SendPaymentEvent {
9    pub operation_id: OperationId,
10    pub amount: Amount,
11    pub fee: Option<Amount>,
12}
13
14impl Event for SendPaymentEvent {
15    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
16    const KIND: EventKind = EventKind::from_static("payment-send");
17    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
18}
19
20/// Status of a send operation.
21#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
22pub enum SendPaymentStatus {
23    /// The payment was successful, includes the preimage as proof of payment.
24    Success([u8; 32]),
25    /// The payment has been refunded.
26    Refunded,
27}
28
29/// Event emitted when a send operation reaches a final state.
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
31pub struct SendPaymentUpdateEvent {
32    pub operation_id: OperationId,
33    pub status: SendPaymentStatus,
34}
35
36impl Event for SendPaymentUpdateEvent {
37    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
38    const KIND: EventKind = EventKind::from_static("payment-send-update");
39    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
40}
41
42/// Event emitted when a receive operation successfully completes and
43/// transitions to the claiming state.
44#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
45pub struct ReceivePaymentEvent {
46    pub operation_id: OperationId,
47    pub amount: Amount,
48}
49
50impl Event for ReceivePaymentEvent {
51    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
52    const KIND: EventKind = EventKind::from_static("payment-receive");
53    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
54}