Skip to main content

fedimint_mint_client/
events.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, or `None` if automatic refund
47    /// is disabled.
48    pub timeout: Option<Duration>,
49
50    /// Boolean that indicates if the invite code was included in the note
51    /// serialization
52    pub include_invite: bool,
53}
54
55impl Event for OOBNotesSpent {
56    const MODULE: Option<ModuleKind> = Some(KIND);
57
58    const KIND: EventKind = EventKind::from_static("oob-notes-spent");
59    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
60}
61
62/// Event that is emitted when out of band ecash is reissued
63#[derive(Serialize, Deserialize)]
64pub struct OOBNotesReissued {
65    /// The amount of out of band ecash being reissued
66    pub amount: Amount,
67}
68
69impl Event for OOBNotesReissued {
70    const MODULE: Option<ModuleKind> = Some(KIND);
71    const KIND: EventKind = EventKind::from_static("oob-notes-reissued");
72    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
73}
74
75/// Event emitted when e-cash is sent out-of-band.
76/// This is a final event - once e-cash is sent, the operation is complete.
77#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
78pub struct SendPaymentEvent {
79    pub operation_id: OperationId,
80    pub amount: Amount,
81    pub oob_notes: String,
82}
83
84impl Event for SendPaymentEvent {
85    const MODULE: Option<ModuleKind> = Some(KIND);
86    const KIND: EventKind = EventKind::from_static("payment-send");
87    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
88}
89
90/// Event emitted when a receive (reissuance) operation is initiated.
91#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
92pub struct ReceivePaymentEvent {
93    pub operation_id: OperationId,
94    pub amount: Amount,
95}
96
97impl Event for ReceivePaymentEvent {
98    const MODULE: Option<ModuleKind> = Some(KIND);
99    const KIND: EventKind = EventKind::from_static("payment-receive");
100    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
101}
102
103/// Status of a receive (reissuance) operation.
104#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
105pub enum ReceivePaymentStatus {
106    /// The reissuance was successful.
107    Success,
108    /// The reissuance was rejected.
109    Rejected,
110}
111
112/// Event emitted when a receive (reissuance) operation reaches a final state.
113#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
114pub struct ReceivePaymentUpdateEvent {
115    pub operation_id: OperationId,
116    pub status: ReceivePaymentStatus,
117}
118
119impl Event for ReceivePaymentUpdateEvent {
120    const MODULE: Option<ModuleKind> = Some(KIND);
121    const KIND: EventKind = EventKind::from_static("payment-receive-update");
122    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
123}