fedimint_mint_client/
event.rs

1use std::time::Duration;
2
3use fedimint_core::Amount;
4use fedimint_core::core::{ModuleKind, OperationId};
5use fedimint_eventlog::{Event, EventKind, EventPersistence};
6use fedimint_mint_common::{KIND, Nonce};
7use serde::{Deserialize, Serialize};
8
9/// Event that is emitted when a note is created.
10#[derive(Clone, Copy, Serialize, Deserialize)]
11pub struct NoteCreated {
12    /// The nonce of the note
13    pub nonce: Nonce,
14}
15
16impl Event for NoteCreated {
17    const MODULE: Option<ModuleKind> = Some(KIND);
18
19    const KIND: EventKind = EventKind::from_static("note-created");
20    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
21}
22
23/// Event that is emitted when a note is spent.
24#[derive(Clone, Copy, Serialize, Deserialize)]
25pub struct NoteSpent {
26    /// The nonce of the note
27    pub nonce: Nonce,
28}
29
30impl Event for NoteSpent {
31    const MODULE: Option<ModuleKind> = Some(KIND);
32
33    const KIND: EventKind = EventKind::from_static("note-spent");
34    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
35}
36
37/// Event that is emitted when ecash is spent out of band
38#[derive(Serialize, Deserialize)]
39pub struct OOBNotesSpent {
40    /// The requested amount to spend out of band
41    pub requested_amount: Amount,
42
43    /// The actual amount of ecash spent
44    pub spent_amount: Amount,
45
46    /// The timeout before attempting to refund
47    pub timeout: Duration,
48
49    /// Boolean that indicates if the invite code was included in the note
50    /// serialization
51    pub include_invite: bool,
52}
53
54impl Event for OOBNotesSpent {
55    const MODULE: Option<ModuleKind> = Some(KIND);
56
57    const KIND: EventKind = EventKind::from_static("oob-notes-spent");
58    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
59}
60
61/// Event that is emitted when out of band ecash is reissued
62#[derive(Serialize, Deserialize)]
63pub struct OOBNotesReissued {
64    /// The amount of out of band ecash being reissued
65    pub amount: Amount,
66}
67
68impl Event for OOBNotesReissued {
69    const MODULE: Option<ModuleKind> = Some(KIND);
70    const KIND: EventKind = EventKind::from_static("oob-notes-reissued");
71    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
72}
73
74/// Event that is emitted when ecash is reissued as part of a recovery process
75#[derive(Serialize, Deserialize)]
76pub struct RecoveryReissuanceStarted {
77    /// The amount of ecash that was recovered and is being reissued
78    pub amount: Amount,
79    /// The operation id of the recovery process
80    pub operation_id: OperationId,
81}
82
83impl Event for RecoveryReissuanceStarted {
84    const MODULE: Option<ModuleKind> = Some(KIND);
85    const KIND: EventKind = EventKind::from_static("recovered-notes-reissued");
86    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
87}
88
89/// Event emitted when e-cash is sent out-of-band.
90/// This is a final event - once e-cash is sent, the operation is complete.
91#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
92pub struct SendPaymentEvent {
93    pub operation_id: OperationId,
94    pub amount: Amount,
95    pub oob_notes: String,
96}
97
98impl Event for SendPaymentEvent {
99    const MODULE: Option<ModuleKind> = Some(KIND);
100    const KIND: EventKind = EventKind::from_static("payment-send");
101    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
102}
103
104/// Event emitted when a receive (reissuance) operation is initiated.
105#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
106pub struct ReceivePaymentEvent {
107    pub operation_id: OperationId,
108    pub amount: Amount,
109}
110
111impl Event for ReceivePaymentEvent {
112    const MODULE: Option<ModuleKind> = Some(KIND);
113    const KIND: EventKind = EventKind::from_static("payment-receive");
114    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
115}
116
117/// Status of a receive (reissuance) operation.
118#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
119pub enum ReceivePaymentStatus {
120    /// The reissuance was successful.
121    Success,
122    /// The reissuance was rejected.
123    Rejected,
124}
125
126/// Event emitted when a receive (reissuance) operation reaches a final state.
127#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
128pub struct ReceivePaymentUpdateEvent {
129    pub operation_id: OperationId,
130    pub status: ReceivePaymentStatus,
131}
132
133impl Event for ReceivePaymentUpdateEvent {
134    const MODULE: Option<ModuleKind> = Some(KIND);
135    const KIND: EventKind = EventKind::from_static("payment-receive-update");
136    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
137}