use serde::{Deserialize, Serialize};
use thiserror::Error;
use super::{CurrencyUnit, MeltOptions, PublicKey};
#[cfg(feature = "mint")]
use crate::quote_id::QuoteId;
use crate::Amount;
#[derive(Debug, Error)]
pub enum Error {
#[error("Unknown quote state")]
UnknownState,
#[error("Amount Overflow")]
AmountOverflow,
#[error("Publickey not defined")]
PublickeyUndefined,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub struct MintQuoteBolt12Request {
pub amount: Option<Amount>,
pub unit: CurrencyUnit,
pub description: Option<String>,
pub pubkey: PublicKey,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
#[serde(bound = "Q: Serialize + for<'a> Deserialize<'a>")]
pub struct MintQuoteBolt12Response<Q> {
pub quote: Q,
pub request: String,
pub amount: Option<Amount>,
pub unit: CurrencyUnit,
pub expiry: Option<u64>,
pub pubkey: PublicKey,
pub amount_paid: Amount,
pub amount_issued: Amount,
}
#[cfg(feature = "mint")]
impl<Q: ToString> MintQuoteBolt12Response<Q> {
pub fn to_string_id(&self) -> MintQuoteBolt12Response<String> {
MintQuoteBolt12Response {
quote: self.quote.to_string(),
request: self.request.clone(),
amount: self.amount,
unit: self.unit.clone(),
expiry: self.expiry,
pubkey: self.pubkey,
amount_paid: self.amount_paid,
amount_issued: self.amount_issued,
}
}
}
#[cfg(feature = "mint")]
impl From<MintQuoteBolt12Response<QuoteId>> for MintQuoteBolt12Response<String> {
fn from(value: MintQuoteBolt12Response<QuoteId>) -> Self {
Self {
quote: value.quote.to_string(),
request: value.request,
expiry: value.expiry,
amount_paid: value.amount_paid,
amount_issued: value.amount_issued,
pubkey: value.pubkey,
amount: value.amount,
unit: value.unit,
}
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub struct MeltQuoteBolt12Request {
pub request: String,
pub unit: CurrencyUnit,
pub options: Option<MeltOptions>,
}
pub type MeltQuoteBolt12Response<Q> = crate::nuts::nut23::MeltQuoteBolt11Response<Q>;