cdk_common/database/mint/
mod.rs1use 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 = "test")]
21pub mod test;
22
23#[cfg(feature = "auth")]
24pub use auth::MintAuthDatabase;
25
26#[async_trait]
28pub trait KeysDatabase {
29 type Err: Into<Error> + From<Error>;
31
32 async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
34 async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
36 async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
38 async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
40 async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
42 async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
44}
45#[async_trait]
47pub trait QuotesDatabase {
48 type Err: Into<Error> + From<Error>;
50
51 async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
53 async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
55 async fn update_mint_quote_state(
57 &self,
58 quote_id: &Uuid,
59 state: MintQuoteState,
60 ) -> Result<MintQuoteState, Self::Err>;
61 async fn get_mint_quote_by_request(
63 &self,
64 request: &str,
65 ) -> Result<Option<MintMintQuote>, Self::Err>;
66 async fn get_mint_quote_by_request_lookup_id(
68 &self,
69 request_lookup_id: &str,
70 ) -> Result<Option<MintMintQuote>, Self::Err>;
71 async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
73 async fn get_mint_quotes_with_state(
75 &self,
76 state: MintQuoteState,
77 ) -> Result<Vec<MintMintQuote>, Self::Err>;
78 async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
80
81 async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
83 async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
85 async fn update_melt_quote_state(
87 &self,
88 quote_id: &Uuid,
89 state: MeltQuoteState,
90 ) -> Result<MeltQuoteState, Self::Err>;
91 async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
93 async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
95
96 async fn add_melt_request(
98 &self,
99 melt_request: MeltBolt11Request<Uuid>,
100 ln_key: PaymentProcessorKey,
101 ) -> Result<(), Self::Err>;
102 async fn get_melt_request(
104 &self,
105 quote_id: &Uuid,
106 ) -> Result<Option<(MeltBolt11Request<Uuid>, PaymentProcessorKey)>, Self::Err>;
107}
108
109#[async_trait]
111pub trait ProofsDatabase {
112 type Err: Into<Error> + From<Error>;
114
115 async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
117 async fn remove_proofs(
119 &self,
120 ys: &[PublicKey],
121 quote_id: Option<Uuid>,
122 ) -> Result<(), Self::Err>;
123 async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
125 async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
127 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
129 async fn update_proofs_states(
131 &self,
132 ys: &[PublicKey],
133 proofs_state: State,
134 ) -> Result<Vec<Option<State>>, Self::Err>;
135 async fn get_proofs_by_keyset_id(
137 &self,
138 keyset_id: &Id,
139 ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
140}
141
142#[async_trait]
143pub trait SignaturesDatabase {
145 type Err: Into<Error> + From<Error>;
147
148 async fn add_blind_signatures(
150 &self,
151 blinded_messages: &[PublicKey],
152 blind_signatures: &[BlindSignature],
153 quote_id: Option<Uuid>,
154 ) -> Result<(), Self::Err>;
155 async fn get_blind_signatures(
157 &self,
158 blinded_messages: &[PublicKey],
159 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
160 async fn get_blind_signatures_for_keyset(
162 &self,
163 keyset_id: &Id,
164 ) -> Result<Vec<BlindSignature>, Self::Err>;
165 async fn get_blind_signatures_for_quote(
167 &self,
168 quote_id: &Uuid,
169 ) -> Result<Vec<BlindSignature>, Self::Err>;
170}
171
172#[async_trait]
174pub trait Database<Error>:
175 KeysDatabase<Err = Error>
176 + QuotesDatabase<Err = Error>
177 + ProofsDatabase<Err = Error>
178 + SignaturesDatabase<Err = Error>
179{
180 async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Error>;
182 async fn get_mint_info(&self) -> Result<MintInfo, Error>;
184
185 async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Error>;
187 async fn get_quote_ttl(&self) -> Result<QuoteTTL, Error>;
189}