//! Websocket types and functions for the CDK. //! //! This module extends the `cashu` crate with types and functions for the CDK, using the correct //! expected ID types. #[cfg(feature = "mint")] use cashu::nut17::ws::JSON_RPC_VERSION; use cashu::nut17::{self}; #[cfg(feature = "mint")] use cashu::NotificationPayload; #[cfg(feature = "mint")] use uuid::Uuid; use crate::pub_sub::SubId; pub type WsUnsubscribeRequest = nut17::ws::WsUnsubscribeRequest; pub type WsNotification = nut17::ws::WsNotification; pub type WsSubscribeResponse = nut17::ws::WsSubscribeResponse; pub type WsResponseResult = nut17::ws::WsResponseResult; pub type WsUnsubscribeResponse = nut17::ws::WsUnsubscribeResponse; pub type WsRequest = nut17::ws::WsRequest; pub type WsResponse = nut17::ws::WsResponse; pub type WsMethodRequest = nut17::ws::WsMethodRequest; pub type WsErrorBody = nut17::ws::WsErrorBody; pub type WsMessageOrResponse = nut17::ws::WsMessageOrResponse; pub type NotificationInner = nut17::ws::NotificationInner; #[cfg(feature = "mint")] pub fn notification_uuid_to_notification_string( notification: NotificationInner, ) -> NotificationInner { nut17::ws::NotificationInner { sub_id: notification.sub_id, payload: match notification.payload { NotificationPayload::ProofState(pk) => NotificationPayload::ProofState(pk), NotificationPayload::MeltQuoteBolt11Response(quote) => { NotificationPayload::MeltQuoteBolt11Response(quote.to_string_id()) } NotificationPayload::MintQuoteBolt11Response(quote) => { NotificationPayload::MintQuoteBolt11Response(quote.to_string_id()) } }, } } #[cfg(feature = "mint")] pub fn notification_to_ws_message(notification: NotificationInner) -> WsMessageOrResponse { nut17::ws::WsMessageOrResponse::Notification(nut17::ws::WsNotification { jsonrpc: JSON_RPC_VERSION.to_owned(), method: "subscribe".to_string(), params: notification_uuid_to_notification_string(notification), }) }