1use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use super::{CurrencyUnit, MeltOptions, PublicKey};
6#[cfg(feature = "mint")]
7use crate::quote_id::QuoteId;
8use crate::Amount;
9
10#[derive(Debug, Error)]
12pub enum Error {
13 #[error("Unknown quote state")]
15 UnknownState,
16 #[error("Amount Overflow")]
18 AmountOverflow,
19 #[error("Publickey not defined")]
21 PublickeyUndefined,
22}
23
24#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
26#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
27pub struct MintQuoteBolt12Request {
28 pub amount: Option<Amount>,
30 pub unit: CurrencyUnit,
32 pub description: Option<String>,
34 pub pubkey: PublicKey,
36}
37
38#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
40#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
41#[serde(bound = "Q: Serialize + for<'a> Deserialize<'a>")]
42pub struct MintQuoteBolt12Response<Q> {
43 pub quote: Q,
45 pub request: String,
47 pub amount: Option<Amount>,
49 pub unit: CurrencyUnit,
51 pub expiry: Option<u64>,
53 pub pubkey: PublicKey,
55 pub amount_paid: Amount,
57 pub amount_issued: Amount,
59}
60
61#[cfg(feature = "mint")]
62impl<Q: ToString> MintQuoteBolt12Response<Q> {
63 pub fn to_string_id(&self) -> MintQuoteBolt12Response<String> {
65 MintQuoteBolt12Response {
66 quote: self.quote.to_string(),
67 request: self.request.clone(),
68 amount: self.amount,
69 unit: self.unit.clone(),
70 expiry: self.expiry,
71 pubkey: self.pubkey,
72 amount_paid: self.amount_paid,
73 amount_issued: self.amount_issued,
74 }
75 }
76}
77
78#[cfg(feature = "mint")]
79impl From<MintQuoteBolt12Response<QuoteId>> for MintQuoteBolt12Response<String> {
80 fn from(value: MintQuoteBolt12Response<QuoteId>) -> Self {
81 Self {
82 quote: value.quote.to_string(),
83 request: value.request,
84 expiry: value.expiry,
85 amount_paid: value.amount_paid,
86 amount_issued: value.amount_issued,
87 pubkey: value.pubkey,
88 amount: value.amount,
89 unit: value.unit,
90 }
91 }
92}
93
94#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
96#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
97pub struct MeltQuoteBolt12Request {
98 pub request: String,
100 pub unit: CurrencyUnit,
102 pub options: Option<MeltOptions>,
104}