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 value: bitcoin::Amount,
49    pub fee: bitcoin::Amount,
50    pub address: Address<NetworkUnchecked>,
51    pub outpoint: Option<bitcoin::OutPoint>,
52}
53
54impl Event for ReceivePaymentEvent {
55    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
56    const KIND: EventKind = EventKind::from_static("payment-receive");
57    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
58}
59
60/// Status of a receive (pegin) operation.
61#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
62pub enum ReceivePaymentStatus {
63    /// The pegin was successful.
64    Success,
65    /// The pegin was aborted.
66    Aborted,
67}
68
69/// Event emitted when a receive (pegin) operation reaches a final state.
70#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
71pub struct ReceivePaymentUpdateEvent {
72    pub operation_id: OperationId,
73    pub status: ReceivePaymentStatus,
74}
75
76impl Event for ReceivePaymentUpdateEvent {
77    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
78    const KIND: EventKind = EventKind::from_static("payment-receive-update");
79    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
80}