fedimint_wallet_client/
events.rs

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