Skip to main content

cdk_common/wallet/saga/
issue.rs

1//! Issue (mint) saga types
2
3use cashu::BlindedMessage;
4use serde::{Deserialize, Serialize};
5
6use crate::Error;
7
8/// States specific to mint (issue) saga
9#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum IssueSagaState {
12    /// Pre-mint secrets created and counter incremented, ready to request signatures
13    SecretsPrepared,
14    /// Mint request sent to mint, awaiting signatures for new proofs
15    MintRequested,
16}
17
18impl std::fmt::Display for IssueSagaState {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            IssueSagaState::SecretsPrepared => write!(f, "secrets_prepared"),
22            IssueSagaState::MintRequested => write!(f, "mint_requested"),
23        }
24    }
25}
26
27impl std::str::FromStr for IssueSagaState {
28    type Err = Error;
29    fn from_str(s: &str) -> Result<Self, Self::Err> {
30        match s {
31            "secrets_prepared" => Ok(IssueSagaState::SecretsPrepared),
32            "mint_requested" => Ok(IssueSagaState::MintRequested),
33            _ => Err(Error::InvalidOperationState),
34        }
35    }
36}
37
38/// Operation-specific data for Mint operations
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct MintOperationData {
41    /// Quote ID
42    pub quote_id: String,
43    /// Amount to mint
44    pub amount: crate::Amount,
45    /// Derivation counter start
46    pub counter_start: Option<u32>,
47    /// Derivation counter end
48    pub counter_end: Option<u32>,
49    /// Blinded messages for recovery
50    ///
51    /// Stored so that if a crash occurs after the mint accepts the request,
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}