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 Database {
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
36 async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
38 async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
40 async fn update_mint_quote_state(
42 &self,
43 quote_id: &Uuid,
44 state: MintQuoteState,
45 ) -> Result<MintQuoteState, Self::Err>;
46 async fn get_mint_quote_by_request(
48 &self,
49 request: &str,
50 ) -> Result<Option<MintMintQuote>, Self::Err>;
51 async fn get_mint_quote_by_request_lookup_id(
53 &self,
54 request_lookup_id: &str,
55 ) -> Result<Option<MintMintQuote>, Self::Err>;
56 async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
58 async fn get_mint_quotes_with_state(
60 &self,
61 state: MintQuoteState,
62 ) -> Result<Vec<MintMintQuote>, Self::Err>;
63 async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
65
66 async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
68 async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
70 async fn update_melt_quote_state(
72 &self,
73 quote_id: &Uuid,
74 state: MeltQuoteState,
75 ) -> Result<MeltQuoteState, Self::Err>;
76 async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
78 async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
80
81 async fn add_melt_request(
83 &self,
84 melt_request: MeltBolt11Request<Uuid>,
85 ln_key: PaymentProcessorKey,
86 ) -> Result<(), Self::Err>;
87 async fn get_melt_request(
89 &self,
90 quote_id: &Uuid,
91 ) -> Result<Option<(MeltBolt11Request<Uuid>, PaymentProcessorKey)>, Self::Err>;
92
93 async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
95 async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
97 async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
99
100 async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
102 async fn remove_proofs(
104 &self,
105 ys: &[PublicKey],
106 quote_id: Option<Uuid>,
107 ) -> Result<(), Self::Err>;
108 async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
110 async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
112 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
114 async fn update_proofs_states(
116 &self,
117 ys: &[PublicKey],
118 proofs_state: State,
119 ) -> Result<Vec<Option<State>>, Self::Err>;
120 async fn get_proofs_by_keyset_id(
122 &self,
123 keyset_id: &Id,
124 ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
125
126 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 async fn get_blind_signatures(
135 &self,
136 blinded_messages: &[PublicKey],
137 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
138 async fn get_blind_signatures_for_keyset(
140 &self,
141 keyset_id: &Id,
142 ) -> Result<Vec<BlindSignature>, Self::Err>;
143 async fn get_blind_signatures_for_quote(
145 &self,
146 quote_id: &Uuid,
147 ) -> Result<Vec<BlindSignature>, Self::Err>;
148
149 async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Self::Err>;
151 async fn get_mint_info(&self) -> Result<MintInfo, Self::Err>;
153
154 async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Self::Err>;
156 async fn get_quote_ttl(&self) -> Result<QuoteTTL, Self::Err>;
158}