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, MeltQuoteState, MeltRequest, MintQuoteState, Proof, Proofs,
14 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
46#[async_trait]
48pub trait QuotesDatabase {
49 type Err: Into<Error> + From<Error>;
51
52 async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
54 async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
56 async fn update_mint_quote_state(
58 &self,
59 quote_id: &Uuid,
60 state: MintQuoteState,
61 ) -> Result<MintQuoteState, Self::Err>;
62 async fn get_mint_quote_by_request(
64 &self,
65 request: &str,
66 ) -> Result<Option<MintMintQuote>, Self::Err>;
67 async fn get_mint_quote_by_request_lookup_id(
69 &self,
70 request_lookup_id: &str,
71 ) -> Result<Option<MintMintQuote>, Self::Err>;
72 async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
74 async fn get_mint_quotes_with_state(
76 &self,
77 state: MintQuoteState,
78 ) -> Result<Vec<MintMintQuote>, Self::Err>;
79 async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
81
82 async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
84 async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
86 async fn update_melt_quote_state(
88 &self,
89 quote_id: &Uuid,
90 state: MeltQuoteState,
91 ) -> Result<MeltQuoteState, Self::Err>;
92 async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
94 async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
96
97 async fn add_melt_request(
99 &self,
100 melt_request: MeltRequest<Uuid>,
101 ln_key: PaymentProcessorKey,
102 ) -> Result<(), Self::Err>;
103 async fn get_melt_request(
105 &self,
106 quote_id: &Uuid,
107 ) -> Result<Option<(MeltRequest<Uuid>, PaymentProcessorKey)>, Self::Err>;
108}
109
110#[async_trait]
112pub trait ProofsDatabase {
113 type Err: Into<Error> + From<Error>;
115
116 async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
118 async fn remove_proofs(
120 &self,
121 ys: &[PublicKey],
122 quote_id: Option<Uuid>,
123 ) -> Result<(), Self::Err>;
124 async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
126 async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
128 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
130 async fn update_proofs_states(
132 &self,
133 ys: &[PublicKey],
134 proofs_state: State,
135 ) -> Result<Vec<Option<State>>, Self::Err>;
136 async fn get_proofs_by_keyset_id(
138 &self,
139 keyset_id: &Id,
140 ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
141}
142
143#[async_trait]
144pub trait SignaturesDatabase {
146 type Err: Into<Error> + From<Error>;
148
149 async fn add_blind_signatures(
151 &self,
152 blinded_messages: &[PublicKey],
153 blind_signatures: &[BlindSignature],
154 quote_id: Option<Uuid>,
155 ) -> Result<(), Self::Err>;
156 async fn get_blind_signatures(
158 &self,
159 blinded_messages: &[PublicKey],
160 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
161 async fn get_blind_signatures_for_keyset(
163 &self,
164 keyset_id: &Id,
165 ) -> Result<Vec<BlindSignature>, Self::Err>;
166 async fn get_blind_signatures_for_quote(
168 &self,
169 quote_id: &Uuid,
170 ) -> Result<Vec<BlindSignature>, Self::Err>;
171}
172
173#[async_trait]
175pub trait Database<Error>:
176 QuotesDatabase<Err = Error> + ProofsDatabase<Err = Error> + SignaturesDatabase<Err = Error>
177{
178 async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Error>;
180 async fn get_mint_info(&self) -> Result<MintInfo, Error>;
182
183 async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Error>;
185 async fn get_quote_ttl(&self) -> Result<QuoteTTL, Error>;
187}