Skip to main content

fedimint_walletv2_client/
events.rs

1use bitcoin::Txid;
2use fedimint_core::core::{ModuleKind, OperationId};
3use fedimint_eventlog::{Event, EventKind, EventPersistence};
4use serde::{Deserialize, Serialize};
5
6/// Event emitted when a peg-out (send to onchain) operation is initiated.
7#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
8pub struct SendPaymentEvent {
9    pub operation_id: OperationId,
10    pub amount: bitcoin::Amount,
11    pub fee: bitcoin::Amount,
12}
13
14impl Event for SendPaymentEvent {
15    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
16    const KIND: EventKind = EventKind::from_static("payment-send");
17    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
18}
19
20/// Status of a send (peg-out) operation.
21#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
22pub enum SendPaymentStatus {
23    /// The peg-out was successful, includes the bitcoin transaction ID.
24    Success(Txid),
25    /// The peg-out was aborted.
26    Aborted,
27}
28
29/// Event emitted when a send (peg-out) operation reaches a final state.
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
31pub struct SendPaymentStatusEvent {
32    pub operation_id: OperationId,
33    pub status: SendPaymentStatus,
34}
35
36impl Event for SendPaymentStatusEvent {
37    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
38    const KIND: EventKind = EventKind::from_static("payment-send-status");
39    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
40}
41
42/// Event emitted when a receive (peg-in) operation is initiated.
43#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
44pub struct ReceivePaymentEvent {
45    pub operation_id: OperationId,
46    pub amount: bitcoin::Amount,
47    pub fee: bitcoin::Amount,
48}
49
50impl Event for ReceivePaymentEvent {
51    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
52    const KIND: EventKind = EventKind::from_static("payment-receive");
53    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
54}
55
56/// Status of a receive (peg-in) operation.
57#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
58pub enum ReceivePaymentStatus {
59    /// The peg-in was successful.
60    Success,
61    /// The peg-in was aborted.
62    Aborted,
63}
64
65/// Event emitted when a receive (peg-in) operation reaches a final state.
66#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
67pub struct ReceivePaymentStatusEvent {
68    pub operation_id: OperationId,
69    pub status: ReceivePaymentStatus,
70}
71
72impl Event for ReceivePaymentStatusEvent {
73    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
74    const KIND: EventKind = EventKind::from_static("payment-receive-status");
75    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
76}