Skip to main content

fedimint_walletv2_client/
events.rs

1use bitcoin::address::NetworkUnchecked;
2use bitcoin::{Address, Txid};
3use fedimint_core::core::{Account, 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    /// Balance the payment was funded from. Defaulted rather than required, so
15    /// entries written before accounts existed still decode — they can only
16    /// have been the one account there was.
17    #[serde(default = "Account::primary")]
18    pub account: Account,
19}
20
21impl Event for SendPaymentEvent {
22    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
23    const KIND: EventKind = EventKind::from_static("payment-send");
24    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
25}
26
27/// Status of a send (pegout) operation.
28#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
29pub enum SendPaymentStatus {
30    /// The pegout was successful, includes the bitcoin transaction ID.
31    Success(Txid),
32    /// The pegout was aborted.
33    Aborted,
34}
35
36/// Event emitted when a send (pegout) operation reaches a final state.
37#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
38pub struct SendPaymentUpdateEvent {
39    pub operation_id: OperationId,
40    pub status: SendPaymentStatus,
41    /// Balance the operation acts on, repeated from the initiating event so a
42    /// consumer can filter the final state by account without joining on the
43    /// operation id. Defaulted so entries written before accounts existed
44    /// still decode.
45    #[serde(default = "Account::primary")]
46    pub account: Account,
47}
48
49impl Event for SendPaymentUpdateEvent {
50    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
51    const KIND: EventKind = EventKind::from_static("payment-send-update");
52    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
53}
54
55/// Event emitted when a receive (pegin) operation is initiated.
56#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
57pub struct ReceivePaymentEvent {
58    pub operation_id: OperationId,
59    pub value: bitcoin::Amount,
60    pub fee: bitcoin::Amount,
61    pub address: Address<NetworkUnchecked>,
62    pub outpoint: Option<bitcoin::OutPoint>,
63    /// Balance the deposit is credited to. See [`SendPaymentEvent::account`]
64    /// for why it is defaulted.
65    #[serde(default = "Account::primary")]
66    pub account: Account,
67}
68
69impl Event for ReceivePaymentEvent {
70    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
71    const KIND: EventKind = EventKind::from_static("payment-receive");
72    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
73}
74
75/// Status of a receive (pegin) operation.
76#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
77pub enum ReceivePaymentStatus {
78    /// The pegin was successful.
79    Success,
80    /// The pegin was aborted.
81    Aborted,
82}
83
84/// Event emitted when a receive (pegin) operation reaches a final state.
85#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
86pub struct ReceivePaymentUpdateEvent {
87    pub operation_id: OperationId,
88    pub status: ReceivePaymentStatus,
89    /// Balance the operation acts on, repeated from the initiating event so a
90    /// consumer can filter the final state by account without joining on the
91    /// operation id. Defaulted so entries written before accounts existed
92    /// still decode.
93    #[serde(default = "Account::primary")]
94    pub account: Account,
95}
96
97impl Event for ReceivePaymentUpdateEvent {
98    const MODULE: Option<ModuleKind> = Some(fedimint_walletv2_common::KIND);
99    const KIND: EventKind = EventKind::from_static("payment-receive-update");
100    const PERSISTENCE: EventPersistence = EventPersistence::Persistent;
101}