diff --git a/crates/cashu/src/nuts/nut17/mod.rs b/crates/cashu/src/nuts/nut17/mod.rs index 33e11e21..10bde715 100644 --- a/crates/cashu/src/nuts/nut17/mod.rs +++ b/crates/cashu/src/nuts/nut17/mod.rs @@ -42,32 +42,49 @@ pub struct SupportedMethods { /// Unit pub unit: CurrencyUnit, /// Command - pub commands: Vec, + pub commands: Vec, } impl SupportedMethods { /// Create [`SupportedMethods`] - pub fn new(method: PaymentMethod, unit: CurrencyUnit) -> Self { + pub fn new(method: PaymentMethod, unit: CurrencyUnit, commands: Vec) -> Self { Self { method, unit, - commands: Vec::new(), + commands, + } + } + + /// Create [`SupportedMethods`] for Bolt11 with all supported commands + pub fn default_bolt11(unit: CurrencyUnit) -> Self { + let commands = vec![ + WsCommand::Bolt11MintQuote, + WsCommand::Bolt11MeltQuote, + WsCommand::ProofState, + ]; + + Self { + method: PaymentMethod::Bolt11, + unit, + commands, } } } -impl Default for SupportedMethods { - fn default() -> Self { - SupportedMethods { - method: PaymentMethod::Bolt11, - unit: CurrencyUnit::Sat, - commands: vec![ - "bolt11_mint_quote".to_owned(), - "bolt11_melt_quote".to_owned(), - "proof_state".to_owned(), - ], - } - } +/// WebSocket commands supported by the Cashu mint +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))] +#[serde(rename_all = "snake_case")] +pub enum WsCommand { + /// Command to request a Lightning invoice for minting tokens + #[serde(rename = "bolt11_mint_quote")] + Bolt11MintQuote, + /// Command to request a Lightning payment for melting tokens + #[serde(rename = "bolt11_melt_quote")] + Bolt11MeltQuote, + /// Command to check the state of a proof + #[serde(rename = "proof_state")] + ProofState, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index ab67e434..6bceb4b1 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -209,7 +209,7 @@ async fn main() -> anyhow::Result<()> { mint_builder = mint_builder.set_unit_fee(&CurrencyUnit::Sat, input_fee)?; } - let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + let nut17_supported = SupportedMethods::default_bolt11(CurrencyUnit::Sat); mint_builder = mint_builder.add_supported_websockets(nut17_supported); } @@ -232,7 +232,7 @@ async fn main() -> anyhow::Result<()> { mint_builder = mint_builder.set_unit_fee(&CurrencyUnit::Sat, input_fee)?; } - let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + let nut17_supported = SupportedMethods::default_bolt11(CurrencyUnit::Sat); mint_builder = mint_builder.add_supported_websockets(nut17_supported); } @@ -255,7 +255,7 @@ async fn main() -> anyhow::Result<()> { mint_builder = mint_builder.set_unit_fee(&CurrencyUnit::Sat, input_fee)?; } - let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + let nut17_supported = SupportedMethods::default_bolt11(CurrencyUnit::Sat); mint_builder = mint_builder.add_supported_websockets(nut17_supported); } @@ -284,7 +284,7 @@ async fn main() -> anyhow::Result<()> { mint_builder = mint_builder.set_unit_fee(&unit, input_fee)?; } - let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, unit); + let nut17_supported = SupportedMethods::default_bolt11(unit); mint_builder = mint_builder.add_supported_websockets(nut17_supported); } @@ -323,7 +323,7 @@ async fn main() -> anyhow::Result<()> { mint_builder = mint_builder.set_unit_fee(&unit, input_fee)?; } - let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, unit); + let nut17_supported = SupportedMethods::default_bolt11(unit); mint_builder = mint_builder.add_supported_websockets(nut17_supported); } }