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 = "auth")]
21pub use auth::MintAuthDatabase;
22
23#[async_trait]
25pub trait KeysDatabase {
26 type Err: Into<Error> + From<Error>;
28
29 async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
31 async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
33 async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
35 async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
37 async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
39 async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
41}
42#[async_trait]
44pub trait QuotesDatabase {
45 type Err: Into<Error> + From<Error>;
47
48 async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
50 async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
52 async fn update_mint_quote_state(
54 &self,
55 quote_id: &Uuid,
56 state: MintQuoteState,
57 ) -> Result<MintQuoteState, Self::Err>;
58 async fn get_mint_quote_by_request(
60 &self,
61 request: &str,
62 ) -> Result<Option<MintMintQuote>, Self::Err>;
63 async fn get_mint_quote_by_request_lookup_id(
65 &self,
66 request_lookup_id: &str,
67 ) -> Result<Option<MintMintQuote>, Self::Err>;
68 async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
70 async fn get_mint_quotes_with_state(
72 &self,
73 state: MintQuoteState,
74 ) -> Result<Vec<MintMintQuote>, Self::Err>;
75 async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
77
78 async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
80 async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
82 async fn update_melt_quote_state(
84 &self,
85 quote_id: &Uuid,
86 state: MeltQuoteState,
87 ) -> Result<MeltQuoteState, Self::Err>;
88 async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
90 async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
92
93 async fn add_melt_request(
95 &self,
96 melt_request: MeltBolt11Request<Uuid>,
97 ln_key: PaymentProcessorKey,
98 ) -> Result<(), Self::Err>;
99 async fn get_melt_request(
101 &self,
102 quote_id: &Uuid,
103 ) -> Result<Option<(MeltBolt11Request<Uuid>, PaymentProcessorKey)>, Self::Err>;
104}
105
106#[async_trait]
108pub trait ProofsDatabase {
109 type Err: Into<Error> + From<Error>;
111
112 async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
114 async fn remove_proofs(
116 &self,
117 ys: &[PublicKey],
118 quote_id: Option<Uuid>,
119 ) -> Result<(), Self::Err>;
120 async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
122 async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
124 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
126 async fn update_proofs_states(
128 &self,
129 ys: &[PublicKey],
130 proofs_state: State,
131 ) -> Result<Vec<Option<State>>, Self::Err>;
132 async fn get_proofs_by_keyset_id(
134 &self,
135 keyset_id: &Id,
136 ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
137}
138
139#[async_trait]
140pub trait SignaturesDatabase {
142 type Err: Into<Error> + From<Error>;
144
145 async fn add_blind_signatures(
147 &self,
148 blinded_messages: &[PublicKey],
149 blind_signatures: &[BlindSignature],
150 quote_id: Option<Uuid>,
151 ) -> Result<(), Self::Err>;
152 async fn get_blind_signatures(
154 &self,
155 blinded_messages: &[PublicKey],
156 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
157 async fn get_blind_signatures_for_keyset(
159 &self,
160 keyset_id: &Id,
161 ) -> Result<Vec<BlindSignature>, Self::Err>;
162 async fn get_blind_signatures_for_quote(
164 &self,
165 quote_id: &Uuid,
166 ) -> Result<Vec<BlindSignature>, Self::Err>;
167}
168
169#[async_trait]
171pub trait Database<Error>:
172 KeysDatabase<Err = Error>
173 + QuotesDatabase<Err = Error>
174 + ProofsDatabase<Err = Error>
175 + SignaturesDatabase<Err = Error>
176{
177 async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Error>;
179 async fn get_mint_info(&self) -> Result<MintInfo, Error>;
181
182 async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Error>;
184 async fn get_quote_ttl(&self) -> Result<QuoteTTL, Error>;
186}