Skip to main content

cdk_common/wallet/saga/
receive.rs

1//! Receive saga types
2
3use cashu::BlindedMessage;
4use serde::{Deserialize, Serialize};
5
6use crate::{Amount, Error};
7
8/// States specific to receive saga
9#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum ReceiveSagaState {
12    /// Input proofs validated and stored as pending, ready to swap for new proofs
13    ProofsPending,
14    /// Swap request sent to mint, awaiting signatures for new proofs
15    SwapRequested,
16}
17
18impl std::fmt::Display for ReceiveSagaState {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            ReceiveSagaState::ProofsPending => write!(f, "proofs_pending"),
22            ReceiveSagaState::SwapRequested => write!(f, "swap_requested"),
23        }
24    }
25}
26
27impl std::str::FromStr for ReceiveSagaState {
28    type Err = Error;
29    fn from_str(s: &str) -> Result<Self, Self::Err> {
30        match s {
31            "proofs_pending" => Ok(ReceiveSagaState::ProofsPending),
32            "swap_requested" => Ok(ReceiveSagaState::SwapRequested),
33            _ => Err(Error::InvalidOperationState),
34        }
35    }
36}
37
38/// Operation-specific data for Receive operations
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct ReceiveOperationData {
41    /// Token to receive
42    pub token: Option<String>,
43    /// Derivation counter start
44    pub counter_start: Option<u32>,
45    /// Derivation counter end
46    pub counter_end: Option<u32>,
47    /// Amount received
48    pub amount: Option<Amount>,
49    /// Blinded messages for recovery
50    ///
51    /// Stored so that if a crash occurs after the mint accepts the swap,
52    /// we can use these to query the mint for signatures and reconstruct proofs.
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    pub blinded_messages: Option<Vec<BlindedMessage>>,
55}