cdk_common/database/mint/
mod.rs

1//! CDK Database
2
3use std::collections::HashMap;
4
5use async_trait::async_trait;
6use cashu::MintInfo;
7use uuid::Uuid;
8
9use super::Error;
10use crate::common::{PaymentProcessorKey, QuoteTTL};
11use crate::mint::{self, MintKeySetInfo, MintQuote as MintMintQuote};
12use crate::nuts::{
13    BlindSignature, CurrencyUnit, Id, MeltBolt11Request, MeltQuoteState, MintQuoteState, Proof,
14    Proofs, PublicKey, State,
15};
16
17#[cfg(feature = "auth")]
18mod auth;
19
20#[cfg(feature = "auth")]
21pub use auth::MintAuthDatabase;
22
23/// Mint Database trait
24#[async_trait]
25pub trait Database {
26    /// Mint Database Error
27    type Err: Into<Error> + From<Error>;
28
29    /// Add Active Keyset
30    async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
31    /// Get Active Keyset
32    async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
33    /// Get all Active Keyset
34    async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
35
36    /// Add [`MintMintQuote`]
37    async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
38    /// Get [`MintMintQuote`]
39    async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
40    /// Update state of [`MintMintQuote`]
41    async fn update_mint_quote_state(
42        &self,
43        quote_id: &Uuid,
44        state: MintQuoteState,
45    ) -> Result<MintQuoteState, Self::Err>;
46    /// Get all [`MintMintQuote`]s
47    async fn get_mint_quote_by_request(
48        &self,
49        request: &str,
50    ) -> Result<Option<MintMintQuote>, Self::Err>;
51    /// Get all [`MintMintQuote`]s
52    async fn get_mint_quote_by_request_lookup_id(
53        &self,
54        request_lookup_id: &str,
55    ) -> Result<Option<MintMintQuote>, Self::Err>;
56    /// Get Mint Quotes
57    async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
58    /// Get Mint Quotes with state
59    async fn get_mint_quotes_with_state(
60        &self,
61        state: MintQuoteState,
62    ) -> Result<Vec<MintMintQuote>, Self::Err>;
63    /// Remove [`MintMintQuote`]
64    async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
65
66    /// Add [`mint::MeltQuote`]
67    async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
68    /// Get [`mint::MeltQuote`]
69    async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
70    /// Update [`mint::MeltQuote`] state
71    async fn update_melt_quote_state(
72        &self,
73        quote_id: &Uuid,
74        state: MeltQuoteState,
75    ) -> Result<MeltQuoteState, Self::Err>;
76    /// Get all [`mint::MeltQuote`]s
77    async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
78    /// Remove [`mint::MeltQuote`]
79    async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
80
81    /// Add melt request
82    async fn add_melt_request(
83        &self,
84        melt_request: MeltBolt11Request<Uuid>,
85        ln_key: PaymentProcessorKey,
86    ) -> Result<(), Self::Err>;
87    /// Get melt request
88    async fn get_melt_request(
89        &self,
90        quote_id: &Uuid,
91    ) -> Result<Option<(MeltBolt11Request<Uuid>, PaymentProcessorKey)>, Self::Err>;
92
93    /// Add [`MintKeySetInfo`]
94    async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
95    /// Get [`MintKeySetInfo`]
96    async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
97    /// Get [`MintKeySetInfo`]s
98    async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
99
100    /// Add  [`Proofs`]
101    async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
102    /// Remove [`Proofs`]
103    async fn remove_proofs(
104        &self,
105        ys: &[PublicKey],
106        quote_id: Option<Uuid>,
107    ) -> Result<(), Self::Err>;
108    /// Get [`Proofs`] by ys
109    async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
110    /// Get ys by quote id
111    async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
112    /// Get [`Proofs`] state
113    async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
114    /// Get [`Proofs`] state
115    async fn update_proofs_states(
116        &self,
117        ys: &[PublicKey],
118        proofs_state: State,
119    ) -> Result<Vec<Option<State>>, Self::Err>;
120    /// Get [`Proofs`] by state
121    async fn get_proofs_by_keyset_id(
122        &self,
123        keyset_id: &Id,
124    ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
125
126    /// Add [`BlindSignature`]
127    async fn add_blind_signatures(
128        &self,
129        blinded_messages: &[PublicKey],
130        blind_signatures: &[BlindSignature],
131        quote_id: Option<Uuid>,
132    ) -> Result<(), Self::Err>;
133    /// Get [`BlindSignature`]s
134    async fn get_blind_signatures(
135        &self,
136        blinded_messages: &[PublicKey],
137    ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
138    /// Get [`BlindSignature`]s for keyset_id
139    async fn get_blind_signatures_for_keyset(
140        &self,
141        keyset_id: &Id,
142    ) -> Result<Vec<BlindSignature>, Self::Err>;
143    /// Get [`BlindSignature`]s for quote
144    async fn get_blind_signatures_for_quote(
145        &self,
146        quote_id: &Uuid,
147    ) -> Result<Vec<BlindSignature>, Self::Err>;
148
149    /// Set [`MintInfo`]
150    async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Self::Err>;
151    /// Get [`MintInfo`]
152    async fn get_mint_info(&self) -> Result<MintInfo, Self::Err>;
153
154    /// Set [`QuoteTTL`]
155    async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Self::Err>;
156    /// Get [`QuoteTTL`]
157    async fn get_quote_ttl(&self) -> Result<QuoteTTL, Self::Err>;
158}