Skip to main content

fedimint_walletv2_client/
events.rs

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