Skip to main content

cdk_common/wallet/saga/
melt.rs

1//! Melt saga types
2
3use cashu::BlindedMessage;
4use serde::{Deserialize, Serialize};
5
6use crate::{Amount, Error};
7
8/// States specific to melt saga
9#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum MeltSagaState {
12    /// Proofs reserved and quote locked, ready to initiate payment
13    ProofsReserved,
14    /// Melt request sent to mint, Lightning payment initiated
15    MeltRequested,
16    /// Lightning payment in progress, awaiting confirmation from network
17    PaymentPending,
18}
19
20impl std::fmt::Display for MeltSagaState {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            MeltSagaState::ProofsReserved => write!(f, "proofs_reserved"),
24            MeltSagaState::MeltRequested => write!(f, "melt_requested"),
25            MeltSagaState::PaymentPending => write!(f, "payment_pending"),
26        }
27    }
28}
29
30impl std::str::FromStr for MeltSagaState {
31    type Err = Error;
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s {
34            "proofs_reserved" => Ok(MeltSagaState::ProofsReserved),
35            "melt_requested" => Ok(MeltSagaState::MeltRequested),
36            "payment_pending" => Ok(MeltSagaState::PaymentPending),
37            _ => Err(Error::InvalidOperationState),
38        }
39    }
40}
41
42/// Operation-specific data for Melt operations
43#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44pub struct MeltOperationData {
45    /// Quote ID
46    pub quote_id: String,
47    /// Amount to melt
48    pub amount: Amount,
49    /// Fee reserve
50    pub fee_reserve: Amount,
51    /// Derivation counter start
52    pub counter_start: Option<u32>,
53    /// Derivation counter end
54    pub counter_end: Option<u32>,
55    /// Change amount (if any)
56    pub change_amount: Option<Amount>,
57    /// Blinded messages for change recovery
58    ///
59    /// Stored so that if a crash occurs after the mint accepts the melt,
60    /// we can use these to query the mint for change signatures and reconstruct proofs.
61    #[serde(default, skip_serializing_if = "Option::is_none")]
62    pub change_blinded_messages: Option<Vec<BlindedMessage>>,
63}