1use serde::de::DeserializeOwned;
3use serde::{Deserialize, Serialize};
4#[cfg(feature = "mint")]
5use uuid::Uuid;
6
7#[cfg(feature = "mint")]
8use super::PublicKey;
9use crate::nuts::{
10 CurrencyUnit, MeltQuoteBolt11Response, MintQuoteBolt11Response, PaymentMethod, ProofState,
11};
12
13pub mod ws;
14
15#[derive(Debug, Clone, Serialize, Eq, PartialEq, Hash, Deserialize)]
17#[serde(bound = "I: DeserializeOwned + Serialize")]
18pub struct Params<I> {
19 pub kind: Kind,
21 pub filters: Vec<String>,
23 #[serde(rename = "subId")]
25 pub id: I,
26}
27
28#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
30#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
31pub struct SupportedSettings {
32 pub supported: Vec<SupportedMethods>,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
38#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
39pub struct SupportedMethods {
40 pub method: PaymentMethod,
42 pub unit: CurrencyUnit,
44 pub commands: Vec<WsCommand>,
46}
47
48impl SupportedMethods {
49 pub fn new(method: PaymentMethod, unit: CurrencyUnit, commands: Vec<WsCommand>) -> Self {
51 Self {
52 method,
53 unit,
54 commands,
55 }
56 }
57
58 pub fn default_bolt11(unit: CurrencyUnit) -> Self {
60 let commands = vec![
61 WsCommand::Bolt11MintQuote,
62 WsCommand::Bolt11MeltQuote,
63 WsCommand::ProofState,
64 ];
65
66 Self {
67 method: PaymentMethod::Bolt11,
68 unit,
69 commands,
70 }
71 }
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
76#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
77#[serde(rename_all = "snake_case")]
78pub enum WsCommand {
79 #[serde(rename = "bolt11_mint_quote")]
81 Bolt11MintQuote,
82 #[serde(rename = "bolt11_melt_quote")]
84 Bolt11MeltQuote,
85 #[serde(rename = "proof_state")]
87 ProofState,
88}
89
90#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
91#[serde(bound = "T: Serialize + DeserializeOwned")]
92#[serde(untagged)]
93pub enum NotificationPayload<T> {
95 ProofState(ProofState),
97 MeltQuoteBolt11Response(MeltQuoteBolt11Response<T>),
99 MintQuoteBolt11Response(MintQuoteBolt11Response<T>),
101}
102
103impl<T> From<ProofState> for NotificationPayload<T> {
104 fn from(proof_state: ProofState) -> NotificationPayload<T> {
105 NotificationPayload::ProofState(proof_state)
106 }
107}
108
109impl<T> From<MeltQuoteBolt11Response<T>> for NotificationPayload<T> {
110 fn from(melt_quote: MeltQuoteBolt11Response<T>) -> NotificationPayload<T> {
111 NotificationPayload::MeltQuoteBolt11Response(melt_quote)
112 }
113}
114
115impl<T> From<MintQuoteBolt11Response<T>> for NotificationPayload<T> {
116 fn from(mint_quote: MintQuoteBolt11Response<T>) -> NotificationPayload<T> {
117 NotificationPayload::MintQuoteBolt11Response(mint_quote)
118 }
119}
120
121#[cfg(feature = "mint")]
122#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
123pub enum Notification {
125 ProofState(PublicKey),
127 MeltQuoteBolt11(Uuid),
129 MintQuoteBolt11(Uuid),
131}
132
133#[derive(Debug, Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Hash, Serialize, Deserialize)]
135#[serde(rename_all = "snake_case")]
136pub enum Kind {
137 Bolt11MeltQuote,
139 Bolt11MintQuote,
141 ProofState,
143}
144
145impl<I> AsRef<I> for Params<I> {
146 fn as_ref(&self) -> &I {
147 &self.id
148 }
149}
150
151#[derive(thiserror::Error, Debug)]
153pub enum Error {
154 #[cfg(feature = "mint")]
155 #[error("Uuid Error: {0}")]
156 Uuid(#[from] uuid::Error),
158
159 #[error("PublicKey Error: {0}")]
160 PublicKey(#[from] crate::nuts::nut01::Error),
162}