Skip to main content

fedimint_lnv2_client/
events.rs

1use fedimint_core::Amount;
2use fedimint_core::core::{Account, 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: Amount,
12    /// Balance the contract was funded from. Defaulted rather than required,
13    /// so entries written before accounts existed still decode — they can only
14    /// have been the one account there was.
15    #[serde(default = "Account::primary")]
16    pub account: Account,
17}
18
19impl Event for SendPaymentEvent {
20    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
21    const KIND: EventKind = EventKind::from_static("payment-send");
22    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
23}
24
25/// Status of a send operation.
26#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
27pub enum SendPaymentStatus {
28    /// The payment was successful, includes the preimage as proof of payment.
29    Success([u8; 32]),
30    /// The payment has been refunded.
31    Refunded,
32}
33
34/// Event emitted when a send operation reaches a final state.
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
36pub struct SendPaymentUpdateEvent {
37    pub operation_id: OperationId,
38    pub status: SendPaymentStatus,
39    /// Balance the operation acts on, repeated from the initiating event so a
40    /// consumer can filter the final state by account without joining on the
41    /// operation id. Defaulted so entries written before accounts existed
42    /// still decode.
43    #[serde(default = "Account::primary")]
44    pub account: Account,
45}
46
47impl Event for SendPaymentUpdateEvent {
48    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
49    const KIND: EventKind = EventKind::from_static("payment-send-update");
50    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
51}
52
53/// Event emitted when a receive operation successfully completes and
54/// transitions to the claiming state.
55#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
56pub struct ReceivePaymentEvent {
57    pub operation_id: OperationId,
58    pub amount: Amount,
59    /// Absolute fee paid to the gateway. Defaults to zero for events recorded
60    /// before this field was added.
61    #[serde(default)]
62    pub fee: Amount,
63    /// Balance the claimed contract is credited to. See
64    /// [`SendPaymentEvent::account`] for why it is defaulted.
65    #[serde(default = "Account::primary")]
66    pub account: Account,
67}
68
69impl Event for ReceivePaymentEvent {
70    const MODULE: Option<ModuleKind> = Some(fedimint_lnv2_common::KIND);
71    const KIND: EventKind = EventKind::from_static("payment-receive");
72    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
73}