Skip to main content

fedimint_mintv2_client/
events.rs

1use fedimint_core::Amount;
2use fedimint_core::core::{Account, ModuleKind, OperationId};
3use fedimint_eventlog::{Event, EventKind, EventPersistence};
4use fedimint_mintv2_common::KIND;
5use serde::{Deserialize, Serialize};
6
7/// Event emitted when e-cash is sent out-of-band.
8/// This is a final event - once e-cash is sent, the operation is complete.
9#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
10pub struct SendPaymentEvent {
11    pub operation_id: OperationId,
12    pub amount: Amount,
13    /// Balance the notes left. Defaulted rather than required, so entries
14    /// written before accounts existed still decode — they can only have been
15    /// the one account there was.
16    #[serde(default = "Account::primary")]
17    pub account: Account,
18    pub ecash: String,
19}
20
21impl Event for SendPaymentEvent {
22    const MODULE: Option<ModuleKind> = Some(KIND);
23    const KIND: EventKind = EventKind::from_static("payment-send");
24    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
25}
26
27/// Event emitted when a receive (reissuance) operation is initiated.
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
29pub struct ReceivePaymentEvent {
30    pub operation_id: OperationId,
31    pub amount: Amount,
32    /// Balance the notes are reissued into. See [`SendPaymentEvent::account`]
33    /// for why it is defaulted.
34    #[serde(default = "Account::primary")]
35    pub account: Account,
36}
37
38impl Event for ReceivePaymentEvent {
39    const MODULE: Option<ModuleKind> = Some(KIND);
40    const KIND: EventKind = EventKind::from_static("payment-receive");
41    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
42}
43
44/// Status of a receive (reissuance) operation.
45#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
46pub enum ReceivePaymentStatus {
47    /// The reissuance was successful.
48    Success,
49    /// The reissuance was rejected.
50    Rejected,
51}
52
53/// Event emitted when a receive (reissuance) operation reaches a final state.
54#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
55pub struct ReceivePaymentUpdateEvent {
56    pub operation_id: OperationId,
57    pub status: ReceivePaymentStatus,
58    /// Balance the operation acts on, repeated from the initiating event so a
59    /// consumer can filter the final state by account without joining on the
60    /// operation id. Defaulted so entries written before accounts existed
61    /// still decode.
62    #[serde(default = "Account::primary")]
63    pub account: Account,
64}
65
66impl Event for ReceivePaymentUpdateEvent {
67    const MODULE: Option<ModuleKind> = Some(KIND);
68    const KIND: EventKind = EventKind::from_static("payment-receive-update");
69    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
70}