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<String>,
46}
47
48impl SupportedMethods {
49 pub fn new(method: PaymentMethod, unit: CurrencyUnit) -> Self {
51 Self {
52 method,
53 unit,
54 commands: Vec::new(),
55 }
56 }
57}
58
59impl Default for SupportedMethods {
60 fn default() -> Self {
61 SupportedMethods {
62 method: PaymentMethod::Bolt11,
63 unit: CurrencyUnit::Sat,
64 commands: vec![
65 "bolt11_mint_quote".to_owned(),
66 "bolt11_melt_quote".to_owned(),
67 "proof_state".to_owned(),
68 ],
69 }
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
74#[serde(bound = "T: Serialize + DeserializeOwned")]
75#[serde(untagged)]
76pub enum NotificationPayload<T> {
78 ProofState(ProofState),
80 MeltQuoteBolt11Response(MeltQuoteBolt11Response<T>),
82 MintQuoteBolt11Response(MintQuoteBolt11Response<T>),
84}
85
86impl<T> From<ProofState> for NotificationPayload<T> {
87 fn from(proof_state: ProofState) -> NotificationPayload<T> {
88 NotificationPayload::ProofState(proof_state)
89 }
90}
91
92impl<T> From<MeltQuoteBolt11Response<T>> for NotificationPayload<T> {
93 fn from(melt_quote: MeltQuoteBolt11Response<T>) -> NotificationPayload<T> {
94 NotificationPayload::MeltQuoteBolt11Response(melt_quote)
95 }
96}
97
98impl<T> From<MintQuoteBolt11Response<T>> for NotificationPayload<T> {
99 fn from(mint_quote: MintQuoteBolt11Response<T>) -> NotificationPayload<T> {
100 NotificationPayload::MintQuoteBolt11Response(mint_quote)
101 }
102}
103
104#[cfg(feature = "mint")]
105#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
106pub enum Notification {
108 ProofState(PublicKey),
110 MeltQuoteBolt11(Uuid),
112 MintQuoteBolt11(Uuid),
114}
115
116#[derive(Debug, Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Hash, Serialize, Deserialize)]
118#[serde(rename_all = "snake_case")]
119pub enum Kind {
120 Bolt11MeltQuote,
122 Bolt11MintQuote,
124 ProofState,
126}
127
128impl<I> AsRef<I> for Params<I> {
129 fn as_ref(&self) -> &I {
130 &self.id
131 }
132}
133
134#[derive(thiserror::Error, Debug)]
136pub enum Error {
137 #[cfg(feature = "mint")]
138 #[error("Uuid Error: {0}")]
139 Uuid(#[from] uuid::Error),
141
142 #[error("PublicKey Error: {0}")]
143 PublicKey(#[from] crate::nuts::nut01::Error),
145}